ngssm-store 14.0.0
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/README.md +85 -0
- package/esm2020/lib/action.mjs +2 -0
- package/esm2020/lib/effect.mjs +3 -0
- package/esm2020/lib/feature-state-specification.mjs +2 -0
- package/esm2020/lib/ngssm-component.mjs +35 -0
- package/esm2020/lib/ngssm-store.module.mjs +16 -0
- package/esm2020/lib/reducer.mjs +3 -0
- package/esm2020/lib/state-initializer.mjs +3 -0
- package/esm2020/lib/state.mjs +2 -0
- package/esm2020/lib/store.mjs +130 -0
- package/esm2020/ngssm-store.mjs +5 -0
- package/esm2020/public-api.mjs +13 -0
- package/fesm2015/ngssm-store.mjs +194 -0
- package/fesm2015/ngssm-store.mjs.map +1 -0
- package/fesm2020/ngssm-store.mjs +189 -0
- package/fesm2020/ngssm-store.mjs.map +1 -0
- package/index.d.ts +5 -0
- package/lib/action.d.ts +3 -0
- package/lib/effect.d.ts +9 -0
- package/lib/feature-state-specification.d.ts +6 -0
- package/lib/ngssm-component.d.ts +18 -0
- package/lib/ngssm-store.module.d.ts +6 -0
- package/lib/reducer.d.ts +8 -0
- package/lib/state-initializer.d.ts +6 -0
- package/lib/state.d.ts +3 -0
- package/lib/store.d.ts +24 -0
- package/package.json +41 -0
- package/public-api.d.ts +9 -0
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# State management
|
|
2
|
+
|
|
3
|
+
This is a simple custom adaptation and implementation of the **redux** pattern.
|
|
4
|
+
|
|
5
|
+
```mermaid
|
|
6
|
+
graph TB;
|
|
7
|
+
B["Store (State manager)"]
|
|
8
|
+
C[/Actions queue/]
|
|
9
|
+
A["State Observers: <br/> <ul> <li>Components</li> <li>Directives</li> <li>Guards</li></ul>"]
|
|
10
|
+
|
|
11
|
+
subgraph G[Action processors]
|
|
12
|
+
D[<b>Reducers</b> <br/> Updates state synchronously taking state immutability into account]
|
|
13
|
+
E[<b>Effects</b> <br/> No update of the state. <br/> Call to remote services <br/> Actions dispatch...]
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
C --- B
|
|
17
|
+
A -- Dispatch actions --> B
|
|
18
|
+
B -- Publish state --> A
|
|
19
|
+
B -- Apply action on state --> D
|
|
20
|
+
B -- Process action --> E
|
|
21
|
+
D -- Updated state --> B
|
|
22
|
+
E -- Dispatch actions --> B
|
|
23
|
+
|
|
24
|
+
style A text-align:left
|
|
25
|
+
style C fill:lightgray
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Store Overview
|
|
29
|
+
|
|
30
|
+
### Action dispatching
|
|
31
|
+
|
|
32
|
+
```mermaid
|
|
33
|
+
sequenceDiagram
|
|
34
|
+
actor O as Component/Effect
|
|
35
|
+
participant S as Store
|
|
36
|
+
participant Q as Actions Queue
|
|
37
|
+
participant E as Event loop
|
|
38
|
+
O->>S: dispatch action
|
|
39
|
+
S->>Q: add action
|
|
40
|
+
S->>E: add message to process next action
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
> An action dispatched by a component or an effect is not processed immediately. The store uses the `setTimeout` function to process "later" the action.
|
|
44
|
+
|
|
45
|
+
### Action processing
|
|
46
|
+
|
|
47
|
+
```mermaid
|
|
48
|
+
sequenceDiagram
|
|
49
|
+
participant L as Event loop
|
|
50
|
+
participant S as Store
|
|
51
|
+
participant Q as Actions Queue
|
|
52
|
+
actor O as State Observer
|
|
53
|
+
participant R as Reducer
|
|
54
|
+
participant E as Effect
|
|
55
|
+
L->>S: doProcessNextAction
|
|
56
|
+
S->>Q: get next available action
|
|
57
|
+
alt There is an action to process
|
|
58
|
+
loop For all registered reducers for the current sction
|
|
59
|
+
S->>R: update state
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
S->>O: publish new state
|
|
63
|
+
|
|
64
|
+
loop For all registered effects for the current action
|
|
65
|
+
S->>E: process action
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
S->>L: add message to process next action
|
|
69
|
+
end
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Dependencies
|
|
73
|
+
|
|
74
|
+
- [angular](https://github.com/angular/angular): the library uses the dependency injection system provided by **angular**,
|
|
75
|
+
- [rxjs](https://rxjs.dev/): the publish/subscribe pattern is implemented with **rxjs**,
|
|
76
|
+
- [immutability-helper](https://github.com/kolodny/immutability-helper): used by the reducers to update safely the state
|
|
77
|
+
|
|
78
|
+
> The state must be immutable. But, to simplify the implementation, it is the responsibility of the user to be sure that the state instance is never updated.
|
|
79
|
+
|
|
80
|
+
- [schematics](https://www.npmjs.com/package/@angular-devkit/schematics): schematics are provided to create feature state, components, reducers, effects, actions...
|
|
81
|
+
- [mermaid.js](https://mermaid-js.github.io/mermaid/#/) for the documentation.
|
|
82
|
+
|
|
83
|
+
## Schematics
|
|
84
|
+
|
|
85
|
+
See [ngssm-schematics](/projects/ngssm-schematics/README.md) for schematics used to create feature state, action, reducer, effect...
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vcHJvamVjdHMvbmdzc20tc3RvcmUvc3JjL2xpYi9hY3Rpb24udHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IiIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBpbnRlcmZhY2UgQWN0aW9uIHtcbiAgdHlwZTogc3RyaW5nO1xufVxuIl19
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
export const NGSSM_EFFECT = new InjectionToken('NGSSM_EFFECT');
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZWZmZWN0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4v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IjpbImV4cG9ydCBpbnRlcmZhY2UgRmVhdHVyZVN0YXRlU3BlY2lmaWNhdGlvbiB7XG4gIHJlYWRvbmx5IGZlYXR1cmVTdGF0ZUtleTogc3RyaW5nO1xuICByZWFkb25seSBpbml0aWFsU3RhdGU6IHsgW2tleTogc3RyaW5nXTogYW55IH07XG59XG4iXX0=
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Component } from '@angular/core';
|
|
2
|
+
import { map, Subject, distinctUntilChanged, takeUntil } from 'rxjs';
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
import * as i1 from "./store";
|
|
5
|
+
export class NgSsmComponent {
|
|
6
|
+
constructor(store) {
|
|
7
|
+
this.store = store;
|
|
8
|
+
this._unsubscribeAll$ = new Subject();
|
|
9
|
+
}
|
|
10
|
+
get unsubscribeAll$() {
|
|
11
|
+
return this._unsubscribeAll$.asObservable();
|
|
12
|
+
}
|
|
13
|
+
ngOnDestroy() {
|
|
14
|
+
this._unsubscribeAll$.next();
|
|
15
|
+
this._unsubscribeAll$.complete();
|
|
16
|
+
}
|
|
17
|
+
watch(selector) {
|
|
18
|
+
return this.store.state$.pipe(map((state) => selector(state)), distinctUntilChanged(), takeUntil(this.unsubscribeAll$));
|
|
19
|
+
}
|
|
20
|
+
dispatchAction(action) {
|
|
21
|
+
this.store.dispatchAction(action);
|
|
22
|
+
}
|
|
23
|
+
dispatchActionType(actionType) {
|
|
24
|
+
this.store.dispatchActionType(actionType);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
NgSsmComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: NgSsmComponent, deps: [{ token: i1.Store }], target: i0.ɵɵFactoryTarget.Component });
|
|
28
|
+
NgSsmComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.2", type: NgSsmComponent, selector: "ng-component", ngImport: i0, template: '', isInline: true });
|
|
29
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: NgSsmComponent, decorators: [{
|
|
30
|
+
type: Component,
|
|
31
|
+
args: [{
|
|
32
|
+
template: ''
|
|
33
|
+
}]
|
|
34
|
+
}], ctorParameters: function () { return [{ type: i1.Store }]; } });
|
|
35
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmdzc20tY29tcG9uZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vcHJvamVjdHMvbmdzc20tc3RvcmUvc3JjL2xpYi9uZ3NzbS1jb21wb25lbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFNBQVMsRUFBYSxNQUFNLGVBQWUsQ0FBQztBQUNyRCxPQUFPLEVBQUUsR0FBRyxFQUFjLE9BQU8sRUFBRSxvQkFBb0IsRUFBRSxTQUFTLEVBQUUsTUFBTSxNQUFNLENBQUM7OztBQVNqRixNQUFNLE9BQU8sY0FBYztJQUd6QixZQUFzQixLQUFZO1FBQVosVUFBSyxHQUFMLEtBQUssQ0FBTztRQUZqQixxQkFBZ0IsR0FBRyxJQUFJLE9BQU8sRUFBUSxDQUFDO0lBRW5CLENBQUM7SUFFdEMsSUFBYyxlQUFlO1FBQzNCLE9BQU8sSUFBSSxDQUFDLGdCQUFnQixDQUFDLFlBQVksRUFBRSxDQUFDO0lBQzlDLENBQUM7SUFFTSxXQUFXO1FBQ2hCLElBQUksQ0FBQyxnQkFBZ0IsQ0FBQyxJQUFJLEVBQUUsQ0FBQztRQUM3QixJQUFJLENBQUMsZ0JBQWdCLENBQUMsUUFBUSxFQUFFLENBQUM7SUFDbkMsQ0FBQztJQUVNLEtBQUssQ0FBSSxRQUE2QjtRQUMzQyxPQUFPLElBQUksQ0FBQyxLQUFLLENBQUMsTUFBTSxDQUFDLElBQUksQ0FDM0IsR0FBRyxDQUFD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IGNvbnN0cnVjdG9yKHByb3RlY3RlZCBzdG9yZTogU3RvcmUpIHt9XG5cbiAgcHJvdGVjdGVkIGdldCB1bnN1YnNjcmliZUFsbCQoKTogT2JzZXJ2YWJsZTx2b2lkPiB7XG4gICAgcmV0dXJuIHRoaXMuX3Vuc3Vic2NyaWJlQWxsJC5hc09ic2VydmFibGUoKTtcbiAgfVxuXG4gIHB1YmxpYyBuZ09uRGVzdHJveSgpOiB2b2lkIHtcbiAgICB0aGlzLl91bnN1YnNjcmliZUFsbCQubmV4dCgpO1xuICAgIHRoaXMuX3Vuc3Vic2NyaWJlQWxsJC5jb21wbGV0ZSgpO1xuICB9XG5cbiAgcHVibGljIHdhdGNoPFQ+KHNlbGVjdG9yOiAoc3RhdGU6IFN0YXRlKSA9PiBUKTogT2JzZXJ2YWJsZTxUPiB7XG4gICAgcmV0dXJuIHRoaXMuc3RvcmUuc3RhdGUkLnBpcGUoXG4gICAgICBtYXAoKHN0YXRlKSA9PiBzZWxlY3RvcihzdGF0ZSkpLFxuICAgICAgZGlzdGluY3RVbnRpbENoYW5nZWQoKSxcbiAgICAgIHRha2VVbnRpbCh0aGlzLnVuc3Vic2NyaWJlQWxsJClcbiAgICApO1xuICB9XG5cbiAgcHVibGljIGRpc3BhdGNoQWN0aW9uKGFjdGlvbjogQWN0aW9uKTogdm9pZCB7XG4gICAgdGhpcy5zdG9yZS5kaXNwYXRjaEFjdGlvbihhY3Rpb24pO1xuICB9XG5cbiAgcHVibGljIGRpc3BhdGNoQWN0aW9uVHlwZShhY3Rpb25UeXBlOiBzdHJpbmcpOiB2b2lkIHtcbiAgICB0aGlzLnN0b3JlLmRpc3BhdGNoQWN0aW9uVHlwZShhY3Rpb25UeXBlKTtcbiAgfVxufVxuIl19
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NgModule } from '@angular/core';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
export class NgssmStoreModule {
|
|
4
|
+
}
|
|
5
|
+
NgssmStoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: NgssmStoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
6
|
+
NgssmStoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.2", ngImport: i0, type: NgssmStoreModule });
|
|
7
|
+
NgssmStoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: NgssmStoreModule });
|
|
8
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: NgssmStoreModule, decorators: [{
|
|
9
|
+
type: NgModule,
|
|
10
|
+
args: [{
|
|
11
|
+
declarations: [],
|
|
12
|
+
imports: [],
|
|
13
|
+
exports: []
|
|
14
|
+
}]
|
|
15
|
+
}] });
|
|
16
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmdzc20tc3RvcmUubW9kdWxlLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vcHJvamVjdHMvbmdzc20tc3RvcmUvc3JjL2xpYi9uZ3NzbS1zdG9yZS5tb2R1bGUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLFFBQVEsRUFBRSxNQUFNLGVBQWUsQ0FBQzs7QUFPekMsTUFBTSxPQUFPLGdCQUFnQjs7NkdBQWhCLGdCQUFnQjs4R0FBaEIsZ0JBQWdCOzhHQUFoQixnQkFBZ0I7MkZBQWhCLGdCQUFnQjtrQkFMNUIsUUFBUTttQkFBQztvQkFDUixZQUFZLEVBQUUsRUFBRTtvQkFDaEIsT0FBTyxFQUFFLEVBQUU7b0JBQ1gsT0FBTyxFQUFFLEVBQUU7aUJBQ1oiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBOZ01vZHVsZSB9IGZyb20gJ0Bhbmd1bGFyL2NvcmUnO1xuXG5ATmdNb2R1bGUoe1xuICBkZWNsYXJhdGlvbnM6IFtdLFxuICBpbXBvcnRzOiBbXSxcbiAgZXhwb3J0czogW11cbn0pXG5leHBvcnQgY2xhc3MgTmdzc21TdG9yZU1vZHVsZSB7fVxuIl19
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
export const NGSSM_REDUCER = new InjectionToken('NGSSM_REDUCER');
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVkdWNlci5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uL3Byb2plY3RzL25nc3NtLXN0b3JlL3NyYy9saWIvcmVkdWNlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxPQUFPLEVBQUUsY0FBYyxFQUFFLE1BQU0sZUFBZSxDQUFDO0FBVS9DLE1BQU0sQ0FBQyxNQUFNLGFBQWEsR0FBRyxJQUFJLGNBQWMsQ0FBVSxlQUFlLENBQUMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbImltcG9ydCB7IEluamVjdGlvblRva2VuIH0gZnJvbSAnQGFuZ3VsYXIvY29yZSc7XG5cbmltcG9ydCB7IEFjdGlvbiB9IGZyb20gJy4vYWN0aW9uJztcbmltcG9ydCB7IFN0YXRlIH0gZnJvbSAnLi9zdGF0ZSc7XG5cbmV4cG9ydCBpbnRlcmZhY2UgUmVkdWNlciB7XG4gIHByb2Nlc3NlZEFjdGlvbnM6IHN0cmluZ1tdO1xuICB1cGRhdGVTdGF0ZShzdGF0ZTogU3RhdGUsIGFjdGlvbjogQWN0aW9uKTogU3RhdGU7XG59XG5cbmV4cG9ydCBjb25zdCBOR1NTTV9SRURVQ0VSID0gbmV3IEluamVjdGlvblRva2VuPFJlZHVjZXI+KCdOR1NTTV9SRURVQ0VSJyk7XG4iXX0=
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
export const NGSSM_STATE_INITIALIZER = new InjectionToken('NGSSM_STATE_INITIALIZER');
|
|
3
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RhdGUtaW5pdGlhbGl6ZXIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9uZ3NzbS1zdG9yZS9zcmMvbGliL3N0YXRlLWluaXRpYWxpemVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxjQUFjLEVBQUUsTUFBTSxlQUFlLENBQUM7QUFPL0MsTUFBTSxDQUFDLE1BQU0sdUJBQXVCLEdBQUcsSUFBSSxjQUFjLENBQW1CLHlCQUF5QixDQUFDLENBQUMiLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBJbmplY3Rpb25Ub2tlbiB9IGZyb20gJ0Bhbmd1bGFyL2NvcmUnO1xuaW1wb3J0IHsgU3RhdGUgfSBmcm9tICcuL3N0YXRlJztcblxuZXhwb3J0IGludGVyZmFjZSBTdGF0ZUluaXRpYWxpemVyIHtcbiAgaW5pdGlhbGl6ZVN0YXRlKHN0YXRlOiBTdGF0ZSk6IFN0YXRlO1xufVxuXG5leHBvcnQgY29uc3QgTkdTU01fU1RBVEVfSU5JVElBTElaRVIgPSBuZXcgSW5qZWN0aW9uVG9rZW48U3RhdGVJbml0aWFsaXplcj4oJ05HU1NNX1NUQVRFX0lOSVRJQUxJWkVSJyk7XG4iXX0=
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RhdGUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9uZ3NzbS1zdG9yZS9zcmMvbGliL3N0YXRlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiIiLCJzb3VyY2VzQ29udGVudCI6WyJleHBvcnQgaW50ZXJmYWNlIFN0YXRlIHtcbiAgW2tleTogc3RyaW5nXTogYW55O1xufVxuIl19
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { Inject, Injectable, Optional } from '@angular/core';
|
|
2
|
+
import { BehaviorSubject } from 'rxjs';
|
|
3
|
+
import update from 'immutability-helper';
|
|
4
|
+
import { NGSSM_REDUCER } from './reducer';
|
|
5
|
+
import { NGSSM_EFFECT } from './effect';
|
|
6
|
+
import { NGSSM_STATE_INITIALIZER } from './state-initializer';
|
|
7
|
+
import * as i0 from "@angular/core";
|
|
8
|
+
import * as i1 from "ngssm-toolkit";
|
|
9
|
+
const featureStateSpecifications = [];
|
|
10
|
+
export const NgSsmFeatureState = (specification) => {
|
|
11
|
+
return (target) => {
|
|
12
|
+
featureStateSpecifications.push(specification);
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export class Store {
|
|
16
|
+
constructor(logger, reducers, effects, initializers) {
|
|
17
|
+
this.logger = logger;
|
|
18
|
+
this._state$ = new BehaviorSubject({});
|
|
19
|
+
this.actionQueue = [];
|
|
20
|
+
this.reducersPerActionType = new Map();
|
|
21
|
+
this.effectsPerActionType = new Map();
|
|
22
|
+
this.logger.information('[Store] ---> state initialization...');
|
|
23
|
+
let state = this._state$.getValue();
|
|
24
|
+
state = featureStateSpecifications.reduce((p, c) => update(p, { [c.featureStateKey]: { $set: c.initialState } }), state);
|
|
25
|
+
(initializers ?? []).forEach((initializer) => {
|
|
26
|
+
this.logger.information('[Store] ------> calling initializer', initializer);
|
|
27
|
+
state = initializer.initializeState(state);
|
|
28
|
+
});
|
|
29
|
+
this._state$.next(state);
|
|
30
|
+
this.logger.information(`[Store] ---> initialization of ${(reducers ?? []).length} reducers...`);
|
|
31
|
+
(reducers ?? []).forEach((reducer) => {
|
|
32
|
+
this.logger.information('[Store] ------> initialization of ', reducer);
|
|
33
|
+
reducer.processedActions.forEach((processedAction) => {
|
|
34
|
+
const storeReducers = this.reducersPerActionType.get(processedAction) ?? [];
|
|
35
|
+
if (storeReducers.length === 0) {
|
|
36
|
+
this.reducersPerActionType.set(processedAction, storeReducers);
|
|
37
|
+
}
|
|
38
|
+
storeReducers.push(reducer);
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
this.logger.information(`[Store] ---> initialization of ${(effects ?? []).length} effects...`);
|
|
42
|
+
(effects ?? []).forEach((effect) => {
|
|
43
|
+
this.logger.information('[Store] ------> initialization of ', effect);
|
|
44
|
+
effect.processedActions.forEach((processedAction) => {
|
|
45
|
+
const storedEffects = this.effectsPerActionType.get(processedAction) ?? [];
|
|
46
|
+
if (storedEffects.length === 0) {
|
|
47
|
+
this.effectsPerActionType.set(processedAction, storedEffects);
|
|
48
|
+
}
|
|
49
|
+
storedEffects.push(effect);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
get state$() {
|
|
54
|
+
return this._state$.asObservable();
|
|
55
|
+
}
|
|
56
|
+
dispatchAction(action) {
|
|
57
|
+
this.actionQueue.push(action);
|
|
58
|
+
this.logger.debug(`Action of type '${action.type}' added to the queue => ${this.actionQueue.length} pending actions`, action);
|
|
59
|
+
setTimeout(() => this.processNextAction());
|
|
60
|
+
}
|
|
61
|
+
dispatchActionType(type) {
|
|
62
|
+
this.dispatchAction({ type });
|
|
63
|
+
}
|
|
64
|
+
processNextAction() {
|
|
65
|
+
const nextAction = this.actionQueue.shift();
|
|
66
|
+
if (!nextAction) {
|
|
67
|
+
this.logger.debug('[processNextAction] No action to process');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.logger.information(`[processNextAction] Start processing action '${nextAction.type}...`, nextAction);
|
|
71
|
+
try {
|
|
72
|
+
const reducers = this.reducersPerActionType.get(nextAction.type) ?? [];
|
|
73
|
+
this.logger.debug(`[Store] ${reducers.length} reducers found to process the action ${nextAction.type}`, reducers);
|
|
74
|
+
const currentState = this._state$.getValue();
|
|
75
|
+
const updatedState = reducers.reduce((p, c) => c.updateState(p, nextAction), currentState);
|
|
76
|
+
if (updatedState !== currentState) {
|
|
77
|
+
this._state$.next(updatedState);
|
|
78
|
+
}
|
|
79
|
+
const effects = this.effectsPerActionType.get(nextAction.type) ?? [];
|
|
80
|
+
this.logger.debug(`[Store] ${effects.length} effects found to process the action ${nextAction.type}`, effects);
|
|
81
|
+
effects.forEach((effect) => {
|
|
82
|
+
try {
|
|
83
|
+
effect.processAction(this, updatedState, nextAction);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
this.logger.error(`Unable to process action ${nextAction.type} by effect ${effect}`, {
|
|
87
|
+
error,
|
|
88
|
+
action: nextAction,
|
|
89
|
+
processor: effect
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
this.logger.error(`Error when processing action ${nextAction.type}`, {
|
|
96
|
+
error,
|
|
97
|
+
action: nextAction
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
finally {
|
|
101
|
+
this.logger.information(`[processNextAction] action '${nextAction.type} processed.`, nextAction);
|
|
102
|
+
// Should not be useful.But, just in case.
|
|
103
|
+
setTimeout(() => this.processNextAction());
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
Store.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: Store, deps: [{ token: i1.Logger }, { token: NGSSM_REDUCER, optional: true }, { token: NGSSM_EFFECT, optional: true }, { token: NGSSM_STATE_INITIALIZER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
108
|
+
Store.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: Store, providedIn: 'root' });
|
|
109
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: Store, decorators: [{
|
|
110
|
+
type: Injectable,
|
|
111
|
+
args: [{
|
|
112
|
+
providedIn: 'root'
|
|
113
|
+
}]
|
|
114
|
+
}], ctorParameters: function () { return [{ type: i1.Logger }, { type: undefined, decorators: [{
|
|
115
|
+
type: Inject,
|
|
116
|
+
args: [NGSSM_REDUCER]
|
|
117
|
+
}, {
|
|
118
|
+
type: Optional
|
|
119
|
+
}] }, { type: undefined, decorators: [{
|
|
120
|
+
type: Inject,
|
|
121
|
+
args: [NGSSM_EFFECT]
|
|
122
|
+
}, {
|
|
123
|
+
type: Optional
|
|
124
|
+
}] }, { type: undefined, decorators: [{
|
|
125
|
+
type: Inject,
|
|
126
|
+
args: [NGSSM_STATE_INITIALIZER]
|
|
127
|
+
}, {
|
|
128
|
+
type: Optional
|
|
129
|
+
}] }]; } });
|
|
130
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic3RvcmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9wcm9qZWN0cy9uZ3NzbS1zdG9yZS9zcmMvbGliL3N0b3JlLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLE9BQU8sRUFBRSxNQUFNLEVBQUUsVUFBVSxFQUFFLFFBQVEsRUFBRSxNQUFNLGVBQWUsQ0FBQztBQUM3RCxPQUFPLEVBQUUsZUFBZSxFQUFjLE1BQU0sTUFBTSxDQUFDO0FBRW5ELE9BQU8sTUFBTSxNQUFNLHFCQUFxQixDQUFDO0FBT3pDLE9BQU8sRUFBRSxhQUFhLEVBQVcsTUFBTSxXQUFXLENBQUM7QUFDbkQsT0FBTyxFQUFVLFlBQVksRUFBRSxNQUFNLFVBQVUsQ0FBQztBQUNoRCxPQUFPLEVBQUUsdUJBQXVCLEVBQW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VxuICB9XG59XG4iXX0=
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generated bundle index. Do not edit.
|
|
3
|
+
*/
|
|
4
|
+
export * from './public-api';
|
|
5
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmdzc20tc3RvcmUuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi9wcm9qZWN0cy9uZ3NzbS1zdG9yZS9zcmMvbmdzc20tc3RvcmUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7O0dBRUc7QUFFSCxjQUFjLGNBQWMsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qKlxuICogR2VuZXJhdGVkIGJ1bmRsZSBpbmRleC4gRG8gbm90IGVkaXQuXG4gKi9cblxuZXhwb3J0ICogZnJvbSAnLi9wdWJsaWMtYXBpJztcbiJdfQ==
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Public API Surface of ngssm-store
|
|
3
|
+
*/
|
|
4
|
+
export * from './lib/ngssm-store.module';
|
|
5
|
+
export * from './lib/store';
|
|
6
|
+
export * from './lib/state';
|
|
7
|
+
export * from './lib/action';
|
|
8
|
+
export * from './lib/reducer';
|
|
9
|
+
export * from './lib/effect';
|
|
10
|
+
export * from './lib/feature-state-specification';
|
|
11
|
+
export * from './lib/ngssm-component';
|
|
12
|
+
export * from './lib/state-initializer';
|
|
13
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHVibGljLWFwaS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3Byb2plY3RzL25nc3NtLXN0b3JlL3NyYy9wdWJsaWMtYXBpLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOztHQUVHO0FBRUgsY0FBYywwQkFBMEIsQ0FBQztBQUV6QyxjQUFjLGFBQWEsQ0FBQztBQUM1QixjQUFjLGFBQWEsQ0FBQztBQUM1QixjQUFjLGNBQWMsQ0FBQztBQUM3QixjQUFjLGVBQWUsQ0FBQztBQUM5QixjQUFjLGNBQWMsQ0FBQztBQUM3QixjQUFjLG1DQUFtQyxDQUFDO0FBQ2xELGNBQWMsdUJBQXVCLENBQUM7QUFDdEMsY0FBYyx5QkFBeUIsQ0FBQyIsInNvdXJjZXNDb250ZW50IjpbIi8qXG4gKiBQdWJsaWMgQVBJIFN1cmZhY2Ugb2Ygbmdzc20tc3RvcmVcbiAqL1xuXG5leHBvcnQgKiBmcm9tICcuL2xpYi9uZ3NzbS1zdG9yZS5tb2R1bGUnO1xuXG5leHBvcnQgKiBmcm9tICcuL2xpYi9zdG9yZSc7XG5leHBvcnQgKiBmcm9tICcuL2xpYi9zdGF0ZSc7XG5leHBvcnQgKiBmcm9tICcuL2xpYi9hY3Rpb24nO1xuZXhwb3J0ICogZnJvbSAnLi9saWIvcmVkdWNlcic7XG5leHBvcnQgKiBmcm9tICcuL2xpYi9lZmZlY3QnO1xuZXhwb3J0ICogZnJvbSAnLi9saWIvZmVhdHVyZS1zdGF0ZS1zcGVjaWZpY2F0aW9uJztcbmV4cG9ydCAqIGZyb20gJy4vbGliL25nc3NtLWNvbXBvbmVudCc7XG5leHBvcnQgKiBmcm9tICcuL2xpYi9zdGF0ZS1pbml0aWFsaXplcic7XG4iXX0=
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { NgModule, InjectionToken, Injectable, Inject, Optional, Component } from '@angular/core';
|
|
3
|
+
import { BehaviorSubject, Subject, map, distinctUntilChanged, takeUntil } from 'rxjs';
|
|
4
|
+
import update from 'immutability-helper';
|
|
5
|
+
import * as i1 from 'ngssm-toolkit';
|
|
6
|
+
|
|
7
|
+
class NgssmStoreModule {
|
|
8
|
+
}
|
|
9
|
+
NgssmStoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: NgssmStoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
10
|
+
NgssmStoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.2", ngImport: i0, type: NgssmStoreModule });
|
|
11
|
+
NgssmStoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: NgssmStoreModule });
|
|
12
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: NgssmStoreModule, decorators: [{
|
|
13
|
+
type: NgModule,
|
|
14
|
+
args: [{
|
|
15
|
+
declarations: [],
|
|
16
|
+
imports: [],
|
|
17
|
+
exports: []
|
|
18
|
+
}]
|
|
19
|
+
}] });
|
|
20
|
+
|
|
21
|
+
const NGSSM_REDUCER = new InjectionToken('NGSSM_REDUCER');
|
|
22
|
+
|
|
23
|
+
const NGSSM_EFFECT = new InjectionToken('NGSSM_EFFECT');
|
|
24
|
+
|
|
25
|
+
const NGSSM_STATE_INITIALIZER = new InjectionToken('NGSSM_STATE_INITIALIZER');
|
|
26
|
+
|
|
27
|
+
const featureStateSpecifications = [];
|
|
28
|
+
const NgSsmFeatureState = (specification) => {
|
|
29
|
+
return (target) => {
|
|
30
|
+
featureStateSpecifications.push(specification);
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
class Store {
|
|
34
|
+
constructor(logger, reducers, effects, initializers) {
|
|
35
|
+
this.logger = logger;
|
|
36
|
+
this._state$ = new BehaviorSubject({});
|
|
37
|
+
this.actionQueue = [];
|
|
38
|
+
this.reducersPerActionType = new Map();
|
|
39
|
+
this.effectsPerActionType = new Map();
|
|
40
|
+
this.logger.information('[Store] ---> state initialization...');
|
|
41
|
+
let state = this._state$.getValue();
|
|
42
|
+
state = featureStateSpecifications.reduce((p, c) => update(p, { [c.featureStateKey]: { $set: c.initialState } }), state);
|
|
43
|
+
(initializers !== null && initializers !== void 0 ? initializers : []).forEach((initializer) => {
|
|
44
|
+
this.logger.information('[Store] ------> calling initializer', initializer);
|
|
45
|
+
state = initializer.initializeState(state);
|
|
46
|
+
});
|
|
47
|
+
this._state$.next(state);
|
|
48
|
+
this.logger.information(`[Store] ---> initialization of ${(reducers !== null && reducers !== void 0 ? reducers : []).length} reducers...`);
|
|
49
|
+
(reducers !== null && reducers !== void 0 ? reducers : []).forEach((reducer) => {
|
|
50
|
+
this.logger.information('[Store] ------> initialization of ', reducer);
|
|
51
|
+
reducer.processedActions.forEach((processedAction) => {
|
|
52
|
+
var _a;
|
|
53
|
+
const storeReducers = (_a = this.reducersPerActionType.get(processedAction)) !== null && _a !== void 0 ? _a : [];
|
|
54
|
+
if (storeReducers.length === 0) {
|
|
55
|
+
this.reducersPerActionType.set(processedAction, storeReducers);
|
|
56
|
+
}
|
|
57
|
+
storeReducers.push(reducer);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
this.logger.information(`[Store] ---> initialization of ${(effects !== null && effects !== void 0 ? effects : []).length} effects...`);
|
|
61
|
+
(effects !== null && effects !== void 0 ? effects : []).forEach((effect) => {
|
|
62
|
+
this.logger.information('[Store] ------> initialization of ', effect);
|
|
63
|
+
effect.processedActions.forEach((processedAction) => {
|
|
64
|
+
var _a;
|
|
65
|
+
const storedEffects = (_a = this.effectsPerActionType.get(processedAction)) !== null && _a !== void 0 ? _a : [];
|
|
66
|
+
if (storedEffects.length === 0) {
|
|
67
|
+
this.effectsPerActionType.set(processedAction, storedEffects);
|
|
68
|
+
}
|
|
69
|
+
storedEffects.push(effect);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
get state$() {
|
|
74
|
+
return this._state$.asObservable();
|
|
75
|
+
}
|
|
76
|
+
dispatchAction(action) {
|
|
77
|
+
this.actionQueue.push(action);
|
|
78
|
+
this.logger.debug(`Action of type '${action.type}' added to the queue => ${this.actionQueue.length} pending actions`, action);
|
|
79
|
+
setTimeout(() => this.processNextAction());
|
|
80
|
+
}
|
|
81
|
+
dispatchActionType(type) {
|
|
82
|
+
this.dispatchAction({ type });
|
|
83
|
+
}
|
|
84
|
+
processNextAction() {
|
|
85
|
+
var _a, _b;
|
|
86
|
+
const nextAction = this.actionQueue.shift();
|
|
87
|
+
if (!nextAction) {
|
|
88
|
+
this.logger.debug('[processNextAction] No action to process');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
this.logger.information(`[processNextAction] Start processing action '${nextAction.type}...`, nextAction);
|
|
92
|
+
try {
|
|
93
|
+
const reducers = (_a = this.reducersPerActionType.get(nextAction.type)) !== null && _a !== void 0 ? _a : [];
|
|
94
|
+
this.logger.debug(`[Store] ${reducers.length} reducers found to process the action ${nextAction.type}`, reducers);
|
|
95
|
+
const currentState = this._state$.getValue();
|
|
96
|
+
const updatedState = reducers.reduce((p, c) => c.updateState(p, nextAction), currentState);
|
|
97
|
+
if (updatedState !== currentState) {
|
|
98
|
+
this._state$.next(updatedState);
|
|
99
|
+
}
|
|
100
|
+
const effects = (_b = this.effectsPerActionType.get(nextAction.type)) !== null && _b !== void 0 ? _b : [];
|
|
101
|
+
this.logger.debug(`[Store] ${effects.length} effects found to process the action ${nextAction.type}`, effects);
|
|
102
|
+
effects.forEach((effect) => {
|
|
103
|
+
try {
|
|
104
|
+
effect.processAction(this, updatedState, nextAction);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
this.logger.error(`Unable to process action ${nextAction.type} by effect ${effect}`, {
|
|
108
|
+
error,
|
|
109
|
+
action: nextAction,
|
|
110
|
+
processor: effect
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
catch (error) {
|
|
116
|
+
this.logger.error(`Error when processing action ${nextAction.type}`, {
|
|
117
|
+
error,
|
|
118
|
+
action: nextAction
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
this.logger.information(`[processNextAction] action '${nextAction.type} processed.`, nextAction);
|
|
123
|
+
// Should not be useful.But, just in case.
|
|
124
|
+
setTimeout(() => this.processNextAction());
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
Store.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: Store, deps: [{ token: i1.Logger }, { token: NGSSM_REDUCER, optional: true }, { token: NGSSM_EFFECT, optional: true }, { token: NGSSM_STATE_INITIALIZER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
129
|
+
Store.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: Store, providedIn: 'root' });
|
|
130
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: Store, decorators: [{
|
|
131
|
+
type: Injectable,
|
|
132
|
+
args: [{
|
|
133
|
+
providedIn: 'root'
|
|
134
|
+
}]
|
|
135
|
+
}], ctorParameters: function () {
|
|
136
|
+
return [{ type: i1.Logger }, { type: undefined, decorators: [{
|
|
137
|
+
type: Inject,
|
|
138
|
+
args: [NGSSM_REDUCER]
|
|
139
|
+
}, {
|
|
140
|
+
type: Optional
|
|
141
|
+
}] }, { type: undefined, decorators: [{
|
|
142
|
+
type: Inject,
|
|
143
|
+
args: [NGSSM_EFFECT]
|
|
144
|
+
}, {
|
|
145
|
+
type: Optional
|
|
146
|
+
}] }, { type: undefined, decorators: [{
|
|
147
|
+
type: Inject,
|
|
148
|
+
args: [NGSSM_STATE_INITIALIZER]
|
|
149
|
+
}, {
|
|
150
|
+
type: Optional
|
|
151
|
+
}] }];
|
|
152
|
+
} });
|
|
153
|
+
|
|
154
|
+
class NgSsmComponent {
|
|
155
|
+
constructor(store) {
|
|
156
|
+
this.store = store;
|
|
157
|
+
this._unsubscribeAll$ = new Subject();
|
|
158
|
+
}
|
|
159
|
+
get unsubscribeAll$() {
|
|
160
|
+
return this._unsubscribeAll$.asObservable();
|
|
161
|
+
}
|
|
162
|
+
ngOnDestroy() {
|
|
163
|
+
this._unsubscribeAll$.next();
|
|
164
|
+
this._unsubscribeAll$.complete();
|
|
165
|
+
}
|
|
166
|
+
watch(selector) {
|
|
167
|
+
return this.store.state$.pipe(map((state) => selector(state)), distinctUntilChanged(), takeUntil(this.unsubscribeAll$));
|
|
168
|
+
}
|
|
169
|
+
dispatchAction(action) {
|
|
170
|
+
this.store.dispatchAction(action);
|
|
171
|
+
}
|
|
172
|
+
dispatchActionType(actionType) {
|
|
173
|
+
this.store.dispatchActionType(actionType);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
NgSsmComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: NgSsmComponent, deps: [{ token: Store }], target: i0.ɵɵFactoryTarget.Component });
|
|
177
|
+
NgSsmComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.2", type: NgSsmComponent, selector: "ng-component", ngImport: i0, template: '', isInline: true });
|
|
178
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: NgSsmComponent, decorators: [{
|
|
179
|
+
type: Component,
|
|
180
|
+
args: [{
|
|
181
|
+
template: ''
|
|
182
|
+
}]
|
|
183
|
+
}], ctorParameters: function () { return [{ type: Store }]; } });
|
|
184
|
+
|
|
185
|
+
/*
|
|
186
|
+
* Public API Surface of ngssm-store
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Generated bundle index. Do not edit.
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
export { NGSSM_EFFECT, NGSSM_REDUCER, NGSSM_STATE_INITIALIZER, NgSsmComponent, NgSsmFeatureState, NgssmStoreModule, Store };
|
|
194
|
+
//# sourceMappingURL=ngssm-store.mjs.map
|
|
@@ -0,0 +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;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,G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A,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;;;;"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { NgModule, InjectionToken, Injectable, Inject, Optional, Component } from '@angular/core';
|
|
3
|
+
import { BehaviorSubject, Subject, map, distinctUntilChanged, takeUntil } from 'rxjs';
|
|
4
|
+
import update from 'immutability-helper';
|
|
5
|
+
import * as i1 from 'ngssm-toolkit';
|
|
6
|
+
|
|
7
|
+
class NgssmStoreModule {
|
|
8
|
+
}
|
|
9
|
+
NgssmStoreModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: NgssmStoreModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
|
|
10
|
+
NgssmStoreModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "14.2.2", ngImport: i0, type: NgssmStoreModule });
|
|
11
|
+
NgssmStoreModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: NgssmStoreModule });
|
|
12
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: NgssmStoreModule, decorators: [{
|
|
13
|
+
type: NgModule,
|
|
14
|
+
args: [{
|
|
15
|
+
declarations: [],
|
|
16
|
+
imports: [],
|
|
17
|
+
exports: []
|
|
18
|
+
}]
|
|
19
|
+
}] });
|
|
20
|
+
|
|
21
|
+
const NGSSM_REDUCER = new InjectionToken('NGSSM_REDUCER');
|
|
22
|
+
|
|
23
|
+
const NGSSM_EFFECT = new InjectionToken('NGSSM_EFFECT');
|
|
24
|
+
|
|
25
|
+
const NGSSM_STATE_INITIALIZER = new InjectionToken('NGSSM_STATE_INITIALIZER');
|
|
26
|
+
|
|
27
|
+
const featureStateSpecifications = [];
|
|
28
|
+
const NgSsmFeatureState = (specification) => {
|
|
29
|
+
return (target) => {
|
|
30
|
+
featureStateSpecifications.push(specification);
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
class Store {
|
|
34
|
+
constructor(logger, reducers, effects, initializers) {
|
|
35
|
+
this.logger = logger;
|
|
36
|
+
this._state$ = new BehaviorSubject({});
|
|
37
|
+
this.actionQueue = [];
|
|
38
|
+
this.reducersPerActionType = new Map();
|
|
39
|
+
this.effectsPerActionType = new Map();
|
|
40
|
+
this.logger.information('[Store] ---> state initialization...');
|
|
41
|
+
let state = this._state$.getValue();
|
|
42
|
+
state = featureStateSpecifications.reduce((p, c) => update(p, { [c.featureStateKey]: { $set: c.initialState } }), state);
|
|
43
|
+
(initializers ?? []).forEach((initializer) => {
|
|
44
|
+
this.logger.information('[Store] ------> calling initializer', initializer);
|
|
45
|
+
state = initializer.initializeState(state);
|
|
46
|
+
});
|
|
47
|
+
this._state$.next(state);
|
|
48
|
+
this.logger.information(`[Store] ---> initialization of ${(reducers ?? []).length} reducers...`);
|
|
49
|
+
(reducers ?? []).forEach((reducer) => {
|
|
50
|
+
this.logger.information('[Store] ------> initialization of ', reducer);
|
|
51
|
+
reducer.processedActions.forEach((processedAction) => {
|
|
52
|
+
const storeReducers = this.reducersPerActionType.get(processedAction) ?? [];
|
|
53
|
+
if (storeReducers.length === 0) {
|
|
54
|
+
this.reducersPerActionType.set(processedAction, storeReducers);
|
|
55
|
+
}
|
|
56
|
+
storeReducers.push(reducer);
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
this.logger.information(`[Store] ---> initialization of ${(effects ?? []).length} effects...`);
|
|
60
|
+
(effects ?? []).forEach((effect) => {
|
|
61
|
+
this.logger.information('[Store] ------> initialization of ', effect);
|
|
62
|
+
effect.processedActions.forEach((processedAction) => {
|
|
63
|
+
const storedEffects = this.effectsPerActionType.get(processedAction) ?? [];
|
|
64
|
+
if (storedEffects.length === 0) {
|
|
65
|
+
this.effectsPerActionType.set(processedAction, storedEffects);
|
|
66
|
+
}
|
|
67
|
+
storedEffects.push(effect);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
get state$() {
|
|
72
|
+
return this._state$.asObservable();
|
|
73
|
+
}
|
|
74
|
+
dispatchAction(action) {
|
|
75
|
+
this.actionQueue.push(action);
|
|
76
|
+
this.logger.debug(`Action of type '${action.type}' added to the queue => ${this.actionQueue.length} pending actions`, action);
|
|
77
|
+
setTimeout(() => this.processNextAction());
|
|
78
|
+
}
|
|
79
|
+
dispatchActionType(type) {
|
|
80
|
+
this.dispatchAction({ type });
|
|
81
|
+
}
|
|
82
|
+
processNextAction() {
|
|
83
|
+
const nextAction = this.actionQueue.shift();
|
|
84
|
+
if (!nextAction) {
|
|
85
|
+
this.logger.debug('[processNextAction] No action to process');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
this.logger.information(`[processNextAction] Start processing action '${nextAction.type}...`, nextAction);
|
|
89
|
+
try {
|
|
90
|
+
const reducers = this.reducersPerActionType.get(nextAction.type) ?? [];
|
|
91
|
+
this.logger.debug(`[Store] ${reducers.length} reducers found to process the action ${nextAction.type}`, reducers);
|
|
92
|
+
const currentState = this._state$.getValue();
|
|
93
|
+
const updatedState = reducers.reduce((p, c) => c.updateState(p, nextAction), currentState);
|
|
94
|
+
if (updatedState !== currentState) {
|
|
95
|
+
this._state$.next(updatedState);
|
|
96
|
+
}
|
|
97
|
+
const effects = this.effectsPerActionType.get(nextAction.type) ?? [];
|
|
98
|
+
this.logger.debug(`[Store] ${effects.length} effects found to process the action ${nextAction.type}`, effects);
|
|
99
|
+
effects.forEach((effect) => {
|
|
100
|
+
try {
|
|
101
|
+
effect.processAction(this, updatedState, nextAction);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
this.logger.error(`Unable to process action ${nextAction.type} by effect ${effect}`, {
|
|
105
|
+
error,
|
|
106
|
+
action: nextAction,
|
|
107
|
+
processor: effect
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
this.logger.error(`Error when processing action ${nextAction.type}`, {
|
|
114
|
+
error,
|
|
115
|
+
action: nextAction
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
finally {
|
|
119
|
+
this.logger.information(`[processNextAction] action '${nextAction.type} processed.`, nextAction);
|
|
120
|
+
// Should not be useful.But, just in case.
|
|
121
|
+
setTimeout(() => this.processNextAction());
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
Store.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: Store, deps: [{ token: i1.Logger }, { token: NGSSM_REDUCER, optional: true }, { token: NGSSM_EFFECT, optional: true }, { token: NGSSM_STATE_INITIALIZER, optional: true }], target: i0.ɵɵFactoryTarget.Injectable });
|
|
126
|
+
Store.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: Store, providedIn: 'root' });
|
|
127
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: Store, decorators: [{
|
|
128
|
+
type: Injectable,
|
|
129
|
+
args: [{
|
|
130
|
+
providedIn: 'root'
|
|
131
|
+
}]
|
|
132
|
+
}], ctorParameters: function () { return [{ type: i1.Logger }, { type: undefined, decorators: [{
|
|
133
|
+
type: Inject,
|
|
134
|
+
args: [NGSSM_REDUCER]
|
|
135
|
+
}, {
|
|
136
|
+
type: Optional
|
|
137
|
+
}] }, { type: undefined, decorators: [{
|
|
138
|
+
type: Inject,
|
|
139
|
+
args: [NGSSM_EFFECT]
|
|
140
|
+
}, {
|
|
141
|
+
type: Optional
|
|
142
|
+
}] }, { type: undefined, decorators: [{
|
|
143
|
+
type: Inject,
|
|
144
|
+
args: [NGSSM_STATE_INITIALIZER]
|
|
145
|
+
}, {
|
|
146
|
+
type: Optional
|
|
147
|
+
}] }]; } });
|
|
148
|
+
|
|
149
|
+
class NgSsmComponent {
|
|
150
|
+
constructor(store) {
|
|
151
|
+
this.store = store;
|
|
152
|
+
this._unsubscribeAll$ = new Subject();
|
|
153
|
+
}
|
|
154
|
+
get unsubscribeAll$() {
|
|
155
|
+
return this._unsubscribeAll$.asObservable();
|
|
156
|
+
}
|
|
157
|
+
ngOnDestroy() {
|
|
158
|
+
this._unsubscribeAll$.next();
|
|
159
|
+
this._unsubscribeAll$.complete();
|
|
160
|
+
}
|
|
161
|
+
watch(selector) {
|
|
162
|
+
return this.store.state$.pipe(map((state) => selector(state)), distinctUntilChanged(), takeUntil(this.unsubscribeAll$));
|
|
163
|
+
}
|
|
164
|
+
dispatchAction(action) {
|
|
165
|
+
this.store.dispatchAction(action);
|
|
166
|
+
}
|
|
167
|
+
dispatchActionType(actionType) {
|
|
168
|
+
this.store.dispatchActionType(actionType);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
NgSsmComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: NgSsmComponent, deps: [{ token: Store }], target: i0.ɵɵFactoryTarget.Component });
|
|
172
|
+
NgSsmComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "14.2.2", type: NgSsmComponent, selector: "ng-component", ngImport: i0, template: '', isInline: true });
|
|
173
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "14.2.2", ngImport: i0, type: NgSsmComponent, decorators: [{
|
|
174
|
+
type: Component,
|
|
175
|
+
args: [{
|
|
176
|
+
template: ''
|
|
177
|
+
}]
|
|
178
|
+
}], ctorParameters: function () { return [{ type: Store }]; } });
|
|
179
|
+
|
|
180
|
+
/*
|
|
181
|
+
* Public API Surface of ngssm-store
|
|
182
|
+
*/
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Generated bundle index. Do not edit.
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
export { NGSSM_EFFECT, NGSSM_REDUCER, NGSSM_STATE_INITIALIZER, NgSsmComponent, NgSsmFeatureState, NgssmStoreModule, Store };
|
|
189
|
+
//# sourceMappingURL=ngssm-store.mjs.map
|
|
@@ -0,0 +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,aA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AA,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;AACb,iBAAA,CAAA;;;ACTD;;AAEG;;ACFH;;AAEG;;;;"}
|
package/index.d.ts
ADDED
package/lib/action.d.ts
ADDED
package/lib/effect.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
import { Action } from './action';
|
|
3
|
+
import { State } from './state';
|
|
4
|
+
import { Store } from './store';
|
|
5
|
+
export interface Effect {
|
|
6
|
+
processedActions: string[];
|
|
7
|
+
processAction(store: Store, state: State, action: Action): void;
|
|
8
|
+
}
|
|
9
|
+
export declare const NGSSM_EFFECT: InjectionToken<Effect>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { OnDestroy } from '@angular/core';
|
|
2
|
+
import { Observable } from 'rxjs';
|
|
3
|
+
import { Action } from './action';
|
|
4
|
+
import { State } from './state';
|
|
5
|
+
import { Store } from './store';
|
|
6
|
+
import * as i0 from "@angular/core";
|
|
7
|
+
export declare class NgSsmComponent implements OnDestroy {
|
|
8
|
+
protected store: Store;
|
|
9
|
+
private readonly _unsubscribeAll$;
|
|
10
|
+
constructor(store: Store);
|
|
11
|
+
protected get unsubscribeAll$(): Observable<void>;
|
|
12
|
+
ngOnDestroy(): void;
|
|
13
|
+
watch<T>(selector: (state: State) => T): Observable<T>;
|
|
14
|
+
dispatchAction(action: Action): void;
|
|
15
|
+
dispatchActionType(actionType: string): void;
|
|
16
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NgSsmComponent, never>;
|
|
17
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<NgSsmComponent, "ng-component", never, {}, {}, never, never, false>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
export declare class NgssmStoreModule {
|
|
3
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<NgssmStoreModule, never>;
|
|
4
|
+
static ɵmod: i0.ɵɵNgModuleDeclaration<NgssmStoreModule, never, never, never>;
|
|
5
|
+
static ɵinj: i0.ɵɵInjectorDeclaration<NgssmStoreModule>;
|
|
6
|
+
}
|
package/lib/reducer.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InjectionToken } from '@angular/core';
|
|
2
|
+
import { Action } from './action';
|
|
3
|
+
import { State } from './state';
|
|
4
|
+
export interface Reducer {
|
|
5
|
+
processedActions: string[];
|
|
6
|
+
updateState(state: State, action: Action): State;
|
|
7
|
+
}
|
|
8
|
+
export declare const NGSSM_REDUCER: InjectionToken<Reducer>;
|
package/lib/state.d.ts
ADDED
package/lib/store.d.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { Logger } from 'ngssm-toolkit';
|
|
3
|
+
import { FeatureStateSpecification } from './feature-state-specification';
|
|
4
|
+
import { State } from './state';
|
|
5
|
+
import { Action } from './action';
|
|
6
|
+
import { Reducer } from './reducer';
|
|
7
|
+
import { Effect } from './effect';
|
|
8
|
+
import { StateInitializer } from './state-initializer';
|
|
9
|
+
import * as i0 from "@angular/core";
|
|
10
|
+
export declare const NgSsmFeatureState: (specification: FeatureStateSpecification) => (target: object) => void;
|
|
11
|
+
export declare class Store {
|
|
12
|
+
private logger;
|
|
13
|
+
private readonly _state$;
|
|
14
|
+
private readonly actionQueue;
|
|
15
|
+
private readonly reducersPerActionType;
|
|
16
|
+
private readonly effectsPerActionType;
|
|
17
|
+
constructor(logger: Logger, reducers: Reducer[], effects: Effect[], initializers: StateInitializer[]);
|
|
18
|
+
get state$(): Observable<State>;
|
|
19
|
+
dispatchAction(action: Action): void;
|
|
20
|
+
dispatchActionType(type: string): void;
|
|
21
|
+
private processNextAction;
|
|
22
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<Store, [null, { optional: true; }, { optional: true; }, { optional: true; }]>;
|
|
23
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<Store>;
|
|
24
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ngssm-store",
|
|
3
|
+
"version": "14.0.0",
|
|
4
|
+
"description": "NgSsm - Simple state management implementation.",
|
|
5
|
+
"author": "Lion Marc",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"@angular/common": "^14.2.0",
|
|
9
|
+
"@angular/core": "^14.2.0",
|
|
10
|
+
"immutability-helper": "^3.1.1",
|
|
11
|
+
"ngssm-toolkit": "14.0.0"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"tslib": "^2.3.0"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "https://github.com/LionMarc/ng-simple-state-management",
|
|
19
|
+
"directory": "projects/ngssm-store"
|
|
20
|
+
},
|
|
21
|
+
"module": "fesm2015/ngssm-store.mjs",
|
|
22
|
+
"es2020": "fesm2020/ngssm-store.mjs",
|
|
23
|
+
"esm2020": "esm2020/ngssm-store.mjs",
|
|
24
|
+
"fesm2020": "fesm2020/ngssm-store.mjs",
|
|
25
|
+
"fesm2015": "fesm2015/ngssm-store.mjs",
|
|
26
|
+
"typings": "index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
"./package.json": {
|
|
29
|
+
"default": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./index.d.ts",
|
|
33
|
+
"esm2020": "./esm2020/ngssm-store.mjs",
|
|
34
|
+
"es2020": "./fesm2020/ngssm-store.mjs",
|
|
35
|
+
"es2015": "./fesm2015/ngssm-store.mjs",
|
|
36
|
+
"node": "./fesm2015/ngssm-store.mjs",
|
|
37
|
+
"default": "./fesm2020/ngssm-store.mjs"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"sideEffects": false
|
|
41
|
+
}
|
package/public-api.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './lib/ngssm-store.module';
|
|
2
|
+
export * from './lib/store';
|
|
3
|
+
export * from './lib/state';
|
|
4
|
+
export * from './lib/action';
|
|
5
|
+
export * from './lib/reducer';
|
|
6
|
+
export * from './lib/effect';
|
|
7
|
+
export * from './lib/feature-state-specification';
|
|
8
|
+
export * from './lib/ngssm-component';
|
|
9
|
+
export * from './lib/state-initializer';
|