sprinklers3/client/state/UserStore.ts

26 lines
610 B
TypeScript
Raw Permalink Normal View History

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