ngssm-store 14.1.0 → 14.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/esm2020/lib/store-mock.mjs +10 -0
- package/esm2020/public-api.mjs +2 -1
- package/fesm2015/ngssm-store.mjs +10 -1
- package/fesm2015/ngssm-store.mjs.map +1 -1
- package/fesm2020/ngssm-store.mjs +10 -1
- package/fesm2020/ngssm-store.mjs.map +1 -1
- package/lib/store-mock.d.ts +12 -0
- package/package.json +2 -2
- package/public-api.d.ts +1 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BehaviorSubject } from 'rxjs';
|
|
2
|
+
export class StoreMock {
|
|
3
|
+
constructor(initialState) {
|
|
4
|
+
this.state$ = new BehaviorSubject({});
|
|
5
|
+
this.state$.next(initialState);
|
|
6
|
+
}
|
|
7
|
+
dispatchAction(action) { }
|
|
8
|
+
dispatchActionType(type) { }
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmUtbW9jay5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3Byb2plY3RzL25nc3NtLXN0b3JlL3NyYy9saWIvc3RvcmUtbW9jay50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsZUFBZSxFQUFFLE1BQU0sTUFBTSxDQUFDO0FBR3ZDLE1BQU0sT0FBTyxTQUFTO0lBR3BCLFlBQVksWUFBb0M7UUFGekMsV0FBTSxHQUFHLElBQUksZUFBZSxDQUF5QixFQUFFLENBQUMsQ0FBQztRQUc5RCxJQUFJLENBQUMsTUFBTSxDQUFDLElBQUksQ0FBQyxZQUFZLENBQUMsQ0FBQztJQUNqQyxDQUFDO0lBRU0sY0FBYyxDQUFDLE1BQWMsSUFBUyxDQUFDO0lBRXZDLGtCQUFrQixDQUFDLElBQVksSUFBUyxDQUFDO0NBQ2pEIiwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0IHsgQmVoYXZpb3JTdWJqZWN0IH0gZnJvbSAncnhqcyc7XG5pbXBvcnQgeyBBY3Rpb24gfSBmcm9tICcuL2FjdGlvbic7XG5cbmV4cG9ydCBjbGFzcyBTdG9yZU1vY2sge1xuICBwdWJsaWMgc3RhdGUkID0gbmV3IEJlaGF2aW9yU3ViamVjdDx7IFtrZXk6IHN0cmluZ106IGFueSB9Pih7fSk7XG5cbiAgY29uc3RydWN0b3IoaW5pdGlhbFN0YXRlOiB7IFtrZXk6IHN0cmluZ106IGFueSB9KSB7XG4gICAgdGhpcy5zdGF0ZSQubmV4dChpbml0aWFsU3RhdGUpO1xuICB9XG5cbiAgcHVibGljIGRpc3BhdGNoQWN0aW9uKGFjdGlvbjogQWN0aW9uKTogdm9pZCB7fVxuXG4gIHB1YmxpYyBkaXNwYXRjaEFjdGlvblR5cGUodHlwZTogc3RyaW5nKTogdm9pZCB7fVxufVxuIl19
|
package/esm2020/public-api.mjs
CHANGED
|
@@ -10,4 +10,5 @@ export * from './lib/effect';
|
|
|
10
10
|
export * from './lib/feature-state-specification';
|
|
11
11
|
export * from './lib/ngssm-component';
|
|
12
12
|
export * from './lib/state-initializer';
|
|
13
|
-
|
|
13
|
+
export * from './lib/store-mock';
|
|
14
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3Byb2plY3RzL25nc3NtLXN0b3JlL3NyYy9wdWJsaWMtYXBpLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBRUgsY0FBYywwQkFBMEIsQ0FBQztBQUV6QyxjQUFjLGFBQWEsQ0FBQztBQUM1QixjQUFjLGFBQWEsQ0FBQztBQUM1QixjQUFjLGNBQWMsQ0FBQztBQUM3QixjQUFjLGVBQWUsQ0FBQztBQUM5QixjQUFjLGNBQWMsQ0FBQztBQUM3QixjQUFjLG1DQUFtQyxDQUFDO0FBQ2xELGNBQWMsdUJBQXVCLENBQUM7QUFDdEMsY0FBYyx5QkFBeUIsQ0FBQztBQUV4QyxjQUFjLGtCQUFrQixDQUFDIiwic291cmNlc0NvbnRlbnQiOlsiLypcbiAqIFB1YmxpYyBBUEkgU3VyZmFjZSBvZiBuZ3NzbS1zdG9yZVxuICovXG5cbmV4cG9ydCAqIGZyb20gJy4vbGliL25nc3NtLXN0b3JlLm1vZHVsZSc7XG5cbmV4cG9ydCAqIGZyb20gJy4vbGliL3N0b3JlJztcbmV4cG9ydCAqIGZyb20gJy4vbGliL3N0YXRlJztcbmV4cG9ydCAqIGZyb20gJy4vbGliL2FjdGlvbic7XG5leHBvcnQgKiBmcm9tICcuL2xpYi9yZWR1Y2VyJztcbmV4cG9ydCAqIGZyb20gJy4vbGliL2VmZmVjdCc7XG5leHBvcnQgKiBmcm9tICcuL2xpYi9mZWF0dXJlLXN0YXRlLXNwZWNpZmljYXRpb24nO1xuZXhwb3J0ICogZnJvbSAnLi9saWIvbmdzc20tY29tcG9uZW50JztcbmV4cG9ydCAqIGZyb20gJy4vbGliL3N0YXRlLWluaXRpYWxpemVyJztcblxuZXhwb3J0ICogZnJvbSAnLi9saWIvc3RvcmUtbW9jayc7XG4iXX0=
|
package/fesm2015/ngssm-store.mjs
CHANGED
|
@@ -182,6 +182,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
|
|
|
182
182
|
}]
|
|
183
183
|
}], ctorParameters: function () { return [{ type: Store }]; } });
|
|
184
184
|
|
|
185
|
+
class StoreMock {
|
|
186
|
+
constructor(initialState) {
|
|
187
|
+
this.state$ = new BehaviorSubject({});
|
|
188
|
+
this.state$.next(initialState);
|
|
189
|
+
}
|
|
190
|
+
dispatchAction(action) { }
|
|
191
|
+
dispatchActionType(type) { }
|
|
192
|
+
}
|
|
193
|
+
|
|
185
194
|
/*
|
|
186
195
|
* Public API Surface of ngssm-store
|
|
187
196
|
*/
|
|
@@ -190,5 +199,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
|
|
|
190
199
|
* Generated bundle index. Do not edit.
|
|
191
200
|
*/
|
|
192
201
|
|
|
193
|
-
export { NGSSM_EFFECT, NGSSM_REDUCER, NGSSM_STATE_INITIALIZER, NgSsmComponent, NgSsmFeatureState, NgssmStoreModule, Store };
|
|
202
|
+
export { NGSSM_EFFECT, NGSSM_REDUCER, NGSSM_STATE_INITIALIZER, NgSsmComponent, NgSsmFeatureState, NgssmStoreModule, Store, StoreMock };
|
|
194
203
|
//# sourceMappingURL=ngssm-store.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngssm-store.mjs","sources":["../../../projects/ngssm-store/src/lib/ngssm-store.module.ts","../../../projects/ngssm-store/src/lib/reducer.ts","../../../projects/ngssm-store/src/lib/effect.ts","../../../projects/ngssm-store/src/lib/state-initializer.ts","../../../projects/ngssm-store/src/lib/store.ts","../../../projects/ngssm-store/src/lib/ngssm-component.ts","../../../projects/ngssm-store/src/public-api.ts","../../../projects/ngssm-store/src/ngssm-store.ts"],"sourcesContent":["import { NgModule } from '@angular/core';\n\n@NgModule({\n declarations: [],\n imports: [],\n exports: []\n})\nexport class NgssmStoreModule {}\n","import { InjectionToken } from '@angular/core';\n\nimport { Action } from './action';\nimport { State } from './state';\n\nexport interface Reducer {\n processedActions: string[];\n updateState(state: State, action: Action): State;\n}\n\nexport const NGSSM_REDUCER = new InjectionToken<Reducer>('NGSSM_REDUCER');\n","import { InjectionToken } from '@angular/core';\n\nimport { Action } from './action';\nimport { State } from './state';\nimport { Store } from './store';\n\nexport interface Effect {\n processedActions: string[];\n processAction(store: Store, state: State, action: Action): void;\n}\n\nexport const NGSSM_EFFECT = new InjectionToken<Effect>('NGSSM_EFFECT');\n","import { InjectionToken } from '@angular/core';\nimport { State } from './state';\n\nexport interface StateInitializer {\n initializeState(state: State): State;\n}\n\nexport const NGSSM_STATE_INITIALIZER = new InjectionToken<StateInitializer>('NGSSM_STATE_INITIALIZER');\n","import { Inject, Injectable, Optional } from '@angular/core';\nimport { BehaviorSubject, Observable } from 'rxjs';\n\nimport update from 'immutability-helper';\n\nimport { Logger } from 'ngssm-toolkit';\n\nimport { FeatureStateSpecification } from './feature-state-specification';\nimport { State } from './state';\nimport { Action } from './action';\nimport { NGSSM_REDUCER, Reducer } from './reducer';\nimport { Effect, NGSSM_EFFECT } from './effect';\nimport { NGSSM_STATE_INITIALIZER, StateInitializer } from './state-initializer';\n\nconst featureStateSpecifications: FeatureStateSpecification[] = [];\nexport const NgSsmFeatureState = (specification: FeatureStateSpecification) => {\n return (target: object) => {\n featureStateSpecifications.push(specification);\n };\n};\n\n@Injectable({\n providedIn: 'root'\n})\nexport class Store {\n private readonly _state$ = new BehaviorSubject<State>({});\n private readonly actionQueue: Action[] = [];\n private readonly reducersPerActionType = new Map<string, Reducer[]>();\n private readonly effectsPerActionType = new Map<string, Effect[]>();\n\n constructor(\n private logger: Logger,\n @Inject(NGSSM_REDUCER) @Optional() reducers: Reducer[],\n @Inject(NGSSM_EFFECT) @Optional() effects: Effect[],\n @Inject(NGSSM_STATE_INITIALIZER) @Optional() initializers: StateInitializer[]\n ) {\n this.logger.information('[Store] ---> state initialization...');\n let state = this._state$.getValue();\n state = featureStateSpecifications.reduce((p, c) => update(p, { [c.featureStateKey]: { $set: c.initialState } }), state);\n\n (initializers ?? []).forEach((initializer) => {\n this.logger.information('[Store] ------> calling initializer', initializer);\n state = initializer.initializeState(state);\n });\n\n this._state$.next(state);\n\n this.logger.information(`[Store] ---> initialization of ${(reducers ?? []).length} reducers...`);\n (reducers ?? []).forEach((reducer) => {\n this.logger.information('[Store] ------> initialization of ', reducer);\n reducer.processedActions.forEach((processedAction) => {\n const storeReducers: Reducer[] = this.reducersPerActionType.get(processedAction) ?? [];\n if (storeReducers.length === 0) {\n this.reducersPerActionType.set(processedAction, storeReducers);\n }\n\n storeReducers.push(reducer);\n });\n });\n\n this.logger.information(`[Store] ---> initialization of ${(effects ?? []).length} effects...`);\n (effects ?? []).forEach((effect) => {\n this.logger.information('[Store] ------> initialization of ', effect);\n effect.processedActions.forEach((processedAction) => {\n const storedEffects: Effect[] = this.effectsPerActionType.get(processedAction) ?? [];\n if (storedEffects.length === 0) {\n this.effectsPerActionType.set(processedAction, storedEffects);\n }\n\n storedEffects.push(effect);\n });\n });\n }\n\n public get state$(): Observable<State> {\n return this._state$.asObservable();\n }\n\n public dispatchAction(action: Action): void {\n this.actionQueue.push(action);\n this.logger.debug(`Action of type '${action.type}' added to the queue => ${this.actionQueue.length} pending actions`, action);\n setTimeout(() => this.processNextAction());\n }\n\n public dispatchActionType(type: string): void {\n this.dispatchAction({ type });\n }\n\n private processNextAction(): void {\n const nextAction = this.actionQueue.shift();\n if (!nextAction) {\n this.logger.debug('[processNextAction] No action to process');\n return;\n }\n\n this.logger.information(`[processNextAction] Start processing action '${nextAction.type}...`, nextAction);\n\n try {\n const reducers = this.reducersPerActionType.get(nextAction.type) ?? [];\n this.logger.debug(`[Store] ${reducers.length} reducers found to process the action ${nextAction.type}`, reducers);\n const currentState = this._state$.getValue();\n const updatedState = reducers.reduce((p, c) => c.updateState(p, nextAction), currentState);\n\n if (updatedState !== currentState) {\n this._state$.next(updatedState);\n }\n\n const effects = this.effectsPerActionType.get(nextAction.type) ?? [];\n this.logger.debug(`[Store] ${effects.length} effects found to process the action ${nextAction.type}`, effects);\n effects.forEach((effect) => {\n try {\n effect.processAction(this, updatedState, nextAction);\n } catch (error) {\n this.logger.error(`Unable to process action ${nextAction.type} by effect ${effect}`, {\n error,\n action: nextAction,\n processor: effect\n });\n }\n });\n } catch (error) {\n this.logger.error(`Error when processing action ${nextAction.type}`, {\n error,\n action: nextAction\n });\n } finally {\n this.logger.information(`[processNextAction] action '${nextAction.type} processed.`, nextAction);\n\n // Should not be useful.But, just in case.\n setTimeout(() => this.processNextAction());\n }\n }\n}\n","import { Component, OnDestroy } from '@angular/core';\nimport { map, Observable, Subject, distinctUntilChanged, takeUntil } from 'rxjs';\n\nimport { Action } from './action';\nimport { State } from './state';\nimport { Store } from './store';\n\n@Component({\n template: ''\n})\nexport class NgSsmComponent implements OnDestroy {\n private readonly _unsubscribeAll$ = new Subject<void>();\n\n constructor(protected store: Store) {}\n\n protected get unsubscribeAll$(): Observable<void> {\n return this._unsubscribeAll$.asObservable();\n }\n\n public ngOnDestroy(): void {\n this._unsubscribeAll$.next();\n this._unsubscribeAll$.complete();\n }\n\n public watch<T>(selector: (state: State) => T): Observable<T> {\n return this.store.state$.pipe(\n map((state) => selector(state)),\n distinctUntilChanged(),\n takeUntil(this.unsubscribeAll$)\n );\n }\n\n public dispatchAction(action: Action): void {\n this.store.dispatchAction(action);\n }\n\n public dispatchActionType(actionType: string): void {\n this.store.dispatchActionType(actionType);\n }\n}\n","/*\n * Public API Surface of ngssm-store\n */\n\nexport * from './lib/ngssm-store.module';\n\nexport * from './lib/store';\nexport * from './lib/state';\nexport * from './lib/action';\nexport * from './lib/reducer';\nexport * from './lib/effect';\nexport * from './lib/feature-state-specification';\nexport * from './lib/ngssm-component';\nexport * from './lib/state-initializer';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.Store"],"mappings":";;;;;;MAOa,gBAAgB,CAAA;;6GAAhB,gBAAgB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;8GAAhB,gBAAgB,EAAA,CAAA,CAAA;8GAAhB,gBAAgB,EAAA,CAAA,CAAA;2FAAhB,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAL5B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,YAAY,EAAE,EAAE;AAChB,oBAAA,OAAO,EAAE,EAAE;AACX,o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AK,CAAC,MAAM,CAAC,IAAI,CAC3B,GAAG,CAAC,CAAC,KAAK,KAAK,QAAQ,CAAC,KAAK,CAAC,CAAC,EAC/B,oBAAoB,EAAE,EACtB,SAAS,CAAC,IAAI,CAAC,eAAe,CAAC,CAChC,CAAC;KACH;AAEM,IAAA,cAAc,CAAC,MAAc,EAAA;AAClC,QAAA,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;KACnC;AAEM,IAAA,kBAAkB,CAAC,UAAkB,EAAA;AAC1C,QAAA,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;KAC3C;;2GA5BU,cAAc,EAAA,IAAA,EAAA,CAAA,EAAA,KAAA,EAAAA,KAAA,EAAA,CAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA,CAAA;AAAd,cAAA,CAAA,IAAA,GAAA,EAAA,CAAA,oBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,IAAA,EAAA,cAAc,oDAFf,EAAE,EAAA,QAAA,EAAA,IAAA,EAAA,CAAA,CAAA;2FAED,cAAc,EAAA,UAAA,EAAA,CAAA;kBAH1B,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACT,oBAAA,QAAQ,EAAE,EAAE;iBACb,CAAA;;;ACTD;;AAEG;;ACFH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"ngssm-store.mjs","sources":["../../../projects/ngssm-store/src/lib/ngssm-store.module.ts","../../../projects/ngssm-store/src/lib/reducer.ts","../../../projects/ngssm-store/src/lib/effect.ts","../../../projects/ngssm-store/src/lib/state-initializer.ts","../../../projects/ngssm-store/src/lib/store.ts","../../../projects/ngssm-store/src/lib/ngssm-component.ts","../../../projects/ngssm-store/src/lib/store-mock.ts","../../../projects/ngssm-store/src/public-api.ts","../../../projects/ngssm-store/src/ngssm-store.ts"],"sourcesContent":["import { NgModule } from '@angular/core';\n\n@NgModule({\n declarations: [],\n imports: [],\n exports: []\n})\nexport class NgssmStoreModule {}\n","import { InjectionToken } from '@angular/core';\n\nimport { Action } from './action';\nimport { State } from './state';\n\nexport interface Reducer {\n processedActions: string[];\n updateState(state: State, action: Action): State;\n}\n\nexport const NGSSM_REDUCER = new InjectionToken<Reducer>('NGSSM_REDUCER');\n","import { InjectionToken } from '@angular/core';\n\nimport { Action } from './action';\nimport { State } from './state';\nimport { Store } from './store';\n\nexport interface Effect {\n processedActions: string[];\n processAction(store: Store, state: State, action: Action): void;\n}\n\nexport const NGSSM_EFFECT = new InjectionToken<Effect>('NGSSM_EFFECT');\n","import { InjectionToken } from '@angular/core';\nimport { State } from './state';\n\nexport interface StateInitializer {\n initializeState(state: State): State;\n}\n\nexport const NGSSM_STATE_INITIALIZER = new InjectionToken<StateInitializer>('NGSSM_STATE_INITIALIZER');\n","import { Inject, Injectable, Optional } from '@angular/core';\nimport { BehaviorSubject, Observable } from 'rxjs';\n\nimport update from 'immutability-helper';\n\nimport { Logger } from 'ngssm-toolkit';\n\nimport { FeatureStateSpecification } from './feature-state-specification';\nimport { State } from './state';\nimport { Action } from './action';\nimport { NGSSM_REDUCER, Reducer } from './reducer';\nimport { Effect, NGSSM_EFFECT } from './effect';\nimport { NGSSM_STATE_INITIALIZER, StateInitializer } from './state-initializer';\n\nconst featureStateSpecifications: FeatureStateSpecification[] = [];\nexport const NgSsmFeatureState = (specification: FeatureStateSpecification) => {\n return (target: object) => {\n featureStateSpecifications.push(specification);\n };\n};\n\n@Injectable({\n providedIn: 'root'\n})\nexport class Store {\n private readonly _state$ = new BehaviorSubject<State>({});\n private readonly actionQueue: Action[] = [];\n private readonly reducersPerActionType = new Map<string, Reducer[]>();\n private readonly effectsPerActionType = new Map<string, Effect[]>();\n\n constructor(\n private logger: Logger,\n @Inject(NGSSM_REDUCER) @Optional() reducers: Reducer[],\n @Inject(NGSSM_EFFECT) @Optional() effects: Effect[],\n @Inject(NGSSM_STATE_INITIALIZER) @Optional() initializers: StateInitializer[]\n ) {\n this.logger.information('[Store] ---> state initialization...');\n let state = this._state$.getValue();\n state = featureStateSpecifications.reduce((p, c) => update(p, { [c.featureStateKey]: { $set: c.initialState } }), state);\n\n (initializers ?? []).forEach((initializer) => {\n this.logger.information('[Store] ------> calling initializer', initializer);\n state = initializer.initializeState(state);\n });\n\n this._state$.next(state);\n\n this.logger.information(`[Store] ---> initialization of ${(reducers ?? []).length} reducers...`);\n (reducers ?? []).forEach((reducer) => {\n this.logger.information('[Store] ------> initialization of ', reducer);\n reducer.processedActions.forEach((processedAction) => {\n const storeReducers: Reducer[] = this.reducersPerActionType.get(processedAction) ?? [];\n if (storeReducers.length === 0) {\n this.reducersPerActionType.set(processedAction, storeReducers);\n }\n\n storeReducers.push(reducer);\n });\n });\n\n this.logger.information(`[Store] ---> initialization of ${(effects ?? []).length} effects...`);\n (effects ?? []).forEach((effect) => {\n this.logger.information('[Store] ------> initialization of ', effect);\n effect.processedActions.forEach((processedAction) => {\n const storedEffects: Effect[] = this.effectsPerActionType.get(processedAction) ?? [];\n if (storedEffects.length === 0) {\n this.effectsPerActionType.set(processedAction, storedEffects);\n }\n\n storedEffects.push(effect);\n });\n });\n }\n\n public get state$(): Observable<State> {\n return this._state$.asObservable();\n }\n\n public dispatchAction(action: Action): void {\n this.actionQueue.push(action);\n this.logger.debug(`Action of type '${action.type}' added to the queue => ${this.actionQueue.length} pending actions`, action);\n setTimeout(() => this.processNextAction());\n }\n\n public dispatchActionType(type: string): void {\n this.dispatchAction({ type });\n }\n\n private processNextAction(): void {\n const nextAction = this.actionQueue.shift();\n if (!nextAction) {\n this.logger.debug('[processNextAction] No action to process');\n return;\n }\n\n this.logger.information(`[processNextAction] Start processing action '${nextAction.type}...`, nextAction);\n\n try {\n const reducers = this.reducersPerActionType.get(nextAction.type) ?? [];\n this.logger.debug(`[Store] ${reducers.length} reducers found to process the action ${nextAction.type}`, reducers);\n const currentState = this._state$.getValue();\n const updatedState = reducers.reduce((p, c) => c.updateState(p, nextAction), currentState);\n\n if (updatedState !== currentState) {\n this._state$.next(updatedState);\n }\n\n const effects = this.effectsPerActionType.get(nextAction.type) ?? [];\n this.logger.debug(`[Store] ${effects.length} effects found to process the action ${nextAction.type}`, effects);\n effects.forEach((effect) => {\n try {\n effect.processAction(this, updatedState, nextAction);\n } catch (error) {\n this.logger.error(`Unable to process action ${nextAction.type} by effect ${effect}`, {\n error,\n action: nextAction,\n processor: effect\n });\n }\n });\n } catch (error) {\n this.logger.error(`Error when processing action ${nextAction.type}`, {\n error,\n action: nextAction\n });\n } finally {\n this.logger.information(`[processNextAction] action '${nextAction.type} processed.`, nextAction);\n\n // Should not be useful.But, just in case.\n setTimeout(() => this.processNextAction());\n }\n }\n}\n","import { Component, OnDestroy } from '@angular/core';\nimport { map, Observable, Subject, distinctUntilChanged, takeUntil } from 'rxjs';\n\nimport { Action } from './action';\nimport { State } from './state';\nimport { Store } from './store';\n\n@Component({\n template: ''\n})\nexport class NgSsmComponent implements OnDestroy {\n private readonly _unsubscribeAll$ = new Subject<void>();\n\n constructor(protected store: Store) {}\n\n protected get unsubscribeAll$(): Observable<void> {\n return this._unsubscribeAll$.asObservable();\n }\n\n public ngOnDestroy(): void {\n this._unsubscribeAll$.next();\n this._unsubscribeAll$.complete();\n }\n\n public watch<T>(selector: (state: State) => T): Observable<T> {\n return this.store.state$.pipe(\n map((state) => selector(state)),\n distinctUntilChanged(),\n takeUntil(this.unsubscribeAll$)\n );\n }\n\n public dispatchAction(action: Action): void {\n this.store.dispatchAction(action);\n }\n\n public dispatchActionType(actionType: string): void {\n this.store.dispatchActionType(actionType);\n }\n}\n","import { BehaviorSubject } from 'rxjs';\nimport { Action } from './action';\n\nexport class StoreMock {\n public state$ = new BehaviorSubject<{ [key: string]: any }>({});\n\n constructor(initialState: { [key: string]: any }) {\n this.state$.next(initialState);\n }\n\n public dispatchAction(action: Action): void {}\n\n public dispatchActionType(type: string): void {}\n}\n","/*\n * Public API Surface of ngssm-store\n */\n\nexport * from './lib/ngssm-store.module';\n\nexport * from './lib/store';\nexport * from './lib/state';\nexport * from './lib/action';\nexport * from './lib/reducer';\nexport * from './lib/effect';\nexport * from './lib/feature-state-specification';\nexport * from './lib/ngssm-component';\nexport * from './lib/state-initializer';\n\nexport * from './lib/store-mock';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.Store"],"mappings":";;;;;;MAOa,gBAAgB,CAAA;;6GAAhB,gBAAgB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;8GAAhB,gBAAgB,EAAA,CAAA,CAAA;8GAAhB,gBAAgB,EAAA,CAAA,CAAA;2FAAhB,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAL5B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,YAAY,EAAE,EAAE;AAChB,oBAAA,OAAO,EAAE,EAAE;AACX,oBAAA,OAAO,EAAE,EAAE;iBACZ,CAAA;;;MCIY,aAAa,GAAG,IAAI,cAAc,CAAU,eAAe;;MCC3D,YAAY,GAAG,IAAI,cAAc,CAAS,cAAc;;MCJxD,uBAAuB,GAAG,IAAI,cAAc,CAAmB,yBAAyB;;ACOrG,MAAM,0BAA0B,GAAgC,EAAE,CAAC;AACtD,MAAA,iBAAiB,GAAG,CAAC,aAAwC,KAAI;IAC5E,OAAO,CAAC,MAAc,KAAI;AACxB,QAAA,0BAA0B,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AACjD,KAAC,CAAC;AACJ,EAAE;MAKW,KAAK,CAAA;AAMhB,IAAA,WAAA,CACU,MAAc,EACa,QAAmB,EACpB,OAAiB,EACN,YAAgC,EAAA;AAHrE,QAAA,IAAM,CAAA,MAAA,GAAN,MAAM,CAAQ;QANP,IAAA,CAAA,OAAO,GAAG,IAAI,eAAe,CAAQ,EAAE,CAAC,CAAC;AACzC,QAAA,IAAW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AAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,IAAA,EAAA,cAAc,oDAFf,EAAE,EAAA,QAAA,EAAA,IAAA,EAAA,CAAA,CAAA;2FAED,cAAc,EAAA,UAAA,EAAA,CAAA;kBAH1B,SAAS;AAAC,YAAA,IAAA,EAAA,CAAA;AACT,oBAAA,QAAQ,EAAE,EAAE;iBACb,CAAA;;;MCNY,SAAS,CAAA;AAGpB,IAAA,WAAA,CAAY,YAAoC,EAAA;QAFzC,IAAA,CAAA,MAAM,GAAG,IAAI,eAAe,CAAyB,EAAE,CAAC,CAAC;AAG9D,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;KAChC;IAEM,cAAc,CAAC,MAAc,EAAA,GAAU;IAEvC,kBAAkB,CAAC,IAAY,EAAA,GAAU;AACjD;;ACbD;;AAEG;;ACFH;;AAEG;;;;"}
|
package/fesm2020/ngssm-store.mjs
CHANGED
|
@@ -177,6 +177,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
|
|
|
177
177
|
}]
|
|
178
178
|
}], ctorParameters: function () { return [{ type: Store }]; } });
|
|
179
179
|
|
|
180
|
+
class StoreMock {
|
|
181
|
+
constructor(initialState) {
|
|
182
|
+
this.state$ = new BehaviorSubject({});
|
|
183
|
+
this.state$.next(initialState);
|
|
184
|
+
}
|
|
185
|
+
dispatchAction(action) { }
|
|
186
|
+
dispatchActionType(type) { }
|
|
187
|
+
}
|
|
188
|
+
|
|
180
189
|
/*
|
|
181
190
|
* Public API Surface of ngssm-store
|
|
182
191
|
*/
|
|
@@ -185,5 +194,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImpor
|
|
|
185
194
|
* Generated bundle index. Do not edit.
|
|
186
195
|
*/
|
|
187
196
|
|
|
188
|
-
export { NGSSM_EFFECT, NGSSM_REDUCER, NGSSM_STATE_INITIALIZER, NgSsmComponent, NgSsmFeatureState, NgssmStoreModule, Store };
|
|
197
|
+
export { NGSSM_EFFECT, NGSSM_REDUCER, NGSSM_STATE_INITIALIZER, NgSsmComponent, NgSsmFeatureState, NgssmStoreModule, Store, StoreMock };
|
|
189
198
|
//# sourceMappingURL=ngssm-store.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngssm-store.mjs","sources":["../../../projects/ngssm-store/src/lib/ngssm-store.module.ts","../../../projects/ngssm-store/src/lib/reducer.ts","../../../projects/ngssm-store/src/lib/effect.ts","../../../projects/ngssm-store/src/lib/state-initializer.ts","../../../projects/ngssm-store/src/lib/store.ts","../../../projects/ngssm-store/src/lib/ngssm-component.ts","../../../projects/ngssm-store/src/public-api.ts","../../../projects/ngssm-store/src/ngssm-store.ts"],"sourcesContent":["import { NgModule } from '@angular/core';\n\n@NgModule({\n declarations: [],\n imports: [],\n exports: []\n})\nexport class NgssmStoreModule {}\n","import { InjectionToken } from '@angular/core';\n\nimport { Action } from './action';\nimport { State } from './state';\n\nexport interface Reducer {\n processedActions: string[];\n updateState(state: State, action: Action): State;\n}\n\nexport const NGSSM_REDUCER = new InjectionToken<Reducer>('NGSSM_REDUCER');\n","import { InjectionToken } from '@angular/core';\n\nimport { Action } from './action';\nimport { State } from './state';\nimport { Store } from './store';\n\nexport interface Effect {\n processedActions: string[];\n processAction(store: Store, state: State, action: Action): void;\n}\n\nexport const NGSSM_EFFECT = new InjectionToken<Effect>('NGSSM_EFFECT');\n","import { InjectionToken } from '@angular/core';\nimport { State } from './state';\n\nexport interface StateInitializer {\n initializeState(state: State): State;\n}\n\nexport const NGSSM_STATE_INITIALIZER = new InjectionToken<StateInitializer>('NGSSM_STATE_INITIALIZER');\n","import { Inject, Injectable, Optional } from '@angular/core';\nimport { BehaviorSubject, Observable } from 'rxjs';\n\nimport update from 'immutability-helper';\n\nimport { Logger } from 'ngssm-toolkit';\n\nimport { FeatureStateSpecification } from './feature-state-specification';\nimport { State } from './state';\nimport { Action } from './action';\nimport { NGSSM_REDUCER, Reducer } from './reducer';\nimport { Effect, NGSSM_EFFECT } from './effect';\nimport { NGSSM_STATE_INITIALIZER, StateInitializer } from './state-initializer';\n\nconst featureStateSpecifications: FeatureStateSpecification[] = [];\nexport const NgSsmFeatureState = (specification: FeatureStateSpecification) => {\n return (target: object) => {\n featureStateSpecifications.push(specification);\n };\n};\n\n@Injectable({\n providedIn: 'root'\n})\nexport class Store {\n private readonly _state$ = new BehaviorSubject<State>({});\n private readonly actionQueue: Action[] = [];\n private readonly reducersPerActionType = new Map<string, Reducer[]>();\n private readonly effectsPerActionType = new Map<string, Effect[]>();\n\n constructor(\n private logger: Logger,\n @Inject(NGSSM_REDUCER) @Optional() reducers: Reducer[],\n @Inject(NGSSM_EFFECT) @Optional() effects: Effect[],\n @Inject(NGSSM_STATE_INITIALIZER) @Optional() initializers: StateInitializer[]\n ) {\n this.logger.information('[Store] ---> state initialization...');\n let state = this._state$.getValue();\n state = featureStateSpecifications.reduce((p, c) => update(p, { [c.featureStateKey]: { $set: c.initialState } }), state);\n\n (initializers ?? []).forEach((initializer) => {\n this.logger.information('[Store] ------> calling initializer', initializer);\n state = initializer.initializeState(state);\n });\n\n this._state$.next(state);\n\n this.logger.information(`[Store] ---> initialization of ${(reducers ?? []).length} reducers...`);\n (reducers ?? []).forEach((reducer) => {\n this.logger.information('[Store] ------> initialization of ', reducer);\n reducer.processedActions.forEach((processedAction) => {\n const storeReducers: Reducer[] = this.reducersPerActionType.get(processedAction) ?? [];\n if (storeReducers.length === 0) {\n this.reducersPerActionType.set(processedAction, storeReducers);\n }\n\n storeReducers.push(reducer);\n });\n });\n\n this.logger.information(`[Store] ---> initialization of ${(effects ?? []).length} effects...`);\n (effects ?? []).forEach((effect) => {\n this.logger.information('[Store] ------> initialization of ', effect);\n effect.processedActions.forEach((processedAction) => {\n const storedEffects: Effect[] = this.effectsPerActionType.get(processedAction) ?? [];\n if (storedEffects.length === 0) {\n this.effectsPerActionType.set(processedAction, storedEffects);\n }\n\n storedEffects.push(effect);\n });\n });\n }\n\n public get state$(): Observable<State> {\n return this._state$.asObservable();\n }\n\n public dispatchAction(action: Action): void {\n this.actionQueue.push(action);\n this.logger.debug(`Action of type '${action.type}' added to the queue => ${this.actionQueue.length} pending actions`, action);\n setTimeout(() => this.processNextAction());\n }\n\n public dispatchActionType(type: string): void {\n this.dispatchAction({ type });\n }\n\n private processNextAction(): void {\n const nextAction = this.actionQueue.shift();\n if (!nextAction) {\n this.logger.debug('[processNextAction] No action to process');\n return;\n }\n\n this.logger.information(`[processNextAction] Start processing action '${nextAction.type}...`, nextAction);\n\n try {\n const reducers = this.reducersPerActionType.get(nextAction.type) ?? [];\n this.logger.debug(`[Store] ${reducers.length} reducers found to process the action ${nextAction.type}`, reducers);\n const currentState = this._state$.getValue();\n const updatedState = reducers.reduce((p, c) => c.updateState(p, nextAction), currentState);\n\n if (updatedState !== currentState) {\n this._state$.next(updatedState);\n }\n\n const effects = this.effectsPerActionType.get(nextAction.type) ?? [];\n this.logger.debug(`[Store] ${effects.length} effects found to process the action ${nextAction.type}`, effects);\n effects.forEach((effect) => {\n try {\n effect.processAction(this, updatedState, nextAction);\n } catch (error) {\n this.logger.error(`Unable to process action ${nextAction.type} by effect ${effect}`, {\n error,\n action: nextAction,\n processor: effect\n });\n }\n });\n } catch (error) {\n this.logger.error(`Error when processing action ${nextAction.type}`, {\n error,\n action: nextAction\n });\n } finally {\n this.logger.information(`[processNextAction] action '${nextAction.type} processed.`, nextAction);\n\n // Should not be useful.But, just in case.\n setTimeout(() => this.processNextAction());\n }\n }\n}\n","import { Component, OnDestroy } from '@angular/core';\nimport { map, Observable, Subject, distinctUntilChanged, takeUntil } from 'rxjs';\n\nimport { Action } from './action';\nimport { State } from './state';\nimport { Store } from './store';\n\n@Component({\n template: ''\n})\nexport class NgSsmComponent implements OnDestroy {\n private readonly _unsubscribeAll$ = new Subject<void>();\n\n constructor(protected store: Store) {}\n\n protected get unsubscribeAll$(): Observable<void> {\n return this._unsubscribeAll$.asObservable();\n }\n\n public ngOnDestroy(): void {\n this._unsubscribeAll$.next();\n this._unsubscribeAll$.complete();\n }\n\n public watch<T>(selector: (state: State) => T): Observable<T> {\n return this.store.state$.pipe(\n map((state) => selector(state)),\n distinctUntilChanged(),\n takeUntil(this.unsubscribeAll$)\n );\n }\n\n public dispatchAction(action: Action): void {\n this.store.dispatchAction(action);\n }\n\n public dispatchActionType(actionType: string): void {\n this.store.dispatchActionType(actionType);\n }\n}\n","/*\n * Public API Surface of ngssm-store\n */\n\nexport * from './lib/ngssm-store.module';\n\nexport * from './lib/store';\nexport * from './lib/state';\nexport * from './lib/action';\nexport * from './lib/reducer';\nexport * from './lib/effect';\nexport * from './lib/feature-state-specification';\nexport * from './lib/ngssm-component';\nexport * from './lib/state-initializer';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.Store"],"mappings":";;;;;;MAOa,gBAAgB,CAAA;;6GAAhB,gBAAgB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;8GAAhB,gBAAgB,EAAA,CAAA,CAAA;8GAAhB,gBAAgB,EAAA,CAAA,CAAA;2FAAhB,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAL5B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,YAAY,EAAE,EAAE;AAChB,oBAAA,OAAO,EAAE,EAAE;AACX,oBAAA,OAAO,EAAE,EAAE;AACZ,iBAAA,CAAA;;;MCIY,aAAa,GAAG,IAAI,cAAc,CAAU,eAAe;;MCC3D,YAAY,GAAG,IAAI,cAAc,CAAS,cAAc;;MCJxD,uBAAuB,GAAG,IAAI,cAAc,CAAmB,yBAAyB;;ACOrG,MAAM,0BAA0B,GAAgC,EAAE,CAAC;AACtD,MAAA,iBAAiB,GAAG,CAAC,aAAwC,KAAI;IAC5E,OAAO,CAAC,MAAc,KAAI;AAC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|
|
1
|
+
{"version":3,"file":"ngssm-store.mjs","sources":["../../../projects/ngssm-store/src/lib/ngssm-store.module.ts","../../../projects/ngssm-store/src/lib/reducer.ts","../../../projects/ngssm-store/src/lib/effect.ts","../../../projects/ngssm-store/src/lib/state-initializer.ts","../../../projects/ngssm-store/src/lib/store.ts","../../../projects/ngssm-store/src/lib/ngssm-component.ts","../../../projects/ngssm-store/src/lib/store-mock.ts","../../../projects/ngssm-store/src/public-api.ts","../../../projects/ngssm-store/src/ngssm-store.ts"],"sourcesContent":["import { NgModule } from '@angular/core';\n\n@NgModule({\n declarations: [],\n imports: [],\n exports: []\n})\nexport class NgssmStoreModule {}\n","import { InjectionToken } from '@angular/core';\n\nimport { Action } from './action';\nimport { State } from './state';\n\nexport interface Reducer {\n processedActions: string[];\n updateState(state: State, action: Action): State;\n}\n\nexport const NGSSM_REDUCER = new InjectionToken<Reducer>('NGSSM_REDUCER');\n","import { InjectionToken } from '@angular/core';\n\nimport { Action } from './action';\nimport { State } from './state';\nimport { Store } from './store';\n\nexport interface Effect {\n processedActions: string[];\n processAction(store: Store, state: State, action: Action): void;\n}\n\nexport const NGSSM_EFFECT = new InjectionToken<Effect>('NGSSM_EFFECT');\n","import { InjectionToken } from '@angular/core';\nimport { State } from './state';\n\nexport interface StateInitializer {\n initializeState(state: State): State;\n}\n\nexport const NGSSM_STATE_INITIALIZER = new InjectionToken<StateInitializer>('NGSSM_STATE_INITIALIZER');\n","import { Inject, Injectable, Optional } from '@angular/core';\nimport { BehaviorSubject, Observable } from 'rxjs';\n\nimport update from 'immutability-helper';\n\nimport { Logger } from 'ngssm-toolkit';\n\nimport { FeatureStateSpecification } from './feature-state-specification';\nimport { State } from './state';\nimport { Action } from './action';\nimport { NGSSM_REDUCER, Reducer } from './reducer';\nimport { Effect, NGSSM_EFFECT } from './effect';\nimport { NGSSM_STATE_INITIALIZER, StateInitializer } from './state-initializer';\n\nconst featureStateSpecifications: FeatureStateSpecification[] = [];\nexport const NgSsmFeatureState = (specification: FeatureStateSpecification) => {\n return (target: object) => {\n featureStateSpecifications.push(specification);\n };\n};\n\n@Injectable({\n providedIn: 'root'\n})\nexport class Store {\n private readonly _state$ = new BehaviorSubject<State>({});\n private readonly actionQueue: Action[] = [];\n private readonly reducersPerActionType = new Map<string, Reducer[]>();\n private readonly effectsPerActionType = new Map<string, Effect[]>();\n\n constructor(\n private logger: Logger,\n @Inject(NGSSM_REDUCER) @Optional() reducers: Reducer[],\n @Inject(NGSSM_EFFECT) @Optional() effects: Effect[],\n @Inject(NGSSM_STATE_INITIALIZER) @Optional() initializers: StateInitializer[]\n ) {\n this.logger.information('[Store] ---> state initialization...');\n let state = this._state$.getValue();\n state = featureStateSpecifications.reduce((p, c) => update(p, { [c.featureStateKey]: { $set: c.initialState } }), state);\n\n (initializers ?? []).forEach((initializer) => {\n this.logger.information('[Store] ------> calling initializer', initializer);\n state = initializer.initializeState(state);\n });\n\n this._state$.next(state);\n\n this.logger.information(`[Store] ---> initialization of ${(reducers ?? []).length} reducers...`);\n (reducers ?? []).forEach((reducer) => {\n this.logger.information('[Store] ------> initialization of ', reducer);\n reducer.processedActions.forEach((processedAction) => {\n const storeReducers: Reducer[] = this.reducersPerActionType.get(processedAction) ?? [];\n if (storeReducers.length === 0) {\n this.reducersPerActionType.set(processedAction, storeReducers);\n }\n\n storeReducers.push(reducer);\n });\n });\n\n this.logger.information(`[Store] ---> initialization of ${(effects ?? []).length} effects...`);\n (effects ?? []).forEach((effect) => {\n this.logger.information('[Store] ------> initialization of ', effect);\n effect.processedActions.forEach((processedAction) => {\n const storedEffects: Effect[] = this.effectsPerActionType.get(processedAction) ?? [];\n if (storedEffects.length === 0) {\n this.effectsPerActionType.set(processedAction, storedEffects);\n }\n\n storedEffects.push(effect);\n });\n });\n }\n\n public get state$(): Observable<State> {\n return this._state$.asObservable();\n }\n\n public dispatchAction(action: Action): void {\n this.actionQueue.push(action);\n this.logger.debug(`Action of type '${action.type}' added to the queue => ${this.actionQueue.length} pending actions`, action);\n setTimeout(() => this.processNextAction());\n }\n\n public dispatchActionType(type: string): void {\n this.dispatchAction({ type });\n }\n\n private processNextAction(): void {\n const nextAction = this.actionQueue.shift();\n if (!nextAction) {\n this.logger.debug('[processNextAction] No action to process');\n return;\n }\n\n this.logger.information(`[processNextAction] Start processing action '${nextAction.type}...`, nextAction);\n\n try {\n const reducers = this.reducersPerActionType.get(nextAction.type) ?? [];\n this.logger.debug(`[Store] ${reducers.length} reducers found to process the action ${nextAction.type}`, reducers);\n const currentState = this._state$.getValue();\n const updatedState = reducers.reduce((p, c) => c.updateState(p, nextAction), currentState);\n\n if (updatedState !== currentState) {\n this._state$.next(updatedState);\n }\n\n const effects = this.effectsPerActionType.get(nextAction.type) ?? [];\n this.logger.debug(`[Store] ${effects.length} effects found to process the action ${nextAction.type}`, effects);\n effects.forEach((effect) => {\n try {\n effect.processAction(this, updatedState, nextAction);\n } catch (error) {\n this.logger.error(`Unable to process action ${nextAction.type} by effect ${effect}`, {\n error,\n action: nextAction,\n processor: effect\n });\n }\n });\n } catch (error) {\n this.logger.error(`Error when processing action ${nextAction.type}`, {\n error,\n action: nextAction\n });\n } finally {\n this.logger.information(`[processNextAction] action '${nextAction.type} processed.`, nextAction);\n\n // Should not be useful.But, just in case.\n setTimeout(() => this.processNextAction());\n }\n }\n}\n","import { Component, OnDestroy } from '@angular/core';\nimport { map, Observable, Subject, distinctUntilChanged, takeUntil } from 'rxjs';\n\nimport { Action } from './action';\nimport { State } from './state';\nimport { Store } from './store';\n\n@Component({\n template: ''\n})\nexport class NgSsmComponent implements OnDestroy {\n private readonly _unsubscribeAll$ = new Subject<void>();\n\n constructor(protected store: Store) {}\n\n protected get unsubscribeAll$(): Observable<void> {\n return this._unsubscribeAll$.asObservable();\n }\n\n public ngOnDestroy(): void {\n this._unsubscribeAll$.next();\n this._unsubscribeAll$.complete();\n }\n\n public watch<T>(selector: (state: State) => T): Observable<T> {\n return this.store.state$.pipe(\n map((state) => selector(state)),\n distinctUntilChanged(),\n takeUntil(this.unsubscribeAll$)\n );\n }\n\n public dispatchAction(action: Action): void {\n this.store.dispatchAction(action);\n }\n\n public dispatchActionType(actionType: string): void {\n this.store.dispatchActionType(actionType);\n }\n}\n","import { BehaviorSubject } from 'rxjs';\nimport { Action } from './action';\n\nexport class StoreMock {\n public state$ = new BehaviorSubject<{ [key: string]: any }>({});\n\n constructor(initialState: { [key: string]: any }) {\n this.state$.next(initialState);\n }\n\n public dispatchAction(action: Action): void {}\n\n public dispatchActionType(type: string): void {}\n}\n","/*\n * Public API Surface of ngssm-store\n */\n\nexport * from './lib/ngssm-store.module';\n\nexport * from './lib/store';\nexport * from './lib/state';\nexport * from './lib/action';\nexport * from './lib/reducer';\nexport * from './lib/effect';\nexport * from './lib/feature-state-specification';\nexport * from './lib/ngssm-component';\nexport * from './lib/state-initializer';\n\nexport * from './lib/store-mock';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":["i1.Store"],"mappings":";;;;;;MAOa,gBAAgB,CAAA;;6GAAhB,gBAAgB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;8GAAhB,gBAAgB,EAAA,CAAA,CAAA;8GAAhB,gBAAgB,EAAA,CAAA,CAAA;2FAAhB,gBAAgB,EAAA,UAAA,EAAA,CAAA;kBAL5B,QAAQ;AAAC,YAAA,IAAA,EAAA,CAAA;AACR,oBAAA,YAAY,EAAE,EAAE;AAChB,oBAAA,OAAO,EAAE,EAAE;AACX,oBAAA,OAAO,EAAE,EAAE;AACZ,iBAAA,CAAA;;;MCIY,aAAa,GAAG,IAAI,cAAc,CAAU,eAAe;;MCC3D,YAAY,GAAG,IAAI,cAAc,CAAS,cAAc;;MCJxD,uBAAuB,GAAG,IAAI,cAAc,CAAmB,yBAAyB;;ACOrG,MAAM,0BAA0B,GAAgC,EAAE,CAAC;AACtD,MAAA,iBAAiB,GAAG,CAAC,aAAwC,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A;;;MCNY,SAAS,CAAA;AAGpB,IAAA,WAAA,CAAY,YAAoC,EAAA;AAFzC,QAAA,IAAA,CAAA,MAAM,GAAG,IAAI,eAAe,CAAyB,EAAE,CAAC,CAAC;AAG9D,QAAA,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;KAChC;IAEM,cAAc,CAAC,MAAc,EAAA,GAAU;IAEvC,kBAAkB,CAAC,IAAY,EAAA,GAAU;AACjD;;ACbD;;AAEG;;ACFH;;AAEG;;;;"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BehaviorSubject } from 'rxjs';
|
|
2
|
+
import { Action } from './action';
|
|
3
|
+
export declare class StoreMock {
|
|
4
|
+
state$: BehaviorSubject<{
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}>;
|
|
7
|
+
constructor(initialState: {
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
});
|
|
10
|
+
dispatchAction(action: Action): void;
|
|
11
|
+
dispatchActionType(type: string): void;
|
|
12
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ngssm-store",
|
|
3
|
-
"version": "14.1.
|
|
3
|
+
"version": "14.1.2",
|
|
4
4
|
"description": "NgSsm - Simple state management implementation.",
|
|
5
5
|
"author": "Lion Marc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"@angular/common": "^14.2.0",
|
|
9
9
|
"@angular/core": "^14.2.0",
|
|
10
10
|
"immutability-helper": "^3.1.1",
|
|
11
|
-
"ngssm-toolkit": "14.1.
|
|
11
|
+
"ngssm-toolkit": "14.1.2"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"tslib": "^2.3.0"
|
package/public-api.d.ts
CHANGED