UNPKG

1.9 kBJavaScriptView Raw
1import { BehaviorSubject, queueScheduler, Observable } from 'rxjs';
2import { observeOn, scan, map, distinctUntilChanged } from 'rxjs/operators';
3
4class MiniState extends BehaviorSubject {
5 constructor(_initialState, actionsDispatcher$, reducer) {
6 super(_initialState);
7 const actionInQueue$ = actionsDispatcher$.pipe(observeOn(queueScheduler));
8 const state$ = actionInQueue$.pipe(scan((state, action) => {
9 if (!action) {
10 return state;
11 }
12 return reducer(state, action);
13 }, _initialState));
14 state$.subscribe((value) => this.next(value));
15 }
16}
17
18/**
19 * @copyright ngrx
20 */
21class MiniStore extends Observable {
22 constructor(_dispatcher,
23 // eslint-disable-next-line @typescript-eslint/no-explicit-any
24 _reducer,
25 // eslint-disable-next-line @typescript-eslint/no-explicit-any
26 state$) {
27 super();
28 this._dispatcher = _dispatcher;
29 this._reducer = _reducer;
30 this.source = state$;
31 }
32 select(pathOrMapFn) {
33 // eslint-disable-next-line @typescript-eslint/ban-ts-comment
34 // @ts-ignore
35 const mapped$ = this.source?.pipe(map(pathOrMapFn)) || new Observable().pipe(map(pathOrMapFn));
36 return mapped$.pipe(distinctUntilChanged());
37 }
38 lift(operator) {
39 const store = new MiniStore(this._dispatcher, this._reducer, this);
40 store.operator = operator;
41 return store;
42 }
43 dispatch(action) {
44 this._dispatcher.next(action);
45 }
46 next(action) {
47 this._dispatcher.next(action);
48 }
49 // eslint-disable-next-line @typescript-eslint/no-explicit-any
50 error(err) {
51 this._dispatcher.error(err);
52 }
53 complete() {
54 /*noop*/
55 }
56}
57
58/**
59 * Generated bundle index. Do not edit.
60 */
61
62export { MiniState, MiniStore };
63//# sourceMappingURL=ngx-bootstrap-mini-ngrx.mjs.map