/** * @copyright ngrx */ import { Observable, Observer, Operator } from 'rxjs'; import { distinctUntilChanged, map } from 'rxjs/operators'; import { Action, ActionReducer } from './index'; export class MiniStore extends Observable implements Observer { constructor( private _dispatcher: Observer, /* tslint:disable-next-line: no-any */ private _reducer: ActionReducer, /* tslint:disable-next-line: no-any */ state$: Observable ) { super(); /* tslint:disable-next-line: deprecation */ this.source = state$; } select(pathOrMapFn: (state: T) => R): Observable { /* tslint:disable-next-line: deprecation */ const mapped$: Observable = this.source.pipe(map(pathOrMapFn)); return mapped$.pipe(distinctUntilChanged()); } lift(operator: Operator): MiniStore { const store = new MiniStore(this._dispatcher, this._reducer, this); /* tslint:disable-next-line: deprecation */ store.operator = operator; return store; } dispatch(action: Action) { this._dispatcher.next(action); } next(action: Action) { this._dispatcher.next(action); } /* tslint:disable-next-line: no-any */ error(err: any) { this._dispatcher.error(err); } complete() { /*noop*/ } }