Alex Mikhalev
7 years ago
7 changed files with 61 additions and 39 deletions
@ -0,0 +1,16 @@
@@ -0,0 +1,16 @@
|
||||
import * as PropTypes from "prop-types"; |
||||
import * as React from "react"; |
||||
|
||||
export class Provider<T extends {}> extends React.Component<T> { |
||||
static childContextTypes = { |
||||
injected: any, |
||||
}; |
||||
} |
||||
|
||||
export function inject<P, T extends React.ComponentType<P>>(...names: string[]): (base: T) => React.ComponentClass<T> { |
||||
return (Component) => { |
||||
return class extends React.Component<T> { |
||||
|
||||
}; |
||||
}; |
||||
} |
@ -0,0 +1,22 @@
@@ -0,0 +1,22 @@
|
||||
import { MqttApiClient } from "@app/mqtt"; |
||||
import { Message, UiStore } from "@app/ui"; |
||||
import { ISprinklersApi, SprinklersDevice } from "@common/sprinklers"; |
||||
|
||||
export class State { |
||||
client: ISprinklersApi = new MqttApiClient(); |
||||
device: SprinklersDevice; |
||||
uiStore = new UiStore(); |
||||
|
||||
constructor() { |
||||
const device = this.client.getDevice("grinklers"); |
||||
this.uiStore.addMessage({ header: "asdf", content: "boo!", error: true }); |
||||
} |
||||
|
||||
start() { |
||||
this.client.start(); |
||||
} |
||||
} |
||||
|
||||
const state = new State(); |
||||
|
||||
export default state; |
@ -1,32 +1,20 @@
@@ -1,32 +1,20 @@
|
||||
import {observable} from "mobx"; |
||||
import { IObservableArray, observable } from "mobx"; |
||||
import { MessageProps } from "semantic-ui-react"; |
||||
|
||||
import { getRandomId } from "@common/utils"; |
||||
|
||||
export class Message { |
||||
id: string; |
||||
header: string = ""; |
||||
content: string = ""; |
||||
type: Message.Type = Message.Type.Default; |
||||
|
||||
constructor(header: string, content: string = "", type: Message.Type = Message.Type.Default) { |
||||
this.id = "" + getRandomId(); |
||||
this.header = header; |
||||
this.content = content; |
||||
this.type = type; |
||||
} |
||||
} |
||||
|
||||
export namespace Message { |
||||
export enum Type { |
||||
Default, Success, Info, Warning, Error, |
||||
} |
||||
export interface Message extends MessageProps { |
||||
id: number; |
||||
} |
||||
|
||||
export class UiStore { |
||||
@observable |
||||
messages: Message[] = []; |
||||
messages: IObservableArray<Message> = observable.array(); |
||||
|
||||
addMessage(message: Message) { |
||||
this.messages.push(message); |
||||
addMessage(message: MessageProps) { |
||||
this.messages.push(observable({ |
||||
...message, |
||||
id: getRandomId(), |
||||
})); |
||||
} |
||||
} |
||||
|
Loading…
Reference in new issue