import { IStateliContext } from './i-stateli-context'; import { IStateliStore } from './i-stateli-store'; import { Map, fromJS } from 'immutable'; export class StateliSnapshotContext implements IStateliContext { private _rootStateSnapshot: Map; private _stateSnapshot: Map; constructor(private getState: (store: IStateliStore) => State, private store: IStateliStore) { this._rootStateSnapshot = fromJS(store.state); this._stateSnapshot = fromJS(getState(store)); } get rootState() { return this.store.state; } get state() { return this.getState(this.store); } get snapshots() { return { rootState: this._rootStateSnapshot.toJS() as RootState, state: this._stateSnapshot.toJS() as State, }; } getter(type: string) { return this.store.getter(type); } commit(type: string, payload: Payload) { this.store.commit(type, payload); } dispatch(type: string, payload: Payload) { return this.store.dispatch(type, payload); } }