1 | import { Injectable, InjectionToken, Inject, isDevMode, NgZone, NgModule, Optional, SkipSelf, Injector } from '@angular/core';
|
2 | import { BehaviorSubject, Observable, Subject, queueScheduler } from 'rxjs';
|
3 | import { observeOn, withLatestFrom, scan, pluck, map, distinctUntilChanged } from 'rxjs/operators';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | const REGISTERED_ACTION_TYPES = {};
|
12 |
|
13 |
|
14 |
|
15 | function resetRegisteredActionTypes() {
|
16 | for (const key of Object.keys(REGISTERED_ACTION_TYPES)) {
|
17 | delete REGISTERED_ACTION_TYPES[key];
|
18 | }
|
19 | }
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 | function createAction(type, config) {
|
101 | REGISTERED_ACTION_TYPES[type] = (REGISTERED_ACTION_TYPES[type] || 0) + 1;
|
102 | if (typeof config === 'function') {
|
103 | return defineType(type, ( |
104 |
|
105 |
|
106 |
|
107 | (...args) => (Object.assign(Object.assign({}, config(...args)), { type }))));
|
108 | }
|
109 |
|
110 | const as = config ? config._as : 'empty';
|
111 | switch (as) {
|
112 | case 'empty':
|
113 | return defineType(type, ( |
114 |
|
115 |
|
116 | () => ({ type })));
|
117 | case 'props':
|
118 | return defineType(type, ( |
119 |
|
120 |
|
121 |
|
122 | (props) => (Object.assign(Object.assign({}, props), { type }))));
|
123 | default:
|
124 | throw new Error('Unexpected config.');
|
125 | }
|
126 | }
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | function props() {
|
132 | return { _as: 'props', _p: ( (undefined)) };
|
133 | }
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 | function union(creators) {
|
140 | return ( (undefined));
|
141 | }
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 | function defineType(type, creator) {
|
149 | return Object.defineProperty(creator, 'type', {
|
150 | value: type,
|
151 | writable: false,
|
152 | });
|
153 | }
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 | const INIT = ( ('@ngrx/store/init'));
|
162 | class ActionsSubject extends BehaviorSubject {
|
163 | constructor() {
|
164 | super({ type: INIT });
|
165 | }
|
166 | |
167 |
|
168 |
|
169 |
|
170 | next(action) {
|
171 | if (typeof action === 'function') {
|
172 | throw new TypeError(`
|
173 | Dispatch expected an object, instead it received a function.
|
174 | If you're using the createAction function, make sure to invoke the function
|
175 | before dispatching the action. For example, someAction should be someAction().`);
|
176 | }
|
177 | else if (typeof action === 'undefined') {
|
178 | throw new TypeError(`Actions must be objects`);
|
179 | }
|
180 | else if (typeof action.type === 'undefined') {
|
181 | throw new TypeError(`Actions must have a type property`);
|
182 | }
|
183 | super.next(action);
|
184 | }
|
185 | |
186 |
|
187 |
|
188 | complete() {
|
189 |
|
190 | }
|
191 | |
192 |
|
193 |
|
194 | ngOnDestroy() {
|
195 | super.complete();
|
196 | }
|
197 | }
|
198 | ActionsSubject.decorators = [
|
199 | { type: Injectable }
|
200 | ];
|
201 |
|
202 | ActionsSubject.ctorParameters = () => [];
|
203 |
|
204 | const ACTIONS_SUBJECT_PROVIDERS = [ActionsSubject];
|
205 |
|
206 |
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 | const _ROOT_STORE_GUARD = new InjectionToken('@ngrx/store Internal Root Guard');
|
213 |
|
214 | const _INITIAL_STATE = new InjectionToken('@ngrx/store Internal Initial State');
|
215 |
|
216 | const INITIAL_STATE = new InjectionToken('@ngrx/store Initial State');
|
217 |
|
218 | const REDUCER_FACTORY = new InjectionToken('@ngrx/store Reducer Factory');
|
219 |
|
220 | const _REDUCER_FACTORY = new InjectionToken('@ngrx/store Internal Reducer Factory Provider');
|
221 |
|
222 | const INITIAL_REDUCERS = new InjectionToken('@ngrx/store Initial Reducers');
|
223 |
|
224 | const _INITIAL_REDUCERS = new InjectionToken('@ngrx/store Internal Initial Reducers');
|
225 |
|
226 | const STORE_FEATURES = new InjectionToken('@ngrx/store Store Features');
|
227 |
|
228 | const _STORE_REDUCERS = new InjectionToken('@ngrx/store Internal Store Reducers');
|
229 |
|
230 | const _FEATURE_REDUCERS = new InjectionToken('@ngrx/store Internal Feature Reducers');
|
231 |
|
232 | const _FEATURE_CONFIGS = new InjectionToken('@ngrx/store Internal Feature Configs');
|
233 |
|
234 | const _STORE_FEATURES = new InjectionToken('@ngrx/store Internal Store Features');
|
235 |
|
236 | const _FEATURE_REDUCERS_TOKEN = new InjectionToken('@ngrx/store Internal Feature Reducers Token');
|
237 |
|
238 | const FEATURE_REDUCERS = new InjectionToken('@ngrx/store Feature Reducers');
|
239 |
|
240 |
|
241 |
|
242 |
|
243 | const USER_PROVIDED_META_REDUCERS = new InjectionToken('@ngrx/store User Provided Meta Reducers');
|
244 |
|
245 |
|
246 |
|
247 |
|
248 | const META_REDUCERS = new InjectionToken('@ngrx/store Meta Reducers');
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 | const _RESOLVED_META_REDUCERS = new InjectionToken('@ngrx/store Internal Resolved Meta Reducers');
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 | const USER_RUNTIME_CHECKS = new InjectionToken('@ngrx/store User Runtime Checks Config');
|
261 |
|
262 |
|
263 |
|
264 |
|
265 | const _USER_RUNTIME_CHECKS = new InjectionToken('@ngrx/store Internal User Runtime Checks Config');
|
266 |
|
267 |
|
268 |
|
269 |
|
270 | const _ACTIVE_RUNTIME_CHECKS = new InjectionToken('@ngrx/store Internal Runtime Checks');
|
271 |
|
272 | const _ACTION_TYPE_UNIQUENESS_CHECK = new InjectionToken('@ngrx/store Check if Action types are unique');
|
273 |
|
274 |
|
275 |
|
276 |
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 |
|
283 |
|
284 |
|
285 |
|
286 |
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 |
|
294 |
|
295 |
|
296 |
|
297 |
|
298 |
|
299 |
|
300 |
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 |
|
307 |
|
308 |
|
309 |
|
310 |
|
311 |
|
312 | function combineReducers(reducers, initialState = {}) {
|
313 |
|
314 | const reducerKeys = Object.keys(reducers);
|
315 |
|
316 | const finalReducers = {};
|
317 | for (let i = 0; i < reducerKeys.length; i++) {
|
318 |
|
319 | const key = reducerKeys[i];
|
320 | if (typeof reducers[key] === 'function') {
|
321 | finalReducers[key] = reducers[key];
|
322 | }
|
323 | }
|
324 |
|
325 | const finalReducerKeys = Object.keys(finalReducers);
|
326 | return ( |
327 |
|
328 |
|
329 |
|
330 |
|
331 | function combination(state, action) {
|
332 | state = state === undefined ? initialState : state;
|
333 |
|
334 | let hasChanged = false;
|
335 |
|
336 | const nextState = {};
|
337 | for (let i = 0; i < finalReducerKeys.length; i++) {
|
338 |
|
339 | const key = finalReducerKeys[i];
|
340 |
|
341 | const reducer = finalReducers[key];
|
342 |
|
343 | const previousStateForKey = state[key];
|
344 |
|
345 | const nextStateForKey = reducer(previousStateForKey, action);
|
346 | nextState[key] = nextStateForKey;
|
347 | hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
|
348 | }
|
349 | return hasChanged ? nextState : state;
|
350 | });
|
351 | }
|
352 |
|
353 |
|
354 |
|
355 |
|
356 |
|
357 |
|
358 | function omit(object, keyToRemove) {
|
359 | return Object.keys(object)
|
360 | .filter(( |
361 |
|
362 |
|
363 |
|
364 | (key) => key !== keyToRemove))
|
365 | .reduce(( |
366 |
|
367 |
|
368 |
|
369 |
|
370 | (result, key) => Object.assign(result, { [key]: object[key] })), {});
|
371 | }
|
372 |
|
373 |
|
374 |
|
375 |
|
376 | function compose(...functions) {
|
377 | return ( |
378 |
|
379 |
|
380 |
|
381 | function (arg) {
|
382 | if (functions.length === 0) {
|
383 | return arg;
|
384 | }
|
385 |
|
386 | const last = functions[functions.length - 1];
|
387 |
|
388 | const rest = functions.slice(0, -1);
|
389 | return rest.reduceRight(( |
390 |
|
391 |
|
392 |
|
393 |
|
394 | (composed, fn) => fn(composed)), last(arg));
|
395 | });
|
396 | }
|
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 | function createReducerFactory(reducerFactory, metaReducers) {
|
404 | if (Array.isArray(metaReducers) && metaReducers.length > 0) {
|
405 | (( (reducerFactory))) = compose.apply(null, [
|
406 | ...metaReducers,
|
407 | reducerFactory,
|
408 | ]);
|
409 | }
|
410 | return ( |
411 |
|
412 |
|
413 |
|
414 |
|
415 | (reducers, initialState) => {
|
416 |
|
417 | const reducer = reducerFactory(reducers);
|
418 | return ( |
419 |
|
420 |
|
421 |
|
422 |
|
423 | (state, action) => {
|
424 | state = state === undefined ? (( (initialState))) : state;
|
425 | return reducer(state, action);
|
426 | });
|
427 | });
|
428 | }
|
429 |
|
430 |
|
431 |
|
432 |
|
433 |
|
434 | function createFeatureReducerFactory(metaReducers) {
|
435 |
|
436 | const reducerFactory = Array.isArray(metaReducers) && metaReducers.length > 0
|
437 | ? compose(...metaReducers)
|
438 | : ( |
439 |
|
440 |
|
441 |
|
442 | (r) => r);
|
443 | return ( |
444 |
|
445 |
|
446 |
|
447 |
|
448 | (reducer, initialState) => {
|
449 | reducer = reducerFactory(reducer);
|
450 | return ( |
451 |
|
452 |
|
453 |
|
454 |
|
455 | (state, action) => {
|
456 | state = state === undefined ? initialState : state;
|
457 | return reducer(state, action);
|
458 | });
|
459 | });
|
460 | }
|
461 |
|
462 |
|
463 |
|
464 |
|
465 |
|
466 |
|
467 |
|
468 |
|
469 |
|
470 | class ReducerObservable extends Observable {
|
471 | }
|
472 |
|
473 |
|
474 |
|
475 | class ReducerManagerDispatcher extends ActionsSubject {
|
476 | }
|
477 |
|
478 | const UPDATE = ( ('@ngrx/store/update-reducers'));
|
479 | class ReducerManager extends BehaviorSubject {
|
480 | |
481 |
|
482 |
|
483 |
|
484 |
|
485 |
|
486 | constructor(dispatcher, initialState, reducers, reducerFactory) {
|
487 | super(reducerFactory(reducers, initialState));
|
488 | this.dispatcher = dispatcher;
|
489 | this.initialState = initialState;
|
490 | this.reducers = reducers;
|
491 | this.reducerFactory = reducerFactory;
|
492 | }
|
493 | |
494 |
|
495 |
|
496 |
|
497 | addFeature(feature) {
|
498 | this.addFeatures([feature]);
|
499 | }
|
500 | |
501 |
|
502 |
|
503 |
|
504 | addFeatures(features) {
|
505 |
|
506 | const reducers = features.reduce(( |
507 |
|
508 |
|
509 |
|
510 |
|
511 | (reducerDict, { reducers, reducerFactory, metaReducers, initialState, key }) => {
|
512 |
|
513 | const reducer = typeof reducers === 'function'
|
514 | ? createFeatureReducerFactory(metaReducers)(reducers, initialState)
|
515 | : createReducerFactory(reducerFactory, metaReducers)(reducers, initialState);
|
516 | reducerDict[key] = reducer;
|
517 | return reducerDict;
|
518 | }), ( ({})));
|
519 | this.addReducers(reducers);
|
520 | }
|
521 | |
522 |
|
523 |
|
524 |
|
525 | removeFeature(feature) {
|
526 | this.removeFeatures([feature]);
|
527 | }
|
528 | |
529 |
|
530 |
|
531 |
|
532 | removeFeatures(features) {
|
533 | this.removeReducers(features.map(( |
534 |
|
535 |
|
536 |
|
537 | (p) => p.key)));
|
538 | }
|
539 | |
540 |
|
541 |
|
542 |
|
543 |
|
544 | addReducer(key, reducer) {
|
545 | this.addReducers({ [key]: reducer });
|
546 | }
|
547 | |
548 |
|
549 |
|
550 |
|
551 | addReducers(reducers) {
|
552 | this.reducers = Object.assign(Object.assign({}, this.reducers), reducers);
|
553 | this.updateReducers(Object.keys(reducers));
|
554 | }
|
555 | |
556 |
|
557 |
|
558 |
|
559 | removeReducer(featureKey) {
|
560 | this.removeReducers([featureKey]);
|
561 | }
|
562 | |
563 |
|
564 |
|
565 |
|
566 | removeReducers(featureKeys) {
|
567 | featureKeys.forEach(( |
568 |
|
569 |
|
570 |
|
571 | (key) => {
|
572 | this.reducers = ( (omit(this.reducers, key) ));
|
573 | }));
|
574 | this.updateReducers(featureKeys);
|
575 | }
|
576 | |
577 |
|
578 |
|
579 |
|
580 |
|
581 | updateReducers(featureKeys) {
|
582 | this.next(this.reducerFactory(this.reducers, this.initialState));
|
583 | this.dispatcher.next(( ({
|
584 | type: UPDATE,
|
585 | features: featureKeys,
|
586 | })));
|
587 | }
|
588 | |
589 |
|
590 |
|
591 | ngOnDestroy() {
|
592 | this.complete();
|
593 | }
|
594 | }
|
595 | ReducerManager.decorators = [
|
596 | { type: Injectable }
|
597 | ];
|
598 |
|
599 | ReducerManager.ctorParameters = () => [
|
600 | { type: ReducerManagerDispatcher },
|
601 | { type: undefined, decorators: [{ type: Inject, args: [INITIAL_STATE,] }] },
|
602 | { type: undefined, decorators: [{ type: Inject, args: [INITIAL_REDUCERS,] }] },
|
603 | { type: undefined, decorators: [{ type: Inject, args: [REDUCER_FACTORY,] }] }
|
604 | ];
|
605 | if (false) {
|
606 | |
607 |
|
608 |
|
609 |
|
610 | ReducerManager.prototype.dispatcher;
|
611 | |
612 |
|
613 |
|
614 |
|
615 | ReducerManager.prototype.initialState;
|
616 | |
617 |
|
618 |
|
619 |
|
620 | ReducerManager.prototype.reducers;
|
621 | |
622 |
|
623 |
|
624 |
|
625 | ReducerManager.prototype.reducerFactory;
|
626 | }
|
627 |
|
628 | const REDUCER_MANAGER_PROVIDERS = [
|
629 | ReducerManager,
|
630 | { provide: ReducerObservable, useExisting: ReducerManager },
|
631 | { provide: ReducerManagerDispatcher, useExisting: ActionsSubject },
|
632 | ];
|
633 |
|
634 |
|
635 |
|
636 |
|
637 |
|
638 |
|
639 | class ScannedActionsSubject extends Subject {
|
640 | |
641 |
|
642 |
|
643 | ngOnDestroy() {
|
644 | this.complete();
|
645 | }
|
646 | }
|
647 | ScannedActionsSubject.decorators = [
|
648 | { type: Injectable }
|
649 | ];
|
650 |
|
651 | const SCANNED_ACTIONS_SUBJECT_PROVIDERS = [
|
652 | ScannedActionsSubject,
|
653 | ];
|
654 |
|
655 |
|
656 |
|
657 |
|
658 |
|
659 |
|
660 |
|
661 |
|
662 |
|
663 | class StateObservable extends Observable {
|
664 | }
|
665 |
|
666 |
|
667 |
|
668 | class State extends BehaviorSubject {
|
669 | |
670 |
|
671 |
|
672 |
|
673 |
|
674 |
|
675 | constructor(actions$, reducer$, scannedActions, initialState) {
|
676 | super(initialState);
|
677 |
|
678 | const actionsOnQueue$ = actions$.pipe(observeOn(queueScheduler));
|
679 |
|
680 | const withLatestReducer$ = actionsOnQueue$.pipe(withLatestFrom(reducer$));
|
681 |
|
682 | const seed = { state: initialState };
|
683 |
|
684 | const stateAndAction$ = withLatestReducer$.pipe(scan(reduceState, seed));
|
685 | this.stateSubscription = stateAndAction$.subscribe(( |
686 |
|
687 |
|
688 |
|
689 | ({ state, action }) => {
|
690 | this.next(state);
|
691 | scannedActions.next(( (action)));
|
692 | }));
|
693 | }
|
694 | |
695 |
|
696 |
|
697 | ngOnDestroy() {
|
698 | this.stateSubscription.unsubscribe();
|
699 | this.complete();
|
700 | }
|
701 | }
|
702 | State.INIT = INIT;
|
703 | State.decorators = [
|
704 | { type: Injectable }
|
705 | ];
|
706 |
|
707 | State.ctorParameters = () => [
|
708 | { type: ActionsSubject },
|
709 | { type: ReducerObservable },
|
710 | { type: ScannedActionsSubject },
|
711 | { type: undefined, decorators: [{ type: Inject, args: [INITIAL_STATE,] }] }
|
712 | ];
|
713 | if (false) {
|
714 |
|
715 | State.INIT;
|
716 | |
717 |
|
718 |
|
719 |
|
720 | State.prototype.stateSubscription;
|
721 | }
|
722 |
|
723 |
|
724 |
|
725 |
|
726 |
|
727 |
|
728 | function reduceState(stateActionPair = { state: undefined }, [action, reducer]) {
|
729 | const { state } = stateActionPair;
|
730 | return { state: reducer(state, action), action };
|
731 | }
|
732 |
|
733 | const STATE_PROVIDERS = [
|
734 | State,
|
735 | { provide: StateObservable, useExisting: State },
|
736 | ];
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 | class Store extends Observable {
|
747 | |
748 |
|
749 |
|
750 |
|
751 |
|
752 | constructor(state$, actionsObserver, reducerManager) {
|
753 | super();
|
754 | this.actionsObserver = actionsObserver;
|
755 | this.reducerManager = reducerManager;
|
756 | this.source = state$;
|
757 | }
|
758 | |
759 |
|
760 |
|
761 |
|
762 |
|
763 |
|
764 | select(pathOrMapFn, ...paths) {
|
765 | return (( (select))).call(null, pathOrMapFn, ...paths)(this);
|
766 | }
|
767 | |
768 |
|
769 |
|
770 |
|
771 |
|
772 | lift(operator) {
|
773 |
|
774 | const store = new Store(this, this.actionsObserver, this.reducerManager);
|
775 | store.operator = operator;
|
776 | return store;
|
777 | }
|
778 | |
779 |
|
780 |
|
781 |
|
782 |
|
783 | dispatch(action) {
|
784 | this.actionsObserver.next(action);
|
785 | }
|
786 | |
787 |
|
788 |
|
789 |
|
790 | next(action) {
|
791 | this.actionsObserver.next(action);
|
792 | }
|
793 | |
794 |
|
795 |
|
796 |
|
797 | error(err) {
|
798 | this.actionsObserver.error(err);
|
799 | }
|
800 | |
801 |
|
802 |
|
803 | complete() {
|
804 | this.actionsObserver.complete();
|
805 | }
|
806 | |
807 |
|
808 |
|
809 |
|
810 |
|
811 |
|
812 | addReducer(key, reducer) {
|
813 | this.reducerManager.addReducer(key, reducer);
|
814 | }
|
815 | |
816 |
|
817 |
|
818 |
|
819 |
|
820 | removeReducer(key) {
|
821 | this.reducerManager.removeReducer(key);
|
822 | }
|
823 | }
|
824 | Store.decorators = [
|
825 | { type: Injectable }
|
826 | ];
|
827 |
|
828 | Store.ctorParameters = () => [
|
829 | { type: StateObservable },
|
830 | { type: ActionsSubject },
|
831 | { type: ReducerManager }
|
832 | ];
|
833 | if (false) {
|
834 | |
835 |
|
836 |
|
837 |
|
838 | Store.prototype.actionsObserver;
|
839 | |
840 |
|
841 |
|
842 |
|
843 | Store.prototype.reducerManager;
|
844 | }
|
845 |
|
846 | const STORE_PROVIDERS = [Store];
|
847 |
|
848 |
|
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 | function select(pathOrMapFn, propsOrPath, ...paths) {
|
855 | return ( |
856 |
|
857 |
|
858 |
|
859 | function selectOperator(source$) {
|
860 |
|
861 | let mapped$;
|
862 | if (typeof pathOrMapFn === 'string') {
|
863 |
|
864 | const pathSlices = [( (propsOrPath)), ...paths].filter(Boolean);
|
865 | mapped$ = source$.pipe(pluck(pathOrMapFn, ...pathSlices));
|
866 | }
|
867 | else if (typeof pathOrMapFn === 'function') {
|
868 | mapped$ = source$.pipe(map(( |
869 |
|
870 |
|
871 |
|
872 | (source) => pathOrMapFn(source, ( (propsOrPath))))));
|
873 | }
|
874 | else {
|
875 | throw new TypeError(`Unexpected type '${typeof pathOrMapFn}' in select operator,` +
|
876 | ` expected 'string' or 'function'`);
|
877 | }
|
878 | return mapped$.pipe(distinctUntilChanged());
|
879 | });
|
880 | }
|
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 | let _ngrxMockEnvironment = false;
|
889 |
|
890 |
|
891 |
|
892 |
|
893 | function setNgrxMockEnvironment(value) {
|
894 | _ngrxMockEnvironment = value;
|
895 | }
|
896 |
|
897 |
|
898 |
|
899 | function isNgrxMockEnvironment() {
|
900 | return _ngrxMockEnvironment;
|
901 | }
|
902 |
|
903 |
|
904 |
|
905 |
|
906 |
|
907 |
|
908 |
|
909 |
|
910 |
|
911 |
|
912 | function MemoizedSelector() { }
|
913 | if (false) {
|
914 |
|
915 | MemoizedSelector.prototype.projector;
|
916 |
|
917 | MemoizedSelector.prototype.setResult;
|
918 |
|
919 | MemoizedSelector.prototype.clearResult;
|
920 | |
921 |
|
922 |
|
923 | MemoizedSelector.prototype.release = function () { };
|
924 | }
|
925 |
|
926 |
|
927 |
|
928 |
|
929 | function MemoizedSelectorWithProps() { }
|
930 | if (false) {
|
931 |
|
932 | MemoizedSelectorWithProps.prototype.projector;
|
933 |
|
934 | MemoizedSelectorWithProps.prototype.setResult;
|
935 |
|
936 | MemoizedSelectorWithProps.prototype.clearResult;
|
937 | |
938 |
|
939 |
|
940 | MemoizedSelectorWithProps.prototype.release = function () { };
|
941 | }
|
942 |
|
943 |
|
944 |
|
945 |
|
946 |
|
947 | function isEqualCheck(a, b) {
|
948 | return a === b;
|
949 | }
|
950 |
|
951 |
|
952 |
|
953 |
|
954 |
|
955 |
|
956 | function isArgumentsChanged(args, lastArguments, comparator) {
|
957 | for (let i = 0; i < args.length; i++) {
|
958 | if (!comparator(args[i], lastArguments[i])) {
|
959 | return true;
|
960 | }
|
961 | }
|
962 | return false;
|
963 | }
|
964 |
|
965 |
|
966 |
|
967 |
|
968 |
|
969 | function resultMemoize(projectionFn, isResultEqual) {
|
970 | return defaultMemoize(projectionFn, isEqualCheck, isResultEqual);
|
971 | }
|
972 |
|
973 |
|
974 |
|
975 |
|
976 |
|
977 |
|
978 | function defaultMemoize(projectionFn, isArgumentsEqual = isEqualCheck, isResultEqual = isEqualCheck) {
|
979 |
|
980 | let lastArguments = null;
|
981 |
|
982 |
|
983 | let lastResult = null;
|
984 |
|
985 | let overrideResult;
|
986 | |
987 |
|
988 |
|
989 | function reset() {
|
990 | lastArguments = null;
|
991 | lastResult = null;
|
992 | }
|
993 | |
994 |
|
995 |
|
996 |
|
997 | function setResult(result = undefined) {
|
998 | overrideResult = { result };
|
999 | }
|
1000 | |
1001 |
|
1002 |
|
1003 | function clearResult() {
|
1004 | overrideResult = undefined;
|
1005 | }
|
1006 |
|
1007 | |
1008 |
|
1009 |
|
1010 | function memoized() {
|
1011 | if (overrideResult !== undefined) {
|
1012 | return overrideResult.result;
|
1013 | }
|
1014 | if (!lastArguments) {
|
1015 | lastResult = projectionFn.apply(null, ( (arguments)));
|
1016 | lastArguments = arguments;
|
1017 | return lastResult;
|
1018 | }
|
1019 | if (!isArgumentsChanged(arguments, lastArguments, isArgumentsEqual)) {
|
1020 | return lastResult;
|
1021 | }
|
1022 |
|
1023 | const newResult = projectionFn.apply(null, ( (arguments)));
|
1024 | lastArguments = arguments;
|
1025 | if (isResultEqual(lastResult, newResult)) {
|
1026 | return lastResult;
|
1027 | }
|
1028 | lastResult = newResult;
|
1029 | return newResult;
|
1030 | }
|
1031 | return { memoized, reset, setResult, clearResult };
|
1032 | }
|
1033 |
|
1034 |
|
1035 |
|
1036 |
|
1037 | function createSelector(...input) {
|
1038 | return createSelectorFactory(defaultMemoize)(...input);
|
1039 | }
|
1040 |
|
1041 |
|
1042 |
|
1043 |
|
1044 |
|
1045 |
|
1046 |
|
1047 | function defaultStateFn(state, selectors, props, memoizedProjector) {
|
1048 | if (props === undefined) {
|
1049 |
|
1050 | const args = (( (selectors))).map(( |
1051 |
|
1052 |
|
1053 |
|
1054 | (fn) => fn(state)));
|
1055 | return memoizedProjector.memoized.apply(null, args);
|
1056 | }
|
1057 |
|
1058 | const args = (( (selectors))).map(( |
1059 |
|
1060 |
|
1061 |
|
1062 | (fn) => fn(state, props)));
|
1063 | return memoizedProjector.memoized.apply(null, [...args, props]);
|
1064 | }
|
1065 |
|
1066 |
|
1067 |
|
1068 |
|
1069 |
|
1070 |
|
1071 |
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 |
|
1084 |
|
1085 |
|
1086 |
|
1087 |
|
1088 |
|
1089 |
|
1090 |
|
1091 |
|
1092 |
|
1093 |
|
1094 |
|
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 |
|
1101 |
|
1102 |
|
1103 |
|
1104 |
|
1105 |
|
1106 |
|
1107 |
|
1108 |
|
1109 |
|
1110 |
|
1111 |
|
1112 |
|
1113 |
|
1114 |
|
1115 |
|
1116 |
|
1117 |
|
1118 |
|
1119 |
|
1120 |
|
1121 |
|
1122 |
|
1123 |
|
1124 |
|
1125 |
|
1126 |
|
1127 |
|
1128 |
|
1129 |
|
1130 |
|
1131 |
|
1132 |
|
1133 |
|
1134 |
|
1135 |
|
1136 |
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 |
|
1142 |
|
1143 |
|
1144 | function createSelectorFactory(memoize, options = {
|
1145 | stateFn: defaultStateFn,
|
1146 | }) {
|
1147 | return ( |
1148 |
|
1149 |
|
1150 |
|
1151 | function (...input) {
|
1152 |
|
1153 | let args = input;
|
1154 | if (Array.isArray(args[0])) {
|
1155 | const [head, ...tail] = args;
|
1156 | args = [...head, ...tail];
|
1157 | }
|
1158 |
|
1159 | const selectors = args.slice(0, args.length - 1);
|
1160 |
|
1161 | const projector = args[args.length - 1];
|
1162 |
|
1163 | const memoizedSelectors = selectors.filter(( |
1164 |
|
1165 |
|
1166 |
|
1167 | (selector) => selector.release && typeof selector.release === 'function'));
|
1168 |
|
1169 | const memoizedProjector = memoize(( |
1170 |
|
1171 |
|
1172 |
|
1173 | function (...selectors) {
|
1174 | return projector.apply(null, selectors);
|
1175 | }));
|
1176 |
|
1177 | const memoizedState = defaultMemoize(( |
1178 |
|
1179 |
|
1180 |
|
1181 |
|
1182 | function (state, props) {
|
1183 | return options.stateFn.apply(null, [
|
1184 | state,
|
1185 | selectors,
|
1186 | props,
|
1187 | memoizedProjector,
|
1188 | ]);
|
1189 | }));
|
1190 | |
1191 |
|
1192 |
|
1193 | function release() {
|
1194 | memoizedState.reset();
|
1195 | memoizedProjector.reset();
|
1196 | memoizedSelectors.forEach(( |
1197 |
|
1198 |
|
1199 |
|
1200 | (selector) => selector.release()));
|
1201 | }
|
1202 | return Object.assign(memoizedState.memoized, {
|
1203 | release,
|
1204 | projector: memoizedProjector.memoized,
|
1205 | setResult: memoizedState.setResult,
|
1206 | clearResult: memoizedState.clearResult,
|
1207 | });
|
1208 | });
|
1209 | }
|
1210 |
|
1211 |
|
1212 |
|
1213 |
|
1214 | function createFeatureSelector(featureName) {
|
1215 | return createSelector(( |
1216 |
|
1217 |
|
1218 |
|
1219 | (state) => {
|
1220 |
|
1221 | const featureState = state[featureName];
|
1222 | if (!isNgrxMockEnvironment() && isDevMode() && !(featureName in state)) {
|
1223 | console.warn(`@ngrx/store: The feature name \"${featureName}\" does ` +
|
1224 | 'not exist in the state, therefore createFeatureSelector ' +
|
1225 | 'cannot access it. Be sure it is imported in a loaded module ' +
|
1226 | `using StoreModule.forRoot('${featureName}', ...) or ` +
|
1227 | `StoreModule.forFeature('${featureName}', ...). If the default ` +
|
1228 | 'state is intended to be undefined, as is the case with router ' +
|
1229 | 'state, this development-only warning message can be ignored.');
|
1230 | }
|
1231 | return featureState;
|
1232 | }), ( |
1233 |
|
1234 |
|
1235 |
|
1236 | (featureState) => featureState));
|
1237 | }
|
1238 |
|
1239 |
|
1240 |
|
1241 |
|
1242 |
|
1243 |
|
1244 |
|
1245 | const RUNTIME_CHECK_URL = 'https://ngrx.io/guide/store/configuration/runtime-checks';
|
1246 |
|
1247 |
|
1248 |
|
1249 |
|
1250 | function isUndefined(target) {
|
1251 | return target === undefined;
|
1252 | }
|
1253 |
|
1254 |
|
1255 |
|
1256 |
|
1257 | function isNull(target) {
|
1258 | return target === null;
|
1259 | }
|
1260 |
|
1261 |
|
1262 |
|
1263 |
|
1264 | function isArray(target) {
|
1265 | return Array.isArray(target);
|
1266 | }
|
1267 |
|
1268 |
|
1269 |
|
1270 |
|
1271 | function isString(target) {
|
1272 | return typeof target === 'string';
|
1273 | }
|
1274 |
|
1275 |
|
1276 |
|
1277 |
|
1278 | function isBoolean(target) {
|
1279 | return typeof target === 'boolean';
|
1280 | }
|
1281 |
|
1282 |
|
1283 |
|
1284 |
|
1285 | function isNumber(target) {
|
1286 | return typeof target === 'number';
|
1287 | }
|
1288 |
|
1289 |
|
1290 |
|
1291 |
|
1292 | function isObjectLike(target) {
|
1293 | return typeof target === 'object' && target !== null;
|
1294 | }
|
1295 |
|
1296 |
|
1297 |
|
1298 |
|
1299 | function isObject(target) {
|
1300 | return isObjectLike(target) && !isArray(target);
|
1301 | }
|
1302 |
|
1303 |
|
1304 |
|
1305 |
|
1306 | function isPlainObject(target) {
|
1307 | if (!isObject(target)) {
|
1308 | return false;
|
1309 | }
|
1310 |
|
1311 | const targetPrototype = Object.getPrototypeOf(target);
|
1312 | return targetPrototype === Object.prototype || targetPrototype === null;
|
1313 | }
|
1314 |
|
1315 |
|
1316 |
|
1317 |
|
1318 | function isFunction(target) {
|
1319 | return typeof target === 'function';
|
1320 | }
|
1321 |
|
1322 |
|
1323 |
|
1324 |
|
1325 | function isComponent(target) {
|
1326 | return isFunction(target) && target.hasOwnProperty('ɵcmp');
|
1327 | }
|
1328 |
|
1329 |
|
1330 |
|
1331 |
|
1332 |
|
1333 | function hasOwnProperty(target, propertyName) {
|
1334 | return Object.prototype.hasOwnProperty.call(target, propertyName);
|
1335 | }
|
1336 |
|
1337 |
|
1338 |
|
1339 |
|
1340 |
|
1341 |
|
1342 |
|
1343 |
|
1344 |
|
1345 |
|
1346 |
|
1347 | function immutabilityCheckMetaReducer(reducer, checks) {
|
1348 | return ( |
1349 |
|
1350 |
|
1351 |
|
1352 |
|
1353 | function (state, action) {
|
1354 |
|
1355 | const act = checks.action(action) ? freeze(action) : action;
|
1356 |
|
1357 | const nextState = reducer(state, act);
|
1358 | return checks.state() ? freeze(nextState) : nextState;
|
1359 | });
|
1360 | }
|
1361 |
|
1362 |
|
1363 |
|
1364 |
|
1365 | function freeze(target) {
|
1366 | Object.freeze(target);
|
1367 |
|
1368 | const targetIsFunction = isFunction(target);
|
1369 | Object.getOwnPropertyNames(target).forEach(( |
1370 |
|
1371 |
|
1372 |
|
1373 | (prop) => {
|
1374 |
|
1375 | if (prop.startsWith('ɵ')) {
|
1376 | return;
|
1377 | }
|
1378 | if (hasOwnProperty(target, prop) &&
|
1379 | (targetIsFunction
|
1380 | ? prop !== 'caller' && prop !== 'callee' && prop !== 'arguments'
|
1381 | : true)) {
|
1382 |
|
1383 | const propValue = target[prop];
|
1384 | if ((isObjectLike(propValue) || isFunction(propValue)) &&
|
1385 | !Object.isFrozen(propValue)) {
|
1386 | freeze(propValue);
|
1387 | }
|
1388 | }
|
1389 | }));
|
1390 | return target;
|
1391 | }
|
1392 |
|
1393 |
|
1394 |
|
1395 |
|
1396 |
|
1397 |
|
1398 |
|
1399 |
|
1400 |
|
1401 |
|
1402 |
|
1403 | function serializationCheckMetaReducer(reducer, checks) {
|
1404 | return ( |
1405 |
|
1406 |
|
1407 |
|
1408 |
|
1409 | function (state, action) {
|
1410 | if (checks.action(action)) {
|
1411 |
|
1412 | const unserializableAction = getUnserializable(action);
|
1413 | throwIfUnserializable(unserializableAction, 'action');
|
1414 | }
|
1415 |
|
1416 | const nextState = reducer(state, action);
|
1417 | if (checks.state()) {
|
1418 |
|
1419 | const unserializableState = getUnserializable(nextState);
|
1420 | throwIfUnserializable(unserializableState, 'state');
|
1421 | }
|
1422 | return nextState;
|
1423 | });
|
1424 | }
|
1425 |
|
1426 |
|
1427 |
|
1428 |
|
1429 |
|
1430 | function getUnserializable(target, path = []) {
|
1431 |
|
1432 | if ((isUndefined(target) || isNull(target)) && path.length === 0) {
|
1433 | return {
|
1434 | path: ['root'],
|
1435 | value: target,
|
1436 | };
|
1437 | }
|
1438 |
|
1439 | const keys = Object.keys(target);
|
1440 | return keys.reduce(( |
1441 |
|
1442 |
|
1443 |
|
1444 |
|
1445 | (result, key) => {
|
1446 | if (result) {
|
1447 | return result;
|
1448 | }
|
1449 |
|
1450 | const value = (( (target)))[key];
|
1451 |
|
1452 | if (isComponent(value)) {
|
1453 | return result;
|
1454 | }
|
1455 | if (isUndefined(value) ||
|
1456 | isNull(value) ||
|
1457 | isNumber(value) ||
|
1458 | isBoolean(value) ||
|
1459 | isString(value) ||
|
1460 | isArray(value)) {
|
1461 | return false;
|
1462 | }
|
1463 | if (isPlainObject(value)) {
|
1464 | return getUnserializable(value, [...path, key]);
|
1465 | }
|
1466 | return {
|
1467 | path: [...path, key],
|
1468 | value,
|
1469 | };
|
1470 | }), false);
|
1471 | }
|
1472 |
|
1473 |
|
1474 |
|
1475 |
|
1476 |
|
1477 | function throwIfUnserializable(unserializable, context) {
|
1478 | if (unserializable === false) {
|
1479 | return;
|
1480 | }
|
1481 |
|
1482 | const unserializablePath = unserializable.path.join('.');
|
1483 |
|
1484 | const error = new Error(`Detected unserializable ${context} at "${unserializablePath}". ${RUNTIME_CHECK_URL}#strict${context}serializability`);
|
1485 | error.value = unserializable.value;
|
1486 | error.unserializablePath = unserializablePath;
|
1487 | throw error;
|
1488 | }
|
1489 |
|
1490 |
|
1491 |
|
1492 |
|
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 |
|
1500 | function inNgZoneAssertMetaReducer(reducer, checks) {
|
1501 | return ( |
1502 |
|
1503 |
|
1504 |
|
1505 |
|
1506 | function (state, action) {
|
1507 | if (checks.action(action) && !NgZone.isInAngularZone()) {
|
1508 | throw new Error(`Action '${action.type}' running outside NgZone. ${RUNTIME_CHECK_URL}#strictactionwithinngzone`);
|
1509 | }
|
1510 | return reducer(state, action);
|
1511 | });
|
1512 | }
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 |
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 | function createActiveRuntimeChecks(runtimeChecks) {
|
1530 | if (isDevMode()) {
|
1531 | return Object.assign({ strictStateSerializability: false, strictActionSerializability: false, strictStateImmutability: true, strictActionImmutability: true, strictActionWithinNgZone: false, strictActionTypeUniqueness: false }, runtimeChecks);
|
1532 | }
|
1533 | return {
|
1534 | strictStateSerializability: false,
|
1535 | strictActionSerializability: false,
|
1536 | strictStateImmutability: false,
|
1537 | strictActionImmutability: false,
|
1538 | strictActionWithinNgZone: false,
|
1539 | strictActionTypeUniqueness: false,
|
1540 | };
|
1541 | }
|
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 | function createSerializationCheckMetaReducer({ strictActionSerializability, strictStateSerializability, }) {
|
1547 | return ( |
1548 |
|
1549 |
|
1550 |
|
1551 | (reducer) => strictActionSerializability || strictStateSerializability
|
1552 | ? serializationCheckMetaReducer(reducer, {
|
1553 | action: ( |
1554 |
|
1555 |
|
1556 |
|
1557 | (action) => strictActionSerializability && !ignoreNgrxAction(action)),
|
1558 | state: ( |
1559 |
|
1560 |
|
1561 | () => strictStateSerializability),
|
1562 | })
|
1563 | : reducer);
|
1564 | }
|
1565 |
|
1566 |
|
1567 |
|
1568 |
|
1569 | function createImmutabilityCheckMetaReducer({ strictActionImmutability, strictStateImmutability, }) {
|
1570 | return ( |
1571 |
|
1572 |
|
1573 |
|
1574 | (reducer) => strictActionImmutability || strictStateImmutability
|
1575 | ? immutabilityCheckMetaReducer(reducer, {
|
1576 | action: ( |
1577 |
|
1578 |
|
1579 |
|
1580 | (action) => strictActionImmutability && !ignoreNgrxAction(action)),
|
1581 | state: ( |
1582 |
|
1583 |
|
1584 | () => strictStateImmutability),
|
1585 | })
|
1586 | : reducer);
|
1587 | }
|
1588 |
|
1589 |
|
1590 |
|
1591 |
|
1592 | function ignoreNgrxAction(action) {
|
1593 | return action.type.startsWith('@ngrx');
|
1594 | }
|
1595 |
|
1596 |
|
1597 |
|
1598 |
|
1599 | function createInNgZoneCheckMetaReducer({ strictActionWithinNgZone, }) {
|
1600 | return ( |
1601 |
|
1602 |
|
1603 |
|
1604 | (reducer) => strictActionWithinNgZone
|
1605 | ? inNgZoneAssertMetaReducer(reducer, {
|
1606 | action: ( |
1607 |
|
1608 |
|
1609 |
|
1610 | (action) => strictActionWithinNgZone && !ignoreNgrxAction(action)),
|
1611 | })
|
1612 | : reducer);
|
1613 | }
|
1614 |
|
1615 |
|
1616 |
|
1617 |
|
1618 | function provideRuntimeChecks(runtimeChecks) {
|
1619 | return [
|
1620 | {
|
1621 | provide: _USER_RUNTIME_CHECKS,
|
1622 | useValue: runtimeChecks,
|
1623 | },
|
1624 | {
|
1625 | provide: USER_RUNTIME_CHECKS,
|
1626 | useFactory: _runtimeChecksFactory,
|
1627 | deps: [_USER_RUNTIME_CHECKS],
|
1628 | },
|
1629 | {
|
1630 | provide: _ACTIVE_RUNTIME_CHECKS,
|
1631 | deps: [USER_RUNTIME_CHECKS],
|
1632 | useFactory: createActiveRuntimeChecks,
|
1633 | },
|
1634 | {
|
1635 | provide: META_REDUCERS,
|
1636 | multi: true,
|
1637 | deps: [_ACTIVE_RUNTIME_CHECKS],
|
1638 | useFactory: createImmutabilityCheckMetaReducer,
|
1639 | },
|
1640 | {
|
1641 | provide: META_REDUCERS,
|
1642 | multi: true,
|
1643 | deps: [_ACTIVE_RUNTIME_CHECKS],
|
1644 | useFactory: createSerializationCheckMetaReducer,
|
1645 | },
|
1646 | {
|
1647 | provide: META_REDUCERS,
|
1648 | multi: true,
|
1649 | deps: [_ACTIVE_RUNTIME_CHECKS],
|
1650 | useFactory: createInNgZoneCheckMetaReducer,
|
1651 | },
|
1652 | ];
|
1653 | }
|
1654 |
|
1655 |
|
1656 |
|
1657 | function checkForActionTypeUniqueness() {
|
1658 | return [
|
1659 | {
|
1660 | provide: _ACTION_TYPE_UNIQUENESS_CHECK,
|
1661 | multi: true,
|
1662 | deps: [_ACTIVE_RUNTIME_CHECKS],
|
1663 | useFactory: _actionTypeUniquenessCheck,
|
1664 | },
|
1665 | ];
|
1666 | }
|
1667 |
|
1668 |
|
1669 |
|
1670 |
|
1671 | function _runtimeChecksFactory(runtimeChecks) {
|
1672 | return runtimeChecks;
|
1673 | }
|
1674 |
|
1675 |
|
1676 |
|
1677 |
|
1678 | function _actionTypeUniquenessCheck(config) {
|
1679 | if (!config.strictActionTypeUniqueness) {
|
1680 | return;
|
1681 | }
|
1682 |
|
1683 | const duplicates = Object.entries(REGISTERED_ACTION_TYPES)
|
1684 | .filter(( |
1685 |
|
1686 |
|
1687 |
|
1688 | ([, registrations]) => registrations > 1))
|
1689 | .map(( |
1690 |
|
1691 |
|
1692 |
|
1693 | ([type]) => type));
|
1694 | if (duplicates.length) {
|
1695 | throw new Error(`Action types are registered more than once, ${duplicates
|
1696 | .map((/**
|
1697 | * @param {?} type
|
1698 | * @return {?}
|
1699 | */
|
1700 | (type) => `"${type}"`))
|
1701 | .join(', ')}. ${RUNTIME_CHECK_URL}#strictactiontypeuniqueness`);
|
1702 | }
|
1703 | }
|
1704 |
|
1705 |
|
1706 |
|
1707 |
|
1708 |
|
1709 |
|
1710 | class StoreRootModule {
|
1711 | |
1712 |
|
1713 |
|
1714 |
|
1715 |
|
1716 |
|
1717 |
|
1718 |
|
1719 | constructor(actions$, reducer$, scannedActions$, store, guard, actionCheck) { }
|
1720 | }
|
1721 | StoreRootModule.decorators = [
|
1722 | { type: NgModule, args: [{},] }
|
1723 | ];
|
1724 |
|
1725 | StoreRootModule.ctorParameters = () => [
|
1726 | { type: ActionsSubject },
|
1727 | { type: ReducerObservable },
|
1728 | { type: ScannedActionsSubject },
|
1729 | { type: Store },
|
1730 | { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [_ROOT_STORE_GUARD,] }] },
|
1731 | { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [_ACTION_TYPE_UNIQUENESS_CHECK,] }] }
|
1732 | ];
|
1733 | class StoreFeatureModule {
|
1734 | |
1735 |
|
1736 |
|
1737 |
|
1738 |
|
1739 |
|
1740 |
|
1741 | constructor(features, featureReducers, reducerManager, root, actionCheck) {
|
1742 | this.features = features;
|
1743 | this.featureReducers = featureReducers;
|
1744 | this.reducerManager = reducerManager;
|
1745 |
|
1746 | const feats = features.map(( |
1747 |
|
1748 |
|
1749 |
|
1750 |
|
1751 | (feature, index) => {
|
1752 |
|
1753 | const featureReducerCollection = featureReducers.shift();
|
1754 |
|
1755 | const reducers = ( (featureReducerCollection ))[index];
|
1756 | return Object.assign(Object.assign({}, feature), { reducers, initialState: _initialStateFactory(feature.initialState) });
|
1757 | }));
|
1758 | reducerManager.addFeatures(feats);
|
1759 | }
|
1760 | |
1761 |
|
1762 |
|
1763 | ngOnDestroy() {
|
1764 | this.reducerManager.removeFeatures(this.features);
|
1765 | }
|
1766 | }
|
1767 | StoreFeatureModule.decorators = [
|
1768 | { type: NgModule, args: [{},] }
|
1769 | ];
|
1770 |
|
1771 | StoreFeatureModule.ctorParameters = () => [
|
1772 | { type: Array, decorators: [{ type: Inject, args: [_STORE_FEATURES,] }] },
|
1773 | { type: Array, decorators: [{ type: Inject, args: [FEATURE_REDUCERS,] }] },
|
1774 | { type: ReducerManager },
|
1775 | { type: StoreRootModule },
|
1776 | { type: undefined, decorators: [{ type: Optional }, { type: Inject, args: [_ACTION_TYPE_UNIQUENESS_CHECK,] }] }
|
1777 | ];
|
1778 | if (false) {
|
1779 | |
1780 |
|
1781 |
|
1782 |
|
1783 | StoreFeatureModule.prototype.features;
|
1784 | |
1785 |
|
1786 |
|
1787 |
|
1788 | StoreFeatureModule.prototype.featureReducers;
|
1789 | |
1790 |
|
1791 |
|
1792 |
|
1793 | StoreFeatureModule.prototype.reducerManager;
|
1794 | }
|
1795 |
|
1796 |
|
1797 |
|
1798 |
|
1799 | function StoreConfig() { }
|
1800 | if (false) {
|
1801 |
|
1802 | StoreConfig.prototype.initialState;
|
1803 |
|
1804 | StoreConfig.prototype.reducerFactory;
|
1805 |
|
1806 | StoreConfig.prototype.metaReducers;
|
1807 | }
|
1808 |
|
1809 |
|
1810 |
|
1811 |
|
1812 | function RootStoreConfig() { }
|
1813 | if (false) {
|
1814 |
|
1815 | RootStoreConfig.prototype.runtimeChecks;
|
1816 | }
|
1817 |
|
1818 |
|
1819 |
|
1820 |
|
1821 |
|
1822 | function FeatureSlice() { }
|
1823 | if (false) {
|
1824 |
|
1825 | FeatureSlice.prototype.name;
|
1826 |
|
1827 | FeatureSlice.prototype.reducer;
|
1828 | }
|
1829 | class StoreModule {
|
1830 | |
1831 |
|
1832 |
|
1833 |
|
1834 |
|
1835 | static forRoot(reducers, config = {}) {
|
1836 | return {
|
1837 | ngModule: StoreRootModule,
|
1838 | providers: [
|
1839 | {
|
1840 | provide: _ROOT_STORE_GUARD,
|
1841 | useFactory: _provideForRootGuard,
|
1842 | deps: [[Store, new Optional(), new SkipSelf()]],
|
1843 | },
|
1844 | { provide: _INITIAL_STATE, useValue: config.initialState },
|
1845 | {
|
1846 | provide: INITIAL_STATE,
|
1847 | useFactory: _initialStateFactory,
|
1848 | deps: [_INITIAL_STATE],
|
1849 | },
|
1850 | { provide: _INITIAL_REDUCERS, useValue: reducers },
|
1851 | {
|
1852 | provide: _STORE_REDUCERS,
|
1853 | useExisting: reducers instanceof InjectionToken ? reducers : _INITIAL_REDUCERS,
|
1854 | },
|
1855 | {
|
1856 | provide: INITIAL_REDUCERS,
|
1857 | deps: [Injector, _INITIAL_REDUCERS, [new Inject(_STORE_REDUCERS)]],
|
1858 | useFactory: _createStoreReducers,
|
1859 | },
|
1860 | {
|
1861 | provide: USER_PROVIDED_META_REDUCERS,
|
1862 | useValue: config.metaReducers ? config.metaReducers : [],
|
1863 | },
|
1864 | {
|
1865 | provide: _RESOLVED_META_REDUCERS,
|
1866 | deps: [META_REDUCERS, USER_PROVIDED_META_REDUCERS],
|
1867 | useFactory: _concatMetaReducers,
|
1868 | },
|
1869 | {
|
1870 | provide: _REDUCER_FACTORY,
|
1871 | useValue: config.reducerFactory
|
1872 | ? config.reducerFactory
|
1873 | : combineReducers,
|
1874 | },
|
1875 | {
|
1876 | provide: REDUCER_FACTORY,
|
1877 | deps: [_REDUCER_FACTORY, _RESOLVED_META_REDUCERS],
|
1878 | useFactory: createReducerFactory,
|
1879 | },
|
1880 | ACTIONS_SUBJECT_PROVIDERS,
|
1881 | REDUCER_MANAGER_PROVIDERS,
|
1882 | SCANNED_ACTIONS_SUBJECT_PROVIDERS,
|
1883 | STATE_PROVIDERS,
|
1884 | STORE_PROVIDERS,
|
1885 | provideRuntimeChecks(config.runtimeChecks),
|
1886 | checkForActionTypeUniqueness(),
|
1887 | ],
|
1888 | };
|
1889 | }
|
1890 | |
1891 |
|
1892 |
|
1893 |
|
1894 |
|
1895 |
|
1896 | static forFeature(featureNameOrSlice, reducersOrConfig, config = {}) {
|
1897 | return {
|
1898 | ngModule: StoreFeatureModule,
|
1899 | providers: [
|
1900 | {
|
1901 | provide: _FEATURE_CONFIGS,
|
1902 | multi: true,
|
1903 | useValue: typeof featureNameOrSlice === 'string' ? config : {},
|
1904 | },
|
1905 | {
|
1906 | provide: STORE_FEATURES,
|
1907 | multi: true,
|
1908 | useValue: {
|
1909 | key: typeof featureNameOrSlice === 'string'
|
1910 | ? featureNameOrSlice
|
1911 | : featureNameOrSlice.name,
|
1912 | reducerFactory: !(config instanceof InjectionToken) && config.reducerFactory
|
1913 | ? config.reducerFactory
|
1914 | : combineReducers,
|
1915 | metaReducers: !(config instanceof InjectionToken) && config.metaReducers
|
1916 | ? config.metaReducers
|
1917 | : [],
|
1918 | initialState: !(config instanceof InjectionToken) && config.initialState
|
1919 | ? config.initialState
|
1920 | : undefined,
|
1921 | },
|
1922 | },
|
1923 | {
|
1924 | provide: _STORE_FEATURES,
|
1925 | deps: [Injector, _FEATURE_CONFIGS, STORE_FEATURES],
|
1926 | useFactory: _createFeatureStore,
|
1927 | },
|
1928 | {
|
1929 | provide: _FEATURE_REDUCERS,
|
1930 | multi: true,
|
1931 | useValue: typeof featureNameOrSlice === 'string'
|
1932 | ? reducersOrConfig
|
1933 | : featureNameOrSlice.reducer,
|
1934 | },
|
1935 | {
|
1936 | provide: _FEATURE_REDUCERS_TOKEN,
|
1937 | multi: true,
|
1938 | useExisting: reducersOrConfig instanceof InjectionToken
|
1939 | ? reducersOrConfig
|
1940 | : _FEATURE_REDUCERS,
|
1941 | },
|
1942 | {
|
1943 | provide: FEATURE_REDUCERS,
|
1944 | multi: true,
|
1945 | deps: [
|
1946 | Injector,
|
1947 | _FEATURE_REDUCERS,
|
1948 | [new Inject(_FEATURE_REDUCERS_TOKEN)],
|
1949 | ],
|
1950 | useFactory: _createFeatureReducers,
|
1951 | },
|
1952 | checkForActionTypeUniqueness(),
|
1953 | ],
|
1954 | };
|
1955 | }
|
1956 | }
|
1957 | StoreModule.decorators = [
|
1958 | { type: NgModule, args: [{},] }
|
1959 | ];
|
1960 |
|
1961 |
|
1962 |
|
1963 |
|
1964 |
|
1965 | function _createStoreReducers(injector, reducers) {
|
1966 | return reducers instanceof InjectionToken ? injector.get(reducers) : reducers;
|
1967 | }
|
1968 |
|
1969 |
|
1970 |
|
1971 |
|
1972 |
|
1973 |
|
1974 | function _createFeatureStore(injector, configs, featureStores) {
|
1975 | return featureStores.map(( |
1976 |
|
1977 |
|
1978 |
|
1979 |
|
1980 | (feat, index) => {
|
1981 | if (configs[index] instanceof InjectionToken) {
|
1982 |
|
1983 | const conf = injector.get(configs[index]);
|
1984 | return {
|
1985 | key: feat.key,
|
1986 | reducerFactory: conf.reducerFactory
|
1987 | ? conf.reducerFactory
|
1988 | : combineReducers,
|
1989 | metaReducers: conf.metaReducers ? conf.metaReducers : [],
|
1990 | initialState: conf.initialState,
|
1991 | };
|
1992 | }
|
1993 | return feat;
|
1994 | }));
|
1995 | }
|
1996 |
|
1997 |
|
1998 |
|
1999 |
|
2000 |
|
2001 | function _createFeatureReducers(injector, reducerCollection) {
|
2002 |
|
2003 | const reducers = reducerCollection.map(( |
2004 |
|
2005 |
|
2006 |
|
2007 | (reducer) => {
|
2008 | return reducer instanceof InjectionToken ? injector.get(reducer) : reducer;
|
2009 | }));
|
2010 | return reducers;
|
2011 | }
|
2012 |
|
2013 |
|
2014 |
|
2015 |
|
2016 | function _initialStateFactory(initialState) {
|
2017 | if (typeof initialState === 'function') {
|
2018 | return initialState();
|
2019 | }
|
2020 | return initialState;
|
2021 | }
|
2022 |
|
2023 |
|
2024 |
|
2025 |
|
2026 |
|
2027 | function _concatMetaReducers(metaReducers, userProvidedMetaReducers) {
|
2028 | return metaReducers.concat(userProvidedMetaReducers);
|
2029 | }
|
2030 |
|
2031 |
|
2032 |
|
2033 |
|
2034 | function _provideForRootGuard(store) {
|
2035 | if (store) {
|
2036 | throw new TypeError(`StoreModule.forRoot() called twice. Feature modules should use StoreModule.forFeature() instead.`);
|
2037 | }
|
2038 | return 'guarded';
|
2039 | }
|
2040 |
|
2041 |
|
2042 |
|
2043 |
|
2044 |
|
2045 |
|
2046 |
|
2047 |
|
2048 |
|
2049 |
|
2050 |
|
2051 |
|
2052 | function ReducerTypes() { }
|
2053 | if (false) {
|
2054 |
|
2055 | ReducerTypes.prototype.reducer;
|
2056 |
|
2057 | ReducerTypes.prototype.types;
|
2058 | }
|
2059 |
|
2060 |
|
2061 |
|
2062 |
|
2063 | function OnReducer() { }
|
2064 |
|
2065 |
|
2066 |
|
2067 |
|
2068 |
|
2069 |
|
2070 |
|
2071 |
|
2072 |
|
2073 |
|
2074 |
|
2075 |
|
2076 |
|
2077 |
|
2078 |
|
2079 | function on(...args) {
|
2080 |
|
2081 |
|
2082 |
|
2083 | const reducer = ( (args.pop()));
|
2084 |
|
2085 | const types = ( ((( ((( ((( (args)))))).map(( |
2086 |
|
2087 |
|
2088 |
|
2089 | (creator) => creator.type)))))));
|
2090 | return { reducer, types };
|
2091 | }
|
2092 |
|
2093 |
|
2094 |
|
2095 |
|
2096 |
|
2097 |
|
2098 |
|
2099 |
|
2100 |
|
2101 |
|
2102 |
|
2103 |
|
2104 |
|
2105 |
|
2106 |
|
2107 |
|
2108 |
|
2109 |
|
2110 |
|
2111 |
|
2112 |
|
2113 |
|
2114 |
|
2115 |
|
2116 |
|
2117 |
|
2118 |
|
2119 |
|
2120 |
|
2121 |
|
2122 |
|
2123 |
|
2124 |
|
2125 |
|
2126 |
|
2127 |
|
2128 |
|
2129 |
|
2130 |
|
2131 |
|
2132 |
|
2133 |
|
2134 |
|
2135 |
|
2136 |
|
2137 |
|
2138 |
|
2139 |
|
2140 |
|
2141 | function createReducer(initialState, ...ons) {
|
2142 |
|
2143 | const map = new Map();
|
2144 | for (let on of ons) {
|
2145 | for (let type of on.types) {
|
2146 |
|
2147 | const existingReducer = map.get(type);
|
2148 | if (existingReducer) {
|
2149 |
|
2150 | const newReducer = ( |
2151 |
|
2152 |
|
2153 |
|
2154 |
|
2155 | (state, action) => on.reducer(existingReducer(state, action), action));
|
2156 | map.set(type, newReducer);
|
2157 | }
|
2158 | else {
|
2159 | map.set(type, on.reducer);
|
2160 | }
|
2161 | }
|
2162 | }
|
2163 | return ( |
2164 |
|
2165 |
|
2166 |
|
2167 |
|
2168 | function (state = initialState, action) {
|
2169 |
|
2170 | const reducer = map.get(action.type);
|
2171 | return reducer ? reducer(state, action) : state;
|
2172 | });
|
2173 | }
|
2174 |
|
2175 |
|
2176 |
|
2177 |
|
2178 |
|
2179 |
|
2180 |
|
2181 |
|
2182 |
|
2183 |
|
2184 |
|
2185 |
|
2186 |
|
2187 |
|
2188 |
|
2189 |
|
2190 |
|
2191 |
|
2192 |
|
2193 |
|
2194 |
|
2195 |
|
2196 |
|
2197 |
|
2198 |
|
2199 | export { ActionsSubject, FEATURE_REDUCERS, INIT, INITIAL_REDUCERS, INITIAL_STATE, META_REDUCERS, REDUCER_FACTORY, ReducerManager, ReducerManagerDispatcher, ReducerObservable, STORE_FEATURES, ScannedActionsSubject, State, StateObservable, Store, StoreFeatureModule, StoreModule, StoreRootModule, UPDATE, USER_PROVIDED_META_REDUCERS, USER_RUNTIME_CHECKS, combineReducers, compose, createAction, createFeatureSelector, createReducer, createReducerFactory, createSelector, createSelectorFactory, defaultMemoize, defaultStateFn, isNgrxMockEnvironment, on, props, reduceState, resultMemoize, select, setNgrxMockEnvironment, union, STORE_PROVIDERS as ɵb, createActiveRuntimeChecks as ɵba, createSerializationCheckMetaReducer as ɵbb, createImmutabilityCheckMetaReducer as ɵbc, createInNgZoneCheckMetaReducer as ɵbd, provideRuntimeChecks as ɵbe, checkForActionTypeUniqueness as ɵbf, _runtimeChecksFactory as ɵbg, _actionTypeUniquenessCheck as ɵbh, ACTIONS_SUBJECT_PROVIDERS as ɵc, REDUCER_MANAGER_PROVIDERS as ɵd, SCANNED_ACTIONS_SUBJECT_PROVIDERS as ɵe, isEqualCheck as ɵf, STATE_PROVIDERS as ɵg, _ROOT_STORE_GUARD as ɵh, _INITIAL_STATE as ɵi, _REDUCER_FACTORY as ɵj, _INITIAL_REDUCERS as ɵk, _STORE_REDUCERS as ɵl, _FEATURE_REDUCERS as ɵm, _FEATURE_CONFIGS as ɵn, _STORE_FEATURES as ɵo, _FEATURE_REDUCERS_TOKEN as ɵp, _RESOLVED_META_REDUCERS as ɵq, _USER_RUNTIME_CHECKS as ɵr, _ACTIVE_RUNTIME_CHECKS as ɵs, _ACTION_TYPE_UNIQUENESS_CHECK as ɵt, _createStoreReducers as ɵu, _createFeatureStore as ɵv, _createFeatureReducers as ɵw, _initialStateFactory as ɵx, _concatMetaReducers as ɵy, _provideForRootGuard as ɵz };
|
2200 |
|