import { Map, fromJS } from 'immutable'; import { IStateliSnapshotStore } from './i-stateli-snapshot-store'; import { IStateliStore } from './i-stateli-store'; import { IStateliAction } from './i-stateli-action'; import { IStateliMutation } from './i-stateli-mutation'; import { IStateliGetter } from './i-stateli-getter'; import { IStateliModule } from './i-stateli-module'; export class StateliSnapshotStore implements IStateliSnapshotStore { private _rootSnapshot: Map; constructor(private store: IStateliStore) { this._rootSnapshot = fromJS(store.state); } get state() { return this.store.state; } set state(s: RootState) { this.store.state = s; } get modules() { return this.store.modules; } get snapshot() { return this._rootSnapshot.toJS() as RootState; } asContext() { return this.store.asContext(); } 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); } reset(config: { actions?: IStateliAction[]; mutations?: IStateliMutation[]; getters?: IStateliGetter[]; modules?: IStateliModule[]; initialState?: RootState; }) { this.store.reset(config); } }