sprinklers3/client/state/UserStore.ts

22 lines
473 B
TypeScript
Raw Normal View History

2018-08-13 15:11:36 +03:00
import { ISprinklersDevice, IUser } from "@common/httpApi";
import { action, observable } from "mobx";
export class UserStore {
2018-09-02 02:57:55 -06:00
@observable
userData: IUser | null = null;
2018-08-13 15:11:36 +03:00
2018-09-02 02:57:55 -06:00
@action.bound
receiveUserData(userData: IUser) {
this.userData = userData;
}
2018-08-13 15:11:36 +03:00
2018-09-02 02:57:55 -06:00
findDevice(id: number): ISprinklersDevice | null {
return (
(this.userData &&
this.userData.devices &&
this.userData.devices.find(dev => dev.id === id)) ||
null
);
}
}