MainModel.ts
33 lines
| 824 B
| video/mp2t
|
TypeScriptLexer
|
|
r107 | import { BehaviorSubject, Observer, Unsubscribable, Subscribable } from "rxjs"; | |
| import { IDestroyable} from "@implab/core-amd/interfaces" | |||
| interface State { | |||
| color: string; | |||
| label: string; | |||
| current: number; | |||
| max: number; | |||
| } | |||
| export default class MainModel implements IDestroyable { | |||
| private readonly _state: BehaviorSubject<State>; | |||
| constructor(initialState: State) { | |||
| this._state = new BehaviorSubject(initialState); | |||
| } | |||
| getState() { | |||
| return this._state.getValue(); | |||
| } | |||
| subscribe(observer: Partial<Observer<State>>): Unsubscribable { | |||
| return this._state.subscribe(observer); | |||
| } | |||
| protected dispatch(command: Partial<State>) { | |||
| const state = this.getState(); | |||
| this._state.next({...state, ... command}); | |||
| } | |||
| load() { } | |||
| destroy() { } | |||
| } |
