1 | import * as i0 from '@angular/core';
|
2 | import { Injectable, InjectionToken, Inject, isDevMode, inject, makeEnvironmentProviders, ENVIRONMENT_INITIALIZER, NgModule, Optional } from '@angular/core';
|
3 | import { BehaviorSubject, Observable, Subject, queueScheduler } from 'rxjs';
|
4 | import { observeOn, withLatestFrom, scan, pluck, map, distinctUntilChanged } from 'rxjs/operators';
|
5 |
|
6 | const REGISTERED_ACTION_TYPES = {};
|
7 | function resetRegisteredActionTypes() {
|
8 | for (const key of Object.keys(REGISTERED_ACTION_TYPES)) {
|
9 | delete REGISTERED_ACTION_TYPES[key];
|
10 | }
|
11 | }
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
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 | function createAction(type, config) {
|
86 | REGISTERED_ACTION_TYPES[type] = (REGISTERED_ACTION_TYPES[type] || 0) + 1;
|
87 | if (typeof config === 'function') {
|
88 | return defineType(type, (...args) => ({
|
89 | ...config(...args),
|
90 | type,
|
91 | }));
|
92 | }
|
93 | const as = config ? config._as : 'empty';
|
94 | switch (as) {
|
95 | case 'empty':
|
96 | return defineType(type, () => ({ type }));
|
97 | case 'props':
|
98 | return defineType(type, (props) => ({
|
99 | ...props,
|
100 | type,
|
101 | }));
|
102 | default:
|
103 | throw new Error('Unexpected config.');
|
104 | }
|
105 | }
|
106 | function props() {
|
107 |
|
108 | return { _as: 'props', _p: undefined };
|
109 | }
|
110 | function union(creators) {
|
111 |
|
112 | return undefined;
|
113 | }
|
114 | function defineType(type, creator) {
|
115 | return Object.defineProperty(creator, 'type', {
|
116 | value: type,
|
117 | writable: false,
|
118 | });
|
119 | }
|
120 |
|
121 | function capitalize(text) {
|
122 | return (text.charAt(0).toUpperCase() + text.substring(1));
|
123 | }
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 |
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 | function createActionGroup(config) {
|
167 | const { source, events } = config;
|
168 | return Object.keys(events).reduce((actionGroup, eventName) => ({
|
169 | ...actionGroup,
|
170 | [toActionName(eventName)]: createAction(toActionType(source, eventName), events[eventName]),
|
171 | }), {});
|
172 | }
|
173 | function emptyProps() {
|
174 | return props();
|
175 | }
|
176 | function toActionName(eventName) {
|
177 | return eventName
|
178 | .trim()
|
179 | .toLowerCase()
|
180 | .split(' ')
|
181 | .map((word, i) => (i === 0 ? word : capitalize(word)))
|
182 | .join('');
|
183 | }
|
184 | function toActionType(source, eventName) {
|
185 | return `[${source}] ${eventName}`;
|
186 | }
|
187 |
|
188 | const INIT = '@ngrx/store/init';
|
189 | class ActionsSubject extends BehaviorSubject {
|
190 | constructor() {
|
191 | super({ type: INIT });
|
192 | }
|
193 | next(action) {
|
194 | if (typeof action === 'function') {
|
195 | throw new TypeError(`
|
196 | Dispatch expected an object, instead it received a function.
|
197 | If you're using the createAction function, make sure to invoke the function
|
198 | before dispatching the action. For example, someAction should be someAction().`);
|
199 | }
|
200 | else if (typeof action === 'undefined') {
|
201 | throw new TypeError(`Actions must be objects`);
|
202 | }
|
203 | else if (typeof action.type === 'undefined') {
|
204 | throw new TypeError(`Actions must have a type property`);
|
205 | }
|
206 | super.next(action);
|
207 | }
|
208 | complete() {
|
209 |
|
210 | }
|
211 | ngOnDestroy() {
|
212 | super.complete();
|
213 | }
|
214 | }
|
215 | ActionsSubject.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: ActionsSubject, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
216 | ActionsSubject.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: ActionsSubject });
|
217 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: ActionsSubject, decorators: [{
|
218 | type: Injectable
|
219 | }], ctorParameters: function () { return []; } });
|
220 | const ACTIONS_SUBJECT_PROVIDERS = [ActionsSubject];
|
221 |
|
222 | const _ROOT_STORE_GUARD = new InjectionToken('@ngrx/store Internal Root Guard');
|
223 | const _INITIAL_STATE = new InjectionToken('@ngrx/store Internal Initial State');
|
224 | const INITIAL_STATE = new InjectionToken('@ngrx/store Initial State');
|
225 | const REDUCER_FACTORY = new InjectionToken('@ngrx/store Reducer Factory');
|
226 | const _REDUCER_FACTORY = new InjectionToken('@ngrx/store Internal Reducer Factory Provider');
|
227 | const INITIAL_REDUCERS = new InjectionToken('@ngrx/store Initial Reducers');
|
228 | const _INITIAL_REDUCERS = new InjectionToken('@ngrx/store Internal Initial Reducers');
|
229 | const STORE_FEATURES = new InjectionToken('@ngrx/store Store Features');
|
230 | const _STORE_REDUCERS = new InjectionToken('@ngrx/store Internal Store Reducers');
|
231 | const _FEATURE_REDUCERS = new InjectionToken('@ngrx/store Internal Feature Reducers');
|
232 | const _FEATURE_CONFIGS = new InjectionToken('@ngrx/store Internal Feature Configs');
|
233 | const _STORE_FEATURES = new InjectionToken('@ngrx/store Internal Store Features');
|
234 | const _FEATURE_REDUCERS_TOKEN = new InjectionToken('@ngrx/store Internal Feature Reducers Token');
|
235 | const FEATURE_REDUCERS = new InjectionToken('@ngrx/store Feature Reducers');
|
236 |
|
237 |
|
238 |
|
239 | const USER_PROVIDED_META_REDUCERS = new InjectionToken('@ngrx/store User Provided Meta Reducers');
|
240 |
|
241 |
|
242 |
|
243 | const META_REDUCERS = new InjectionToken('@ngrx/store Meta Reducers');
|
244 |
|
245 |
|
246 |
|
247 |
|
248 | const _RESOLVED_META_REDUCERS = new InjectionToken('@ngrx/store Internal Resolved Meta Reducers');
|
249 |
|
250 |
|
251 |
|
252 |
|
253 | const USER_RUNTIME_CHECKS = new InjectionToken('@ngrx/store User Runtime Checks Config');
|
254 |
|
255 |
|
256 |
|
257 | const _USER_RUNTIME_CHECKS = new InjectionToken('@ngrx/store Internal User Runtime Checks Config');
|
258 |
|
259 |
|
260 |
|
261 | const ACTIVE_RUNTIME_CHECKS = new InjectionToken('@ngrx/store Internal Runtime Checks');
|
262 | const _ACTION_TYPE_UNIQUENESS_CHECK = new InjectionToken('@ngrx/store Check if Action types are unique');
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 | const ROOT_STORE_PROVIDER = new InjectionToken('@ngrx/store Root Store Provider');
|
270 |
|
271 |
|
272 |
|
273 |
|
274 |
|
275 |
|
276 | const FEATURE_STATE_PROVIDER = new InjectionToken('@ngrx/store Feature State Provider');
|
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 | function combineReducers(reducers, initialState = {}) {
|
312 | const reducerKeys = Object.keys(reducers);
|
313 | const finalReducers = {};
|
314 | for (let i = 0; i < reducerKeys.length; i++) {
|
315 | const key = reducerKeys[i];
|
316 | if (typeof reducers[key] === 'function') {
|
317 | finalReducers[key] = reducers[key];
|
318 | }
|
319 | }
|
320 | const finalReducerKeys = Object.keys(finalReducers);
|
321 | return function combination(state, action) {
|
322 | state = state === undefined ? initialState : state;
|
323 | let hasChanged = false;
|
324 | const nextState = {};
|
325 | for (let i = 0; i < finalReducerKeys.length; i++) {
|
326 | const key = finalReducerKeys[i];
|
327 | const reducer = finalReducers[key];
|
328 | const previousStateForKey = state[key];
|
329 | const nextStateForKey = reducer(previousStateForKey, action);
|
330 | nextState[key] = nextStateForKey;
|
331 | hasChanged = hasChanged || nextStateForKey !== previousStateForKey;
|
332 | }
|
333 | return hasChanged ? nextState : state;
|
334 | };
|
335 | }
|
336 | function omit(object, keyToRemove) {
|
337 | return Object.keys(object)
|
338 | .filter((key) => key !== keyToRemove)
|
339 | .reduce((result, key) => Object.assign(result, { [key]: object[key] }), {});
|
340 | }
|
341 | function compose(...functions) {
|
342 | return function (arg) {
|
343 | if (functions.length === 0) {
|
344 | return arg;
|
345 | }
|
346 | const last = functions[functions.length - 1];
|
347 | const rest = functions.slice(0, -1);
|
348 | return rest.reduceRight((composed, fn) => fn(composed), last(arg));
|
349 | };
|
350 | }
|
351 | function createReducerFactory(reducerFactory, metaReducers) {
|
352 | if (Array.isArray(metaReducers) && metaReducers.length > 0) {
|
353 | reducerFactory = compose.apply(null, [
|
354 | ...metaReducers,
|
355 | reducerFactory,
|
356 | ]);
|
357 | }
|
358 | return (reducers, initialState) => {
|
359 | const reducer = reducerFactory(reducers);
|
360 | return (state, action) => {
|
361 | state = state === undefined ? initialState : state;
|
362 | return reducer(state, action);
|
363 | };
|
364 | };
|
365 | }
|
366 | function createFeatureReducerFactory(metaReducers) {
|
367 | const reducerFactory = Array.isArray(metaReducers) && metaReducers.length > 0
|
368 | ? compose(...metaReducers)
|
369 | : (r) => r;
|
370 | return (reducer, initialState) => {
|
371 | reducer = reducerFactory(reducer);
|
372 | return (state, action) => {
|
373 | state = state === undefined ? initialState : state;
|
374 | return reducer(state, action);
|
375 | };
|
376 | };
|
377 | }
|
378 |
|
379 | class ReducerObservable extends Observable {
|
380 | }
|
381 | class ReducerManagerDispatcher extends ActionsSubject {
|
382 | }
|
383 | const UPDATE = '@ngrx/store/update-reducers';
|
384 | class ReducerManager extends BehaviorSubject {
|
385 | constructor(dispatcher, initialState, reducers, reducerFactory) {
|
386 | super(reducerFactory(reducers, initialState));
|
387 | this.dispatcher = dispatcher;
|
388 | this.initialState = initialState;
|
389 | this.reducers = reducers;
|
390 | this.reducerFactory = reducerFactory;
|
391 | }
|
392 | get currentReducers() {
|
393 | return this.reducers;
|
394 | }
|
395 | addFeature(feature) {
|
396 | this.addFeatures([feature]);
|
397 | }
|
398 | addFeatures(features) {
|
399 | const reducers = features.reduce((reducerDict, { reducers, reducerFactory, metaReducers, initialState, key }) => {
|
400 | const reducer = typeof reducers === 'function'
|
401 | ? createFeatureReducerFactory(metaReducers)(reducers, initialState)
|
402 | : createReducerFactory(reducerFactory, metaReducers)(reducers, initialState);
|
403 | reducerDict[key] = reducer;
|
404 | return reducerDict;
|
405 | }, {});
|
406 | this.addReducers(reducers);
|
407 | }
|
408 | removeFeature(feature) {
|
409 | this.removeFeatures([feature]);
|
410 | }
|
411 | removeFeatures(features) {
|
412 | this.removeReducers(features.map((p) => p.key));
|
413 | }
|
414 | addReducer(key, reducer) {
|
415 | this.addReducers({ [key]: reducer });
|
416 | }
|
417 | addReducers(reducers) {
|
418 | this.reducers = { ...this.reducers, ...reducers };
|
419 | this.updateReducers(Object.keys(reducers));
|
420 | }
|
421 | removeReducer(featureKey) {
|
422 | this.removeReducers([featureKey]);
|
423 | }
|
424 | removeReducers(featureKeys) {
|
425 | featureKeys.forEach((key) => {
|
426 | this.reducers = omit(this.reducers, key) ;
|
427 | });
|
428 | this.updateReducers(featureKeys);
|
429 | }
|
430 | updateReducers(featureKeys) {
|
431 | this.next(this.reducerFactory(this.reducers, this.initialState));
|
432 | this.dispatcher.next({
|
433 | type: UPDATE,
|
434 | features: featureKeys,
|
435 | });
|
436 | }
|
437 | ngOnDestroy() {
|
438 | this.complete();
|
439 | }
|
440 | }
|
441 | ReducerManager.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: ReducerManager, deps: [{ token: ReducerManagerDispatcher }, { token: INITIAL_STATE }, { token: INITIAL_REDUCERS }, { token: REDUCER_FACTORY }], target: i0.ɵɵFactoryTarget.Injectable });
|
442 | ReducerManager.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: ReducerManager });
|
443 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: ReducerManager, decorators: [{
|
444 | type: Injectable
|
445 | }], ctorParameters: function () { return [{ type: ReducerManagerDispatcher }, { type: undefined, decorators: [{
|
446 | type: Inject,
|
447 | args: [INITIAL_STATE]
|
448 | }] }, { type: undefined, decorators: [{
|
449 | type: Inject,
|
450 | args: [INITIAL_REDUCERS]
|
451 | }] }, { type: undefined, decorators: [{
|
452 | type: Inject,
|
453 | args: [REDUCER_FACTORY]
|
454 | }] }]; } });
|
455 | const REDUCER_MANAGER_PROVIDERS = [
|
456 | ReducerManager,
|
457 | { provide: ReducerObservable, useExisting: ReducerManager },
|
458 | { provide: ReducerManagerDispatcher, useExisting: ActionsSubject },
|
459 | ];
|
460 |
|
461 | class ScannedActionsSubject extends Subject {
|
462 | ngOnDestroy() {
|
463 | this.complete();
|
464 | }
|
465 | }
|
466 | ScannedActionsSubject.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: ScannedActionsSubject, deps: null, target: i0.ɵɵFactoryTarget.Injectable });
|
467 | ScannedActionsSubject.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: ScannedActionsSubject });
|
468 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: ScannedActionsSubject, decorators: [{
|
469 | type: Injectable
|
470 | }] });
|
471 | const SCANNED_ACTIONS_SUBJECT_PROVIDERS = [
|
472 | ScannedActionsSubject,
|
473 | ];
|
474 |
|
475 | class StateObservable extends Observable {
|
476 | }
|
477 | class State extends BehaviorSubject {
|
478 | constructor(actions$, reducer$, scannedActions, initialState) {
|
479 | super(initialState);
|
480 | const actionsOnQueue$ = actions$.pipe(observeOn(queueScheduler));
|
481 | const withLatestReducer$ = actionsOnQueue$.pipe(withLatestFrom(reducer$));
|
482 | const seed = { state: initialState };
|
483 | const stateAndAction$ = withLatestReducer$.pipe(scan(reduceState, seed));
|
484 | this.stateSubscription = stateAndAction$.subscribe(({ state, action }) => {
|
485 | this.next(state);
|
486 | scannedActions.next(action);
|
487 | });
|
488 | }
|
489 | ngOnDestroy() {
|
490 | this.stateSubscription.unsubscribe();
|
491 | this.complete();
|
492 | }
|
493 | }
|
494 | State.INIT = INIT;
|
495 | State.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: State, deps: [{ token: ActionsSubject }, { token: ReducerObservable }, { token: ScannedActionsSubject }, { token: INITIAL_STATE }], target: i0.ɵɵFactoryTarget.Injectable });
|
496 | State.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: State });
|
497 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: State, decorators: [{
|
498 | type: Injectable
|
499 | }], ctorParameters: function () { return [{ type: ActionsSubject }, { type: ReducerObservable }, { type: ScannedActionsSubject }, { type: undefined, decorators: [{
|
500 | type: Inject,
|
501 | args: [INITIAL_STATE]
|
502 | }] }]; } });
|
503 | function reduceState(stateActionPair = { state: undefined }, [action, reducer]) {
|
504 | const { state } = stateActionPair;
|
505 | return { state: reducer(state, action), action };
|
506 | }
|
507 | const STATE_PROVIDERS = [
|
508 | State,
|
509 | { provide: StateObservable, useExisting: State },
|
510 | ];
|
511 |
|
512 |
|
513 | class Store extends Observable {
|
514 | constructor(state$, actionsObserver, reducerManager) {
|
515 | super();
|
516 | this.actionsObserver = actionsObserver;
|
517 | this.reducerManager = reducerManager;
|
518 | this.source = state$;
|
519 | }
|
520 | select(pathOrMapFn, ...paths) {
|
521 | return select.call(null, pathOrMapFn, ...paths)(this);
|
522 | }
|
523 | lift(operator) {
|
524 | const store = new Store(this, this.actionsObserver, this.reducerManager);
|
525 | store.operator = operator;
|
526 | return store;
|
527 | }
|
528 | dispatch(action) {
|
529 | this.actionsObserver.next(action);
|
530 | }
|
531 | next(action) {
|
532 | this.actionsObserver.next(action);
|
533 | }
|
534 | error(err) {
|
535 | this.actionsObserver.error(err);
|
536 | }
|
537 | complete() {
|
538 | this.actionsObserver.complete();
|
539 | }
|
540 | addReducer(key, reducer) {
|
541 | this.reducerManager.addReducer(key, reducer);
|
542 | }
|
543 | removeReducer(key) {
|
544 | this.reducerManager.removeReducer(key);
|
545 | }
|
546 | }
|
547 | Store.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: Store, deps: [{ token: StateObservable }, { token: ActionsSubject }, { token: ReducerManager }], target: i0.ɵɵFactoryTarget.Injectable });
|
548 | Store.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: Store });
|
549 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: Store, decorators: [{
|
550 | type: Injectable
|
551 | }], ctorParameters: function () { return [{ type: StateObservable }, { type: ActionsSubject }, { type: ReducerManager }]; } });
|
552 | const STORE_PROVIDERS = [Store];
|
553 | function select(pathOrMapFn, propsOrPath, ...paths) {
|
554 | return function selectOperator(source$) {
|
555 | let mapped$;
|
556 | if (typeof pathOrMapFn === 'string') {
|
557 | const pathSlices = [propsOrPath, ...paths].filter(Boolean);
|
558 | mapped$ = source$.pipe(pluck(pathOrMapFn, ...pathSlices));
|
559 | }
|
560 | else if (typeof pathOrMapFn === 'function') {
|
561 | mapped$ = source$.pipe(map((source) => pathOrMapFn(source, propsOrPath)));
|
562 | }
|
563 | else {
|
564 | throw new TypeError(`Unexpected type '${typeof pathOrMapFn}' in select operator,` +
|
565 | ` expected 'string' or 'function'`);
|
566 | }
|
567 | return mapped$.pipe(distinctUntilChanged());
|
568 | };
|
569 | }
|
570 |
|
571 | const RUNTIME_CHECK_URL = 'https://ngrx.io/guide/store/configuration/runtime-checks';
|
572 | function isUndefined(target) {
|
573 | return target === undefined;
|
574 | }
|
575 | function isNull(target) {
|
576 | return target === null;
|
577 | }
|
578 | function isArray(target) {
|
579 | return Array.isArray(target);
|
580 | }
|
581 | function isString(target) {
|
582 | return typeof target === 'string';
|
583 | }
|
584 | function isBoolean(target) {
|
585 | return typeof target === 'boolean';
|
586 | }
|
587 | function isNumber(target) {
|
588 | return typeof target === 'number';
|
589 | }
|
590 | function isObjectLike(target) {
|
591 | return typeof target === 'object' && target !== null;
|
592 | }
|
593 | function isObject(target) {
|
594 | return isObjectLike(target) && !isArray(target);
|
595 | }
|
596 | function isPlainObject(target) {
|
597 | if (!isObject(target)) {
|
598 | return false;
|
599 | }
|
600 | const targetPrototype = Object.getPrototypeOf(target);
|
601 | return targetPrototype === Object.prototype || targetPrototype === null;
|
602 | }
|
603 | function isFunction(target) {
|
604 | return typeof target === 'function';
|
605 | }
|
606 | function isComponent(target) {
|
607 | return isFunction(target) && target.hasOwnProperty('ɵcmp');
|
608 | }
|
609 | function hasOwnProperty(target, propertyName) {
|
610 | return Object.prototype.hasOwnProperty.call(target, propertyName);
|
611 | }
|
612 |
|
613 | let _ngrxMockEnvironment = false;
|
614 | function setNgrxMockEnvironment(value) {
|
615 | _ngrxMockEnvironment = value;
|
616 | }
|
617 | function isNgrxMockEnvironment() {
|
618 | return _ngrxMockEnvironment;
|
619 | }
|
620 |
|
621 | function isEqualCheck(a, b) {
|
622 | return a === b;
|
623 | }
|
624 | function isArgumentsChanged(args, lastArguments, comparator) {
|
625 | for (let i = 0; i < args.length; i++) {
|
626 | if (!comparator(args[i], lastArguments[i])) {
|
627 | return true;
|
628 | }
|
629 | }
|
630 | return false;
|
631 | }
|
632 | function resultMemoize(projectionFn, isResultEqual) {
|
633 | return defaultMemoize(projectionFn, isEqualCheck, isResultEqual);
|
634 | }
|
635 | function defaultMemoize(projectionFn, isArgumentsEqual = isEqualCheck, isResultEqual = isEqualCheck) {
|
636 | let lastArguments = null;
|
637 |
|
638 | let lastResult = null;
|
639 | let overrideResult;
|
640 | function reset() {
|
641 | lastArguments = null;
|
642 | lastResult = null;
|
643 | }
|
644 | function setResult(result = undefined) {
|
645 | overrideResult = { result };
|
646 | }
|
647 | function clearResult() {
|
648 | overrideResult = undefined;
|
649 | }
|
650 |
|
651 |
|
652 | function memoized() {
|
653 | if (overrideResult !== undefined) {
|
654 | return overrideResult.result;
|
655 | }
|
656 | if (!lastArguments) {
|
657 | lastResult = projectionFn.apply(null, arguments);
|
658 | lastArguments = arguments;
|
659 | return lastResult;
|
660 | }
|
661 | if (!isArgumentsChanged(arguments, lastArguments, isArgumentsEqual)) {
|
662 | return lastResult;
|
663 | }
|
664 | const newResult = projectionFn.apply(null, arguments);
|
665 | lastArguments = arguments;
|
666 | if (isResultEqual(lastResult, newResult)) {
|
667 | return lastResult;
|
668 | }
|
669 | lastResult = newResult;
|
670 | return newResult;
|
671 | }
|
672 | return { memoized, reset, setResult, clearResult };
|
673 | }
|
674 | function createSelector(...input) {
|
675 | return createSelectorFactory(defaultMemoize)(...input);
|
676 | }
|
677 | function defaultStateFn(state, selectors, props, memoizedProjector) {
|
678 | if (props === undefined) {
|
679 | const args = selectors.map((fn) => fn(state));
|
680 | return memoizedProjector.memoized.apply(null, args);
|
681 | }
|
682 | const args = selectors.map((fn) => fn(state, props));
|
683 | return memoizedProjector.memoized.apply(null, [...args, props]);
|
684 | }
|
685 |
|
686 |
|
687 |
|
688 |
|
689 |
|
690 |
|
691 |
|
692 |
|
693 |
|
694 |
|
695 |
|
696 |
|
697 |
|
698 |
|
699 |
|
700 |
|
701 |
|
702 |
|
703 |
|
704 |
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 |
|
712 |
|
713 |
|
714 |
|
715 |
|
716 |
|
717 |
|
718 |
|
719 |
|
720 |
|
721 |
|
722 |
|
723 |
|
724 |
|
725 |
|
726 |
|
727 |
|
728 |
|
729 |
|
730 |
|
731 |
|
732 |
|
733 |
|
734 |
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 |
|
742 |
|
743 |
|
744 |
|
745 |
|
746 |
|
747 |
|
748 |
|
749 |
|
750 |
|
751 |
|
752 |
|
753 |
|
754 |
|
755 |
|
756 |
|
757 |
|
758 |
|
759 |
|
760 |
|
761 | function createSelectorFactory(memoize, options = {
|
762 | stateFn: defaultStateFn,
|
763 | }) {
|
764 | return function (...input) {
|
765 | let args = input;
|
766 | if (Array.isArray(args[0])) {
|
767 | const [head, ...tail] = args;
|
768 | args = [...head, ...tail];
|
769 | }
|
770 | else if (args.length === 1 && isSelectorsDictionary(args[0])) {
|
771 | args = extractArgsFromSelectorsDictionary(args[0]);
|
772 | }
|
773 | const selectors = args.slice(0, args.length - 1);
|
774 | const projector = args[args.length - 1];
|
775 | const memoizedSelectors = selectors.filter((selector) => selector.release && typeof selector.release === 'function');
|
776 | const memoizedProjector = memoize(function (...selectors) {
|
777 | return projector.apply(null, selectors);
|
778 | });
|
779 | const memoizedState = defaultMemoize(function (state, props) {
|
780 | return options.stateFn.apply(null, [
|
781 | state,
|
782 | selectors,
|
783 | props,
|
784 | memoizedProjector,
|
785 | ]);
|
786 | });
|
787 | function release() {
|
788 | memoizedState.reset();
|
789 | memoizedProjector.reset();
|
790 | memoizedSelectors.forEach((selector) => selector.release());
|
791 | }
|
792 | return Object.assign(memoizedState.memoized, {
|
793 | release,
|
794 | projector: memoizedProjector.memoized,
|
795 | setResult: memoizedState.setResult,
|
796 | clearResult: memoizedState.clearResult,
|
797 | });
|
798 | };
|
799 | }
|
800 | function createFeatureSelector(featureName) {
|
801 | return createSelector((state) => {
|
802 | const featureState = state[featureName];
|
803 | if (!isNgrxMockEnvironment() && isDevMode() && !(featureName in state)) {
|
804 | console.warn(`@ngrx/store: The feature name "${featureName}" does ` +
|
805 | 'not exist in the state, therefore createFeatureSelector ' +
|
806 | 'cannot access it. Be sure it is imported in a loaded module ' +
|
807 | `using StoreModule.forRoot('${featureName}', ...) or ` +
|
808 | `StoreModule.forFeature('${featureName}', ...). If the default ` +
|
809 | 'state is intended to be undefined, as is the case with router ' +
|
810 | 'state, this development-only warning message can be ignored.');
|
811 | }
|
812 | return featureState;
|
813 | }, (featureState) => featureState);
|
814 | }
|
815 | function isSelectorsDictionary(selectors) {
|
816 | return (!!selectors &&
|
817 | typeof selectors === 'object' &&
|
818 | Object.values(selectors).every((selector) => typeof selector === 'function'));
|
819 | }
|
820 | function extractArgsFromSelectorsDictionary(selectorsDictionary) {
|
821 | const selectors = Object.values(selectorsDictionary);
|
822 | const resultKeys = Object.keys(selectorsDictionary);
|
823 | const projector = (...selectorResults) => resultKeys.reduce((result, key, index) => ({
|
824 | ...result,
|
825 | [key]: selectorResults[index],
|
826 | }), {});
|
827 | return [...selectors, projector];
|
828 | }
|
829 |
|
830 |
|
831 |
|
832 |
|
833 |
|
834 |
|
835 |
|
836 |
|
837 |
|
838 |
|
839 |
|
840 |
|
841 |
|
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 |
|
848 |
|
849 |
|
850 |
|
851 |
|
852 |
|
853 |
|
854 |
|
855 |
|
856 |
|
857 |
|
858 |
|
859 |
|
860 |
|
861 |
|
862 |
|
863 |
|
864 |
|
865 |
|
866 |
|
867 |
|
868 |
|
869 |
|
870 |
|
871 |
|
872 |
|
873 |
|
874 |
|
875 |
|
876 |
|
877 |
|
878 |
|
879 |
|
880 |
|
881 |
|
882 |
|
883 |
|
884 |
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 |
|
906 |
|
907 |
|
908 |
|
909 |
|
910 |
|
911 |
|
912 |
|
913 |
|
914 |
|
915 |
|
916 |
|
917 |
|
918 |
|
919 |
|
920 | function createFeature(featureConfig) {
|
921 | const { name, reducer, extraSelectors: extraSelectorsFactory, } = featureConfig;
|
922 | const featureSelector = createFeatureSelector(name);
|
923 | const nestedSelectors = createNestedSelectors(featureSelector, reducer);
|
924 | const baseSelectors = {
|
925 | [`select${capitalize(name)}State`]: featureSelector,
|
926 | ...nestedSelectors,
|
927 | };
|
928 | const extraSelectors = extraSelectorsFactory
|
929 | ? extraSelectorsFactory(baseSelectors)
|
930 | : {};
|
931 | return {
|
932 | name,
|
933 | reducer,
|
934 | ...baseSelectors,
|
935 | ...extraSelectors,
|
936 | };
|
937 | }
|
938 | function createNestedSelectors(featureSelector, reducer) {
|
939 | const initialState = getInitialState(reducer);
|
940 | const nestedKeys = (isPlainObject(initialState) ? Object.keys(initialState) : []);
|
941 | return nestedKeys.reduce((nestedSelectors, nestedKey) => ({
|
942 | ...nestedSelectors,
|
943 | [`select${capitalize(nestedKey)}`]: createSelector(featureSelector, (parentState) => parentState?.[nestedKey]),
|
944 | }), {});
|
945 | }
|
946 | function getInitialState(reducer) {
|
947 | return reducer(undefined, { type: '@ngrx/feature/init' });
|
948 | }
|
949 |
|
950 | function _createStoreReducers(reducers) {
|
951 | return reducers instanceof InjectionToken ? inject(reducers) : reducers;
|
952 | }
|
953 | function _createFeatureStore(configs, featureStores) {
|
954 | return featureStores.map((feat, index) => {
|
955 | if (configs[index] instanceof InjectionToken) {
|
956 | const conf = inject(configs[index]);
|
957 | return {
|
958 | key: feat.key,
|
959 | reducerFactory: conf.reducerFactory
|
960 | ? conf.reducerFactory
|
961 | : combineReducers,
|
962 | metaReducers: conf.metaReducers ? conf.metaReducers : [],
|
963 | initialState: conf.initialState,
|
964 | };
|
965 | }
|
966 | return feat;
|
967 | });
|
968 | }
|
969 | function _createFeatureReducers(reducerCollection) {
|
970 | return reducerCollection.map((reducer) => {
|
971 | return reducer instanceof InjectionToken ? inject(reducer) : reducer;
|
972 | });
|
973 | }
|
974 | function _initialStateFactory(initialState) {
|
975 | if (typeof initialState === 'function') {
|
976 | return initialState();
|
977 | }
|
978 | return initialState;
|
979 | }
|
980 | function _concatMetaReducers(metaReducers, userProvidedMetaReducers) {
|
981 | return metaReducers.concat(userProvidedMetaReducers);
|
982 | }
|
983 | function _provideForRootGuard() {
|
984 | const store = inject(Store, { optional: true, skipSelf: true });
|
985 | if (store) {
|
986 | throw new TypeError(`The root Store has been provided more than once. Feature modules should provide feature states instead.`);
|
987 | }
|
988 | return 'guarded';
|
989 | }
|
990 |
|
991 | function immutabilityCheckMetaReducer(reducer, checks) {
|
992 | return function (state, action) {
|
993 | const act = checks.action(action) ? freeze(action) : action;
|
994 | const nextState = reducer(state, act);
|
995 | return checks.state() ? freeze(nextState) : nextState;
|
996 | };
|
997 | }
|
998 | function freeze(target) {
|
999 | Object.freeze(target);
|
1000 | const targetIsFunction = isFunction(target);
|
1001 | Object.getOwnPropertyNames(target).forEach((prop) => {
|
1002 |
|
1003 | if (prop.startsWith('ɵ')) {
|
1004 | return;
|
1005 | }
|
1006 | if (hasOwnProperty(target, prop) &&
|
1007 | (targetIsFunction
|
1008 | ? prop !== 'caller' && prop !== 'callee' && prop !== 'arguments'
|
1009 | : true)) {
|
1010 | const propValue = target[prop];
|
1011 | if ((isObjectLike(propValue) || isFunction(propValue)) &&
|
1012 | !Object.isFrozen(propValue)) {
|
1013 | freeze(propValue);
|
1014 | }
|
1015 | }
|
1016 | });
|
1017 | return target;
|
1018 | }
|
1019 |
|
1020 | function serializationCheckMetaReducer(reducer, checks) {
|
1021 | return function (state, action) {
|
1022 | if (checks.action(action)) {
|
1023 | const unserializableAction = getUnserializable(action);
|
1024 | throwIfUnserializable(unserializableAction, 'action');
|
1025 | }
|
1026 | const nextState = reducer(state, action);
|
1027 | if (checks.state()) {
|
1028 | const unserializableState = getUnserializable(nextState);
|
1029 | throwIfUnserializable(unserializableState, 'state');
|
1030 | }
|
1031 | return nextState;
|
1032 | };
|
1033 | }
|
1034 | function getUnserializable(target, path = []) {
|
1035 |
|
1036 | if ((isUndefined(target) || isNull(target)) && path.length === 0) {
|
1037 | return {
|
1038 | path: ['root'],
|
1039 | value: target,
|
1040 | };
|
1041 | }
|
1042 | const keys = Object.keys(target);
|
1043 | return keys.reduce((result, key) => {
|
1044 | if (result) {
|
1045 | return result;
|
1046 | }
|
1047 | const value = target[key];
|
1048 |
|
1049 | if (isComponent(value)) {
|
1050 | return result;
|
1051 | }
|
1052 | if (isUndefined(value) ||
|
1053 | isNull(value) ||
|
1054 | isNumber(value) ||
|
1055 | isBoolean(value) ||
|
1056 | isString(value) ||
|
1057 | isArray(value)) {
|
1058 | return false;
|
1059 | }
|
1060 | if (isPlainObject(value)) {
|
1061 | return getUnserializable(value, [...path, key]);
|
1062 | }
|
1063 | return {
|
1064 | path: [...path, key],
|
1065 | value,
|
1066 | };
|
1067 | }, false);
|
1068 | }
|
1069 | function throwIfUnserializable(unserializable, context) {
|
1070 | if (unserializable === false) {
|
1071 | return;
|
1072 | }
|
1073 | const unserializablePath = unserializable.path.join('.');
|
1074 | const error = new Error(`Detected unserializable ${context} at "${unserializablePath}". ${RUNTIME_CHECK_URL}#strict${context}serializability`);
|
1075 | error.value = unserializable.value;
|
1076 | error.unserializablePath = unserializablePath;
|
1077 | throw error;
|
1078 | }
|
1079 |
|
1080 | function inNgZoneAssertMetaReducer(reducer, checks) {
|
1081 | return function (state, action) {
|
1082 | if (checks.action(action) && !i0.NgZone.isInAngularZone()) {
|
1083 | throw new Error(`Action '${action.type}' running outside NgZone. ${RUNTIME_CHECK_URL}#strictactionwithinngzone`);
|
1084 | }
|
1085 | return reducer(state, action);
|
1086 | };
|
1087 | }
|
1088 |
|
1089 | function createActiveRuntimeChecks(runtimeChecks) {
|
1090 | if (isDevMode()) {
|
1091 | return {
|
1092 | strictStateSerializability: false,
|
1093 | strictActionSerializability: false,
|
1094 | strictStateImmutability: true,
|
1095 | strictActionImmutability: true,
|
1096 | strictActionWithinNgZone: false,
|
1097 | strictActionTypeUniqueness: false,
|
1098 | ...runtimeChecks,
|
1099 | };
|
1100 | }
|
1101 | return {
|
1102 | strictStateSerializability: false,
|
1103 | strictActionSerializability: false,
|
1104 | strictStateImmutability: false,
|
1105 | strictActionImmutability: false,
|
1106 | strictActionWithinNgZone: false,
|
1107 | strictActionTypeUniqueness: false,
|
1108 | };
|
1109 | }
|
1110 | function createSerializationCheckMetaReducer({ strictActionSerializability, strictStateSerializability, }) {
|
1111 | return (reducer) => strictActionSerializability || strictStateSerializability
|
1112 | ? serializationCheckMetaReducer(reducer, {
|
1113 | action: (action) => strictActionSerializability && !ignoreNgrxAction(action),
|
1114 | state: () => strictStateSerializability,
|
1115 | })
|
1116 | : reducer;
|
1117 | }
|
1118 | function createImmutabilityCheckMetaReducer({ strictActionImmutability, strictStateImmutability, }) {
|
1119 | return (reducer) => strictActionImmutability || strictStateImmutability
|
1120 | ? immutabilityCheckMetaReducer(reducer, {
|
1121 | action: (action) => strictActionImmutability && !ignoreNgrxAction(action),
|
1122 | state: () => strictStateImmutability,
|
1123 | })
|
1124 | : reducer;
|
1125 | }
|
1126 | function ignoreNgrxAction(action) {
|
1127 | return action.type.startsWith('@ngrx');
|
1128 | }
|
1129 | function createInNgZoneCheckMetaReducer({ strictActionWithinNgZone, }) {
|
1130 | return (reducer) => strictActionWithinNgZone
|
1131 | ? inNgZoneAssertMetaReducer(reducer, {
|
1132 | action: (action) => strictActionWithinNgZone && !ignoreNgrxAction(action),
|
1133 | })
|
1134 | : reducer;
|
1135 | }
|
1136 | function provideRuntimeChecks(runtimeChecks) {
|
1137 | return [
|
1138 | {
|
1139 | provide: _USER_RUNTIME_CHECKS,
|
1140 | useValue: runtimeChecks,
|
1141 | },
|
1142 | {
|
1143 | provide: USER_RUNTIME_CHECKS,
|
1144 | useFactory: _runtimeChecksFactory,
|
1145 | deps: [_USER_RUNTIME_CHECKS],
|
1146 | },
|
1147 | {
|
1148 | provide: ACTIVE_RUNTIME_CHECKS,
|
1149 | deps: [USER_RUNTIME_CHECKS],
|
1150 | useFactory: createActiveRuntimeChecks,
|
1151 | },
|
1152 | {
|
1153 | provide: META_REDUCERS,
|
1154 | multi: true,
|
1155 | deps: [ACTIVE_RUNTIME_CHECKS],
|
1156 | useFactory: createImmutabilityCheckMetaReducer,
|
1157 | },
|
1158 | {
|
1159 | provide: META_REDUCERS,
|
1160 | multi: true,
|
1161 | deps: [ACTIVE_RUNTIME_CHECKS],
|
1162 | useFactory: createSerializationCheckMetaReducer,
|
1163 | },
|
1164 | {
|
1165 | provide: META_REDUCERS,
|
1166 | multi: true,
|
1167 | deps: [ACTIVE_RUNTIME_CHECKS],
|
1168 | useFactory: createInNgZoneCheckMetaReducer,
|
1169 | },
|
1170 | ];
|
1171 | }
|
1172 | function checkForActionTypeUniqueness() {
|
1173 | return [
|
1174 | {
|
1175 | provide: _ACTION_TYPE_UNIQUENESS_CHECK,
|
1176 | multi: true,
|
1177 | deps: [ACTIVE_RUNTIME_CHECKS],
|
1178 | useFactory: _actionTypeUniquenessCheck,
|
1179 | },
|
1180 | ];
|
1181 | }
|
1182 | function _runtimeChecksFactory(runtimeChecks) {
|
1183 | return runtimeChecks;
|
1184 | }
|
1185 | function _actionTypeUniquenessCheck(config) {
|
1186 | if (!config.strictActionTypeUniqueness) {
|
1187 | return;
|
1188 | }
|
1189 | const duplicates = Object.entries(REGISTERED_ACTION_TYPES)
|
1190 | .filter(([, registrations]) => registrations > 1)
|
1191 | .map(([type]) => type);
|
1192 | if (duplicates.length) {
|
1193 | throw new Error(`Action types are registered more than once, ${duplicates
|
1194 | .map((type) => `"${type}"`)
|
1195 | .join(', ')}. ${RUNTIME_CHECK_URL}#strictactiontypeuniqueness`);
|
1196 | }
|
1197 | }
|
1198 |
|
1199 |
|
1200 |
|
1201 |
|
1202 |
|
1203 |
|
1204 |
|
1205 |
|
1206 |
|
1207 |
|
1208 |
|
1209 |
|
1210 |
|
1211 |
|
1212 |
|
1213 |
|
1214 |
|
1215 |
|
1216 |
|
1217 |
|
1218 |
|
1219 |
|
1220 | function provideState(featureNameOrSlice, reducers, config = {}) {
|
1221 | return makeEnvironmentProviders([
|
1222 | ..._provideState(featureNameOrSlice, reducers, config),
|
1223 | ENVIRONMENT_STATE_PROVIDER,
|
1224 | ]);
|
1225 | }
|
1226 | function _provideStore(reducers = {}, config = {}) {
|
1227 | return [
|
1228 | {
|
1229 | provide: _ROOT_STORE_GUARD,
|
1230 | useFactory: _provideForRootGuard,
|
1231 | },
|
1232 | { provide: _INITIAL_STATE, useValue: config.initialState },
|
1233 | {
|
1234 | provide: INITIAL_STATE,
|
1235 | useFactory: _initialStateFactory,
|
1236 | deps: [_INITIAL_STATE],
|
1237 | },
|
1238 | { provide: _INITIAL_REDUCERS, useValue: reducers },
|
1239 | {
|
1240 | provide: _STORE_REDUCERS,
|
1241 | useExisting: reducers instanceof InjectionToken ? reducers : _INITIAL_REDUCERS,
|
1242 | },
|
1243 | {
|
1244 | provide: INITIAL_REDUCERS,
|
1245 | deps: [_INITIAL_REDUCERS, [new Inject(_STORE_REDUCERS)]],
|
1246 | useFactory: _createStoreReducers,
|
1247 | },
|
1248 | {
|
1249 | provide: USER_PROVIDED_META_REDUCERS,
|
1250 | useValue: config.metaReducers ? config.metaReducers : [],
|
1251 | },
|
1252 | {
|
1253 | provide: _RESOLVED_META_REDUCERS,
|
1254 | deps: [META_REDUCERS, USER_PROVIDED_META_REDUCERS],
|
1255 | useFactory: _concatMetaReducers,
|
1256 | },
|
1257 | {
|
1258 | provide: _REDUCER_FACTORY,
|
1259 | useValue: config.reducerFactory ? config.reducerFactory : combineReducers,
|
1260 | },
|
1261 | {
|
1262 | provide: REDUCER_FACTORY,
|
1263 | deps: [_REDUCER_FACTORY, _RESOLVED_META_REDUCERS],
|
1264 | useFactory: createReducerFactory,
|
1265 | },
|
1266 | ACTIONS_SUBJECT_PROVIDERS,
|
1267 | REDUCER_MANAGER_PROVIDERS,
|
1268 | SCANNED_ACTIONS_SUBJECT_PROVIDERS,
|
1269 | STATE_PROVIDERS,
|
1270 | STORE_PROVIDERS,
|
1271 | provideRuntimeChecks(config.runtimeChecks),
|
1272 | checkForActionTypeUniqueness(),
|
1273 | ];
|
1274 | }
|
1275 | function rootStoreProviderFactory() {
|
1276 | inject(ActionsSubject);
|
1277 | inject(ReducerObservable);
|
1278 | inject(ScannedActionsSubject);
|
1279 | inject(Store);
|
1280 | inject(_ROOT_STORE_GUARD, { optional: true });
|
1281 | inject(_ACTION_TYPE_UNIQUENESS_CHECK, { optional: true });
|
1282 | }
|
1283 |
|
1284 |
|
1285 |
|
1286 |
|
1287 | const ENVIRONMENT_STORE_PROVIDER = [
|
1288 | { provide: ROOT_STORE_PROVIDER, useFactory: rootStoreProviderFactory },
|
1289 | {
|
1290 | provide: ENVIRONMENT_INITIALIZER,
|
1291 | multi: true,
|
1292 | useFactory() {
|
1293 | return () => inject(ROOT_STORE_PROVIDER);
|
1294 | },
|
1295 | },
|
1296 | ];
|
1297 |
|
1298 |
|
1299 |
|
1300 |
|
1301 |
|
1302 |
|
1303 |
|
1304 |
|
1305 |
|
1306 |
|
1307 |
|
1308 |
|
1309 |
|
1310 |
|
1311 |
|
1312 | function provideStore(reducers, config) {
|
1313 | return makeEnvironmentProviders([
|
1314 | ..._provideStore(reducers, config),
|
1315 | ENVIRONMENT_STORE_PROVIDER,
|
1316 | ]);
|
1317 | }
|
1318 | function featureStateProviderFactory() {
|
1319 | inject(ROOT_STORE_PROVIDER);
|
1320 | const features = inject(_STORE_FEATURES);
|
1321 | const featureReducers = inject(FEATURE_REDUCERS);
|
1322 | const reducerManager = inject(ReducerManager);
|
1323 | inject(_ACTION_TYPE_UNIQUENESS_CHECK, { optional: true });
|
1324 | const feats = features.map((feature, index) => {
|
1325 | const featureReducerCollection = featureReducers.shift();
|
1326 |
|
1327 | const reducers = featureReducerCollection [index];
|
1328 | return {
|
1329 | ...feature,
|
1330 | reducers,
|
1331 | initialState: _initialStateFactory(feature.initialState),
|
1332 | };
|
1333 | });
|
1334 | reducerManager.addFeatures(feats);
|
1335 | }
|
1336 |
|
1337 |
|
1338 |
|
1339 |
|
1340 | const ENVIRONMENT_STATE_PROVIDER = [
|
1341 | {
|
1342 | provide: FEATURE_STATE_PROVIDER,
|
1343 | useFactory: featureStateProviderFactory,
|
1344 | },
|
1345 | {
|
1346 | provide: ENVIRONMENT_INITIALIZER,
|
1347 | multi: true,
|
1348 | useFactory() {
|
1349 | return () => inject(FEATURE_STATE_PROVIDER);
|
1350 | },
|
1351 | },
|
1352 | ];
|
1353 | function _provideState(featureNameOrSlice, reducers, config = {}) {
|
1354 | return [
|
1355 | {
|
1356 | provide: _FEATURE_CONFIGS,
|
1357 | multi: true,
|
1358 | useValue: featureNameOrSlice instanceof Object ? {} : config,
|
1359 | },
|
1360 | {
|
1361 | provide: STORE_FEATURES,
|
1362 | multi: true,
|
1363 | useValue: {
|
1364 | key: featureNameOrSlice instanceof Object
|
1365 | ? featureNameOrSlice.name
|
1366 | : featureNameOrSlice,
|
1367 | reducerFactory: !(config instanceof InjectionToken) && config.reducerFactory
|
1368 | ? config.reducerFactory
|
1369 | : combineReducers,
|
1370 | metaReducers: !(config instanceof InjectionToken) && config.metaReducers
|
1371 | ? config.metaReducers
|
1372 | : [],
|
1373 | initialState: !(config instanceof InjectionToken) && config.initialState
|
1374 | ? config.initialState
|
1375 | : undefined,
|
1376 | },
|
1377 | },
|
1378 | {
|
1379 | provide: _STORE_FEATURES,
|
1380 | deps: [_FEATURE_CONFIGS, STORE_FEATURES],
|
1381 | useFactory: _createFeatureStore,
|
1382 | },
|
1383 | {
|
1384 | provide: _FEATURE_REDUCERS,
|
1385 | multi: true,
|
1386 | useValue: featureNameOrSlice instanceof Object
|
1387 | ? featureNameOrSlice.reducer
|
1388 | : reducers,
|
1389 | },
|
1390 | {
|
1391 | provide: _FEATURE_REDUCERS_TOKEN,
|
1392 | multi: true,
|
1393 | useExisting: reducers instanceof InjectionToken ? reducers : _FEATURE_REDUCERS,
|
1394 | },
|
1395 | {
|
1396 | provide: FEATURE_REDUCERS,
|
1397 | multi: true,
|
1398 | deps: [_FEATURE_REDUCERS, [new Inject(_FEATURE_REDUCERS_TOKEN)]],
|
1399 | useFactory: _createFeatureReducers,
|
1400 | },
|
1401 | checkForActionTypeUniqueness(),
|
1402 | ];
|
1403 | }
|
1404 |
|
1405 | class StoreRootModule {
|
1406 | constructor(actions$, reducer$, scannedActions$, store, guard, actionCheck) { }
|
1407 | }
|
1408 | StoreRootModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: StoreRootModule, deps: [{ token: ActionsSubject }, { token: ReducerObservable }, { token: ScannedActionsSubject }, { token: Store }, { token: _ROOT_STORE_GUARD, optional: true }, { token: _ACTION_TYPE_UNIQUENESS_CHECK, optional: true }], target: i0.ɵɵFactoryTarget.NgModule });
|
1409 | StoreRootModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.0.0", ngImport: i0, type: StoreRootModule });
|
1410 | StoreRootModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: StoreRootModule });
|
1411 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: StoreRootModule, decorators: [{
|
1412 | type: NgModule,
|
1413 | args: [{}]
|
1414 | }], ctorParameters: function () { return [{ type: ActionsSubject }, { type: ReducerObservable }, { type: ScannedActionsSubject }, { type: Store }, { type: undefined, decorators: [{
|
1415 | type: Optional
|
1416 | }, {
|
1417 | type: Inject,
|
1418 | args: [_ROOT_STORE_GUARD]
|
1419 | }] }, { type: undefined, decorators: [{
|
1420 | type: Optional
|
1421 | }, {
|
1422 | type: Inject,
|
1423 | args: [_ACTION_TYPE_UNIQUENESS_CHECK]
|
1424 | }] }]; } });
|
1425 | class StoreFeatureModule {
|
1426 | constructor(features, featureReducers, reducerManager, root, actionCheck) {
|
1427 | this.features = features;
|
1428 | this.featureReducers = featureReducers;
|
1429 | this.reducerManager = reducerManager;
|
1430 | const feats = features.map((feature, index) => {
|
1431 | const featureReducerCollection = featureReducers.shift();
|
1432 |
|
1433 | const reducers = featureReducerCollection [index];
|
1434 | return {
|
1435 | ...feature,
|
1436 | reducers,
|
1437 | initialState: _initialStateFactory(feature.initialState),
|
1438 | };
|
1439 | });
|
1440 | reducerManager.addFeatures(feats);
|
1441 | }
|
1442 |
|
1443 | ngOnDestroy() {
|
1444 | this.reducerManager.removeFeatures(this.features);
|
1445 | }
|
1446 | }
|
1447 | StoreFeatureModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: StoreFeatureModule, deps: [{ token: _STORE_FEATURES }, { token: FEATURE_REDUCERS }, { token: ReducerManager }, { token: StoreRootModule }, { token: _ACTION_TYPE_UNIQUENESS_CHECK, optional: true }], target: i0.ɵɵFactoryTarget.NgModule });
|
1448 | StoreFeatureModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.0.0", ngImport: i0, type: StoreFeatureModule });
|
1449 | StoreFeatureModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: StoreFeatureModule });
|
1450 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: StoreFeatureModule, decorators: [{
|
1451 | type: NgModule,
|
1452 | args: [{}]
|
1453 | }], ctorParameters: function () { return [{ type: undefined, decorators: [{
|
1454 | type: Inject,
|
1455 | args: [_STORE_FEATURES]
|
1456 | }] }, { type: undefined, decorators: [{
|
1457 | type: Inject,
|
1458 | args: [FEATURE_REDUCERS]
|
1459 | }] }, { type: ReducerManager }, { type: StoreRootModule }, { type: undefined, decorators: [{
|
1460 | type: Optional
|
1461 | }, {
|
1462 | type: Inject,
|
1463 | args: [_ACTION_TYPE_UNIQUENESS_CHECK]
|
1464 | }] }]; } });
|
1465 | class StoreModule {
|
1466 | static forRoot(reducers, config) {
|
1467 | return {
|
1468 | ngModule: StoreRootModule,
|
1469 | providers: [..._provideStore(reducers, config)],
|
1470 | };
|
1471 | }
|
1472 | static forFeature(featureNameOrSlice, reducers, config = {}) {
|
1473 | return {
|
1474 | ngModule: StoreFeatureModule,
|
1475 | providers: [..._provideState(featureNameOrSlice, reducers, config)],
|
1476 | };
|
1477 | }
|
1478 | }
|
1479 | StoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: StoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
1480 | StoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "15.0.0", ngImport: i0, type: StoreModule });
|
1481 | StoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: StoreModule });
|
1482 | i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "15.0.0", ngImport: i0, type: StoreModule, decorators: [{
|
1483 | type: NgModule,
|
1484 | args: [{}]
|
1485 | }] });
|
1486 |
|
1487 |
|
1488 |
|
1489 |
|
1490 |
|
1491 |
|
1492 |
|
1493 |
|
1494 |
|
1495 |
|
1496 |
|
1497 |
|
1498 |
|
1499 |
|
1500 |
|
1501 | function on(...args) {
|
1502 | const reducer = args.pop();
|
1503 | const types = args.map((creator) => creator.type);
|
1504 | return { reducer, types };
|
1505 | }
|
1506 |
|
1507 |
|
1508 |
|
1509 |
|
1510 |
|
1511 |
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 |
|
1519 |
|
1520 |
|
1521 |
|
1522 |
|
1523 |
|
1524 |
|
1525 |
|
1526 |
|
1527 |
|
1528 |
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 |
|
1535 | function createReducer(initialState, ...ons) {
|
1536 | const map = new Map();
|
1537 | for (const on of ons) {
|
1538 | for (const type of on.types) {
|
1539 | const existingReducer = map.get(type);
|
1540 | if (existingReducer) {
|
1541 | const newReducer = (state, action) => on.reducer(existingReducer(state, action), action);
|
1542 | map.set(type, newReducer);
|
1543 | }
|
1544 | else {
|
1545 | map.set(type, on.reducer);
|
1546 | }
|
1547 | }
|
1548 | }
|
1549 | return function (state = initialState, action) {
|
1550 | const reducer = map.get(action.type);
|
1551 | return reducer ? reducer(state, action) : state;
|
1552 | };
|
1553 | }
|
1554 |
|
1555 |
|
1556 |
|
1557 |
|
1558 |
|
1559 |
|
1560 |
|
1561 |
|
1562 |
|
1563 |
|
1564 |
|
1565 | export { ACTIVE_RUNTIME_CHECKS, ActionsSubject, FEATURE_REDUCERS, FEATURE_STATE_PROVIDER, INIT, INITIAL_REDUCERS, INITIAL_STATE, META_REDUCERS, REDUCER_FACTORY, ROOT_STORE_PROVIDER, ReducerManager, ReducerManagerDispatcher, ReducerObservable, STORE_FEATURES, ScannedActionsSubject, State, StateObservable, Store, StoreFeatureModule, StoreModule, StoreRootModule, UPDATE, USER_PROVIDED_META_REDUCERS, USER_RUNTIME_CHECKS, combineReducers, compose, createAction, createActionGroup, createFeature, createFeatureSelector, createReducer, createReducerFactory, createSelector, createSelectorFactory, defaultMemoize, defaultStateFn, emptyProps, isNgrxMockEnvironment, on, props, provideState, provideStore, reduceState, resultMemoize, select, setNgrxMockEnvironment, union };
|
1566 |
|
1567 |
|