ngssm-store 22.1.0 → 22.2.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 +3 -52
- package/fesm2022/ngssm-store-caching-testing.mjs +61 -126
- package/fesm2022/ngssm-store-caching-testing.mjs.map +1 -1
- package/fesm2022/ngssm-store-caching.mjs +102 -134
- package/fesm2022/ngssm-store-caching.mjs.map +1 -1
- package/fesm2022/ngssm-store-testing.mjs +36 -64
- package/fesm2022/ngssm-store-testing.mjs.map +1 -1
- package/fesm2022/ngssm-store-visibility-testing.mjs +53 -75
- package/fesm2022/ngssm-store-visibility-testing.mjs.map +1 -1
- package/fesm2022/ngssm-store-visibility.mjs +441 -244
- package/fesm2022/ngssm-store-visibility.mjs.map +1 -1
- package/fesm2022/ngssm-store.mjs +385 -488
- package/fesm2022/ngssm-store.mjs.map +1 -1
- package/package.json +1 -1
- package/types/ngssm-store-caching-testing.d.ts +35 -39
- package/types/ngssm-store-caching.d.ts +43 -55
- package/types/ngssm-store-testing.d.ts +13 -19
- package/types/ngssm-store-visibility-testing.d.ts +29 -33
- package/types/ngssm-store-visibility.d.ts +107 -95
- package/types/ngssm-store.d.ts +183 -232
package/README.md
CHANGED
|
@@ -4,13 +4,13 @@ A lightweight, production-ready state management library for Angular application
|
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
`ngssm-store` is a simple yet powerful custom implementation of the Redux pattern designed specifically for Angular. It leverages Angular's dependency injection
|
|
7
|
+
`ngssm-store` is a simple yet powerful custom implementation of the Redux pattern designed specifically for Angular. It leverages Angular's dependency injection and modern Angular signals for reactive state updates.
|
|
8
8
|
|
|
9
9
|
### Key Features
|
|
10
10
|
|
|
11
11
|
- **Centralized State Management**: Single source of truth for application state
|
|
12
12
|
- **Redux Pattern**: Actions → Reducers → State → Effects → Actions
|
|
13
|
-
- **
|
|
13
|
+
- **Signal Reactivity**: Angular Signals provide reactive state and action updates
|
|
14
14
|
- **Immutable State**: Uses `immutability-helper` to ensure state immutability
|
|
15
15
|
- **Effect System**: Side effects, async operations, and action chaining
|
|
16
16
|
- **Feature States**: Modular state management with feature-based organization
|
|
@@ -199,54 +199,11 @@ export class CounterComponent {
|
|
|
199
199
|
}
|
|
200
200
|
```
|
|
201
201
|
|
|
202
|
-
### Accessing State with Signals
|
|
203
|
-
|
|
204
|
-
Use the signal-based API for reactive components:
|
|
205
|
-
|
|
206
|
-
```typescript
|
|
207
|
-
import { createSignal } from 'ngssm-store';
|
|
208
|
-
|
|
209
|
-
@Component({
|
|
210
|
-
selector: 'app-dashboard',
|
|
211
|
-
template: `
|
|
212
|
-
<div>
|
|
213
|
-
<p>Total Users: {{ userCount() }}</p>
|
|
214
|
-
<div *ngIf="loading()">Loading...</div>
|
|
215
|
-
<ul>
|
|
216
|
-
<li *ngFor="let user of users()">{{ user.name }}</li>
|
|
217
|
-
</ul>
|
|
218
|
-
</div>`
|
|
219
|
-
})
|
|
220
|
-
export class DashboardComponent {
|
|
221
|
-
private store = inject(Store);
|
|
222
|
-
|
|
223
|
-
users = createSignal((state) => state.users?.list ?? []);
|
|
224
202
|
loading = createSignal((state) => state.users?.loading ?? false);
|
|
225
203
|
userCount = createSignal((state) => (state.users?.list ?? []).length);
|
|
226
204
|
}
|
|
227
205
|
```
|
|
228
206
|
|
|
229
|
-
### Accessing State with RxJS
|
|
230
|
-
|
|
231
|
-
For components that need RxJS integration:
|
|
232
|
-
|
|
233
|
-
```typescript
|
|
234
|
-
@Component({
|
|
235
|
-
selector: 'app-user-list',
|
|
236
|
-
template: `
|
|
237
|
-
<ul>
|
|
238
|
-
<li *ngFor="let user of users$ | async">{{ user.name }}</li>
|
|
239
|
-
</ul>`
|
|
240
|
-
})
|
|
241
|
-
export class UserListComponent {
|
|
242
|
-
private store = inject(Store);
|
|
243
|
-
|
|
244
|
-
users$ = this.store.state$.pipe(
|
|
245
|
-
map((state) => state.users?.list ?? [])
|
|
246
|
-
);
|
|
247
|
-
}
|
|
248
|
-
```
|
|
249
|
-
|
|
250
207
|
### Direct State Access
|
|
251
208
|
|
|
252
209
|
Access the current state directly:
|
|
@@ -258,8 +215,6 @@ export class MyComponent {
|
|
|
258
215
|
|
|
259
216
|
getCurrentState() {
|
|
260
217
|
const currentState = this.store.state(); // Signal access
|
|
261
|
-
// or
|
|
262
|
-
const viaObservable = this.store.state$; // Observable access
|
|
263
218
|
}
|
|
264
219
|
}
|
|
265
220
|
```
|
|
@@ -274,9 +229,6 @@ export class MyComponent {
|
|
|
274
229
|
private store = inject(Store);
|
|
275
230
|
|
|
276
231
|
lastAction = createSignal((state) => this.store.processedAction().type);
|
|
277
|
-
|
|
278
|
-
// Or with RxJS
|
|
279
|
-
lastAction$ = this.store.processedAction$.pipe(map(a => a.type));
|
|
280
232
|
}
|
|
281
233
|
```
|
|
282
234
|
|
|
@@ -435,9 +387,7 @@ export class Store {
|
|
|
435
387
|
### Store Class
|
|
436
388
|
|
|
437
389
|
- `state(): Signal<State>` - Get current state as a Signal
|
|
438
|
-
- `state$: Observable<State>` - Get state as an Observable
|
|
439
390
|
- `processedAction(): Signal<Action>` - Get last processed action as a Signal
|
|
440
|
-
- `processedAction$: Observable<Action>` - Get last processed action as Observable
|
|
441
391
|
- `dispatchAction(action: Action): void` - Dispatch an action
|
|
442
392
|
- `dispatchActionType(actionType: string): void` - Dispatch by action type string
|
|
443
393
|
|
|
@@ -449,6 +399,7 @@ export class Store {
|
|
|
449
399
|
- `provideReducers(...reducers)` - Register multiple reducers
|
|
450
400
|
- `provideEffect(effect)` - Register a single effect
|
|
451
401
|
- `provideEffects(...effects)` - Register multiple effects
|
|
402
|
+
- `EffectFunc<TActionType extends Action = Action>` - Effect function receiving state and an action; defaults to the base `Action` type
|
|
452
403
|
- `provideEffectFunc(actionType, func)` - Register an effect function
|
|
453
404
|
|
|
454
405
|
### Interfaces
|
|
@@ -1,132 +1,67 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { StoreMock } from
|
|
5
|
-
import {
|
|
6
|
-
import { TestBed } from
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.store.stateValue = updateNgssmCachingState(this.store.stateValue, {
|
|
53
|
-
caches: {
|
|
54
|
-
[cachedItemKey]: {
|
|
55
|
-
$set: {
|
|
56
|
-
status
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
return this;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Sets the value of a cached item in the StoreMock.
|
|
66
|
-
* If the key does not exist in cache, it is created with the status CachedItemStatus.notSet.
|
|
67
|
-
*
|
|
68
|
-
* @param cachedItemKey The key of the cached item.
|
|
69
|
-
* @param value The value to set.
|
|
70
|
-
* @returns The NgssmCachedItemSetter instance for chaining.
|
|
71
|
-
*/
|
|
72
|
-
setCachedItemValue(cachedItemKey, value) {
|
|
73
|
-
if (selectNgssmCachedItem(this.store.stateValue, cachedItemKey)) {
|
|
74
|
-
this.store.stateValue = updateNgssmCachingState(this.store.stateValue, {
|
|
75
|
-
caches: {
|
|
76
|
-
[cachedItemKey]: {
|
|
77
|
-
item: { $set: value }
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
this.store.stateValue = updateNgssmCachingState(this.store.stateValue, {
|
|
84
|
-
caches: {
|
|
85
|
-
[cachedItemKey]: {
|
|
86
|
-
$set: {
|
|
87
|
-
status: CachedItemStatus.notSet,
|
|
88
|
-
item: value
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
96
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.1.1", ngImport: i0, type: NgssmCachedItemSetter, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
|
|
97
|
-
static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "22.1.1", ngImport: i0, type: NgssmCachedItemSetter });
|
|
98
|
-
}
|
|
99
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.1.1", ngImport: i0, type: NgssmCachedItemSetter, decorators: [{
|
|
100
|
-
type: Injectable
|
|
101
|
-
}] });
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { Injectable, inject, makeEnvironmentProviders, provideAppInitializer } from "@angular/core";
|
|
3
|
+
import { Logger, Store } from "ngssm-store";
|
|
4
|
+
import { StoreMock } from "ngssm-store/testing";
|
|
5
|
+
import { CachedItemStatus, NgssmCachingStateSpecification, selectNgssmCachedItem, updateNgssmCachingState } from "ngssm-store/caching";
|
|
6
|
+
import { TestBed } from "@angular/core/testing";
|
|
7
|
+
var NgssmCachedItemSetter = class NgssmCachedItemSetter {
|
|
8
|
+
store = inject(Store);
|
|
9
|
+
apply(action) {
|
|
10
|
+
this.store.stateValue = updateNgssmCachingState(this.store.stateValue, { caches: { [action.cachedItemKey]: { $set: {
|
|
11
|
+
status: action.status,
|
|
12
|
+
item: action.cachedItem,
|
|
13
|
+
error: action.error
|
|
14
|
+
} } } });
|
|
15
|
+
return this;
|
|
16
|
+
}
|
|
17
|
+
setCachedItemStatus(cachedItemKey, status) {
|
|
18
|
+
if (selectNgssmCachedItem(this.store.stateValue, cachedItemKey)) this.store.stateValue = updateNgssmCachingState(this.store.stateValue, { caches: { [cachedItemKey]: { status: { $set: status } } } });
|
|
19
|
+
else this.store.stateValue = updateNgssmCachingState(this.store.stateValue, { caches: { [cachedItemKey]: { $set: { status } } } });
|
|
20
|
+
return this;
|
|
21
|
+
}
|
|
22
|
+
setCachedItemValue(cachedItemKey, value) {
|
|
23
|
+
if (selectNgssmCachedItem(this.store.stateValue, cachedItemKey)) this.store.stateValue = updateNgssmCachingState(this.store.stateValue, { caches: { [cachedItemKey]: { item: { $set: value } } } });
|
|
24
|
+
else this.store.stateValue = updateNgssmCachingState(this.store.stateValue, { caches: { [cachedItemKey]: { $set: {
|
|
25
|
+
status: CachedItemStatus.notSet,
|
|
26
|
+
item: value
|
|
27
|
+
} } } });
|
|
28
|
+
return this;
|
|
29
|
+
}
|
|
30
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
31
|
+
minVersion: "12.0.0",
|
|
32
|
+
version: "22.2.0",
|
|
33
|
+
ngImport: i0,
|
|
34
|
+
type: NgssmCachedItemSetter,
|
|
35
|
+
deps: [],
|
|
36
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
37
|
+
});
|
|
38
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
39
|
+
minVersion: "12.0.0",
|
|
40
|
+
version: "22.2.0",
|
|
41
|
+
ngImport: i0,
|
|
42
|
+
type: NgssmCachedItemSetter
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
46
|
+
minVersion: "12.0.0",
|
|
47
|
+
version: "22.2.0",
|
|
48
|
+
ngImport: i0,
|
|
49
|
+
type: NgssmCachedItemSetter,
|
|
50
|
+
decorators: [{ type: Injectable }]
|
|
51
|
+
});
|
|
102
52
|
const ngssmCachedItemSetter = () => TestBed.inject(NgssmCachedItemSetter);
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* App initializer that sets up the NgssmCaching state in the StoreMock for testing purposes.
|
|
106
|
-
* Throws an error if StoreMock is not registered.
|
|
107
|
-
*/
|
|
108
53
|
const ngssmCachingStateInitializer = () => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
...store.stateValue,
|
|
117
|
-
[NgssmCachingStateSpecification.featureStateKey]: NgssmCachingStateSpecification.initialState
|
|
118
|
-
};
|
|
54
|
+
inject(Logger).information("[ngssm-caching-testing] Initialization of state");
|
|
55
|
+
const store = inject(Store);
|
|
56
|
+
if (!(store instanceof StoreMock)) throw new Error("StoreMock is not registered.");
|
|
57
|
+
store.stateValue = {
|
|
58
|
+
...store.stateValue,
|
|
59
|
+
[NgssmCachingStateSpecification.featureStateKey]: NgssmCachingStateSpecification.initialState
|
|
60
|
+
};
|
|
119
61
|
};
|
|
120
|
-
/**
|
|
121
|
-
* Provides environment providers for NgssmCaching testing, including the state initializer.
|
|
122
|
-
*/
|
|
123
62
|
const provideNgssmCachingTesting = () => {
|
|
124
|
-
|
|
63
|
+
return makeEnvironmentProviders([provideAppInitializer(ngssmCachingStateInitializer), NgssmCachedItemSetter]);
|
|
125
64
|
};
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Generated bundle index. Do not edit.
|
|
129
|
-
*/
|
|
130
|
-
|
|
131
65
|
export { NgssmCachedItemSetter, ngssmCachedItemSetter, ngssmCachingStateInitializer, provideNgssmCachingTesting };
|
|
132
|
-
|
|
66
|
+
|
|
67
|
+
//# sourceMappingURL=ngssm-store-caching-testing.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ngssm-store-caching-testing.mjs","sources":["../../../projects/ngssm-store/caching/testing/src/ngssm-cached-item-setter.ts","../../../projects/ngssm-store/caching/testing/src/provide-ngssm-caching-testing.ts"
|
|
1
|
+
{"version":3,"file":"ngssm-store-caching-testing.mjs","names":[],"sources":["../../../projects/ngssm-store/caching/testing/src/ngssm-cached-item-setter.ts","../../../projects/ngssm-store/caching/testing/src/provide-ngssm-caching-testing.ts"],"sourcesContent":["import { inject, Injectable } from '@angular/core';\nimport { TestBed } from '@angular/core/testing';\n\nimport { Store } from 'ngssm-store';\nimport { CachedItemStatus, selectNgssmCachedItem, SetCachedItemAction, updateNgssmCachingState } from 'ngssm-store/caching';\nimport { StoreMock } from 'ngssm-store/testing';\n\n/**\n * Utility service for setting and updating cached items in the StoreMock during tests.\n * Provides methods to apply a SetCachedItemAction, set the status, or set the value of a cached item.\n */\n@Injectable()\nexport class NgssmCachedItemSetter {\n public readonly store = inject(Store) as unknown as StoreMock;\n\n /**\n * Applies a SetCachedItemAction to the StoreMock, updating the cache state.\n * @param action The SetCachedItemAction to apply.\n * @returns The NgssmCachedItemSetter instance for chaining.\n */\n public apply<T = unknown>(action: SetCachedItemAction<T>): NgssmCachedItemSetter {\n this.store.stateValue = updateNgssmCachingState(this.store.stateValue, {\n caches: {\n [action.cachedItemKey]: {\n $set: {\n status: action.status,\n item: action.cachedItem,\n error: action.error\n }\n }\n }\n });\n\n return this;\n }\n\n /**\n * Sets the status of a cached item in the StoreMock.\n * If the key does not exist in cache, it is created with an undefined value.\n *\n * @param cachedItemKey The key of the cached item.\n * @param status The new status to set.\n * @returns The NgssmCachedItemSetter instance for chaining.\n */\n public setCachedItemStatus(cachedItemKey: string, status: CachedItemStatus): NgssmCachedItemSetter {\n if (selectNgssmCachedItem(this.store.stateValue, cachedItemKey)) {\n this.store.stateValue = updateNgssmCachingState(this.store.stateValue, {\n caches: {\n [cachedItemKey]: {\n status: { $set: status }\n }\n }\n });\n } else {\n this.store.stateValue = updateNgssmCachingState(this.store.stateValue, {\n caches: {\n [cachedItemKey]: {\n $set: {\n status\n }\n }\n }\n });\n }\n\n return this;\n }\n\n /**\n * Sets the value of a cached item in the StoreMock.\n * If the key does not exist in cache, it is created with the status CachedItemStatus.notSet.\n *\n * @param cachedItemKey The key of the cached item.\n * @param value The value to set.\n * @returns The NgssmCachedItemSetter instance for chaining.\n */\n public setCachedItemValue<T>(cachedItemKey: string, value?: T): NgssmCachedItemSetter {\n if (selectNgssmCachedItem(this.store.stateValue, cachedItemKey)) {\n this.store.stateValue = updateNgssmCachingState(this.store.stateValue, {\n caches: {\n [cachedItemKey]: {\n item: { $set: value }\n }\n }\n });\n } else {\n this.store.stateValue = updateNgssmCachingState(this.store.stateValue, {\n caches: {\n [cachedItemKey]: {\n $set: {\n status: CachedItemStatus.notSet,\n item: value\n }\n }\n }\n });\n }\n\n return this;\n }\n}\n\nexport const ngssmCachedItemSetter = () => TestBed.inject(NgssmCachedItemSetter);\n","import { EnvironmentProviders, inject, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';\n\nimport { Logger, Store } from 'ngssm-store';\nimport { StoreMock } from 'ngssm-store/testing';\nimport { NgssmCachingStateSpecification } from 'ngssm-store/caching';\n\nimport { NgssmCachedItemSetter } from './ngssm-cached-item-setter';\n\n/**\n * App initializer that sets up the NgssmCaching state in the StoreMock for testing purposes.\n * Throws an error if StoreMock is not registered.\n */\nexport const ngssmCachingStateInitializer = () => {\n const logger = inject(Logger);\n logger.information('[ngssm-caching-testing] Initialization of state');\n const store = inject(Store);\n if (!(store instanceof StoreMock)) {\n throw new Error('StoreMock is not registered.');\n }\n\n store.stateValue = {\n ...store.stateValue,\n [NgssmCachingStateSpecification.featureStateKey]: NgssmCachingStateSpecification.initialState\n };\n};\n\n/**\n * Provides environment providers for NgssmCaching testing, including the state initializer.\n */\nexport const provideNgssmCachingTesting = (): EnvironmentProviders => {\n return makeEnvironmentProviders([provideAppInitializer(ngssmCachingStateInitializer), NgssmCachedItemSetter]);\n};\n"],"mappings":";;;;;;AAYA,IAAa,wBAAb,MAAa,sBAAqB;CAChB,QAAQ,OAAO,KAAK;CAO7B,MAAmB,QAA8B;EACtD,KAAK,MAAM,aAAa,wBAAwB,KAAK,MAAM,YAAY,EACrE,QAAQ,GACL,OAAO,gBAAgB,EACtB,MAAM;GACJ,QAAQ,OAAO;GACf,MAAM,OAAO;GACb,OAAO,OAAO;EACf,EACF,EACF,EACF,CAAA;EAED,OAAO;CACT;CAUO,oBAAoB,eAAuB,QAAwB;EACxE,IAAI,sBAAsB,KAAK,MAAM,YAAY,aAAa,GAC5D,KAAK,MAAM,aAAa,wBAAwB,KAAK,MAAM,YAAY,EACrE,QAAQ,GACL,gBAAgB,EACf,QAAQ,EAAE,MAAM,OAAM,EACvB,EACF,EACF,CAAA;OAED,KAAK,MAAM,aAAa,wBAAwB,KAAK,MAAM,YAAY,EACrE,QAAQ,GACL,gBAAgB,EACf,MAAM,EACJ,OACD,EACF,EACF,EACF,CAAA;EAGH,OAAO;CACT;CAUO,mBAAsB,eAAuB,OAAS;EAC3D,IAAI,sBAAsB,KAAK,MAAM,YAAY,aAAa,GAC5D,KAAK,MAAM,aAAa,wBAAwB,KAAK,MAAM,YAAY,EACrE,QAAQ,GACL,gBAAgB,EACf,MAAM,EAAE,MAAM,MAAK,EACpB,EACF,EACF,CAAA;OAED,KAAK,MAAM,aAAa,wBAAwB,KAAK,MAAM,YAAY,EACrE,QAAQ,GACL,gBAAgB,EACf,MAAM;GACJ,QAAQ,iBAAiB;GACzB,MAAM;EACP,EACF,EACF,EACF,CAAA;EAGH,OAAO;CACT;CAvFW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAqB,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAArB,OAAA,QAAA,GAAA,sBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;CAAqB,CAAA;;AAArB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAqB,YAAA,CAAA,EADjC,MAAA,WAAA,CAAA;;AA2FD,MAAa,8BAA8B,QAAQ,OAAO,qBAAqB;AC1F/E,MAAa,qCAAoC;CAE/C,AADe,OAAO,MACtB,CAAA,CAAO,YAAY,iDAAiD;CACpE,MAAM,QAAQ,OAAO,KAAK;CAC1B,IAAI,EAAE,iBAAiB,YACrB,MAAM,IAAI,MAAM,8BAA8B;CAGhD,MAAM,aAAa;EACjB,GAAG,MAAM;GACR,+BAA+B,kBAAkB,+BAA+B;CAClF;AACH;AAKA,MAAa,mCAAwD;CACnE,OAAO,yBAAyB,CAAC,sBAAsB,4BAA4B,GAAG,qBAAqB,CAAC;AAC9G"}
|
|
@@ -1,147 +1,115 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import { Injectable,
|
|
3
|
-
import { NgSsmFeatureState,
|
|
4
|
-
import { __decorate } from
|
|
5
|
-
import update from
|
|
6
|
-
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { Injectable, computed, inject, makeEnvironmentProviders } from "@angular/core";
|
|
3
|
+
import { NgSsmFeatureState, Store, provideReducers } from "ngssm-store";
|
|
4
|
+
import { __decorate } from "tslib";
|
|
5
|
+
import update from "immutability-helper";
|
|
7
6
|
var NgssmCachingActionType;
|
|
8
|
-
(function
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
(function(NgssmCachingActionType) {
|
|
8
|
+
NgssmCachingActionType["setCachedItem"] = "[NgssmCachingActionType] setCachedItem";
|
|
9
|
+
NgssmCachingActionType["unsetCachedItem"] = "[NgssmCachingActionType] unsetCachedItem";
|
|
11
10
|
})(NgssmCachingActionType || (NgssmCachingActionType = {}));
|
|
12
|
-
|
|
13
11
|
var CachedItemStatus;
|
|
14
|
-
(function
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
(function(CachedItemStatus) {
|
|
13
|
+
CachedItemStatus["notSet"] = "Not Set";
|
|
14
|
+
CachedItemStatus["loading"] = "Loading";
|
|
15
|
+
CachedItemStatus["set"] = "Set";
|
|
16
|
+
CachedItemStatus["error"] = "Error";
|
|
19
17
|
})(CachedItemStatus || (CachedItemStatus = {}));
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
type = NgssmCachingActionType.setCachedItem;
|
|
41
|
-
constructor(cachedItemKey, cachedItem, status = CachedItemStatus.set, error) {
|
|
42
|
-
this.cachedItemKey = cachedItemKey;
|
|
43
|
-
this.cachedItem = cachedItem;
|
|
44
|
-
this.status = status;
|
|
45
|
-
this.error = error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
class UnsetCachedItemAction {
|
|
50
|
-
cachedItemKey;
|
|
51
|
-
type = NgssmCachingActionType.unsetCachedItem;
|
|
52
|
-
constructor(cachedItemKey) {
|
|
53
|
-
this.cachedItemKey = cachedItemKey;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
18
|
+
var SetCachedItemAction = class {
|
|
19
|
+
cachedItemKey;
|
|
20
|
+
cachedItem;
|
|
21
|
+
status;
|
|
22
|
+
error;
|
|
23
|
+
type = NgssmCachingActionType.setCachedItem;
|
|
24
|
+
constructor(cachedItemKey, cachedItem, status = CachedItemStatus.set, error) {
|
|
25
|
+
this.cachedItemKey = cachedItemKey;
|
|
26
|
+
this.cachedItem = cachedItem;
|
|
27
|
+
this.status = status;
|
|
28
|
+
this.error = error;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
var UnsetCachedItemAction = class {
|
|
32
|
+
cachedItemKey;
|
|
33
|
+
type = NgssmCachingActionType.unsetCachedItem;
|
|
34
|
+
constructor(cachedItemKey) {
|
|
35
|
+
this.cachedItemKey = cachedItemKey;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
57
38
|
const selectNgssmCachingState = (state) => state[NgssmCachingStateSpecification.featureStateKey];
|
|
58
|
-
const updateNgssmCachingState = (state, command) => update(state, {
|
|
59
|
-
[NgssmCachingStateSpecification.featureStateKey]: command
|
|
60
|
-
});
|
|
39
|
+
const updateNgssmCachingState = (state, command) => update(state, { [NgssmCachingStateSpecification.featureStateKey]: command });
|
|
61
40
|
let NgssmCachingStateSpecification = class NgssmCachingStateSpecification {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
caches: {}
|
|
65
|
-
};
|
|
41
|
+
static featureStateKey = "ngssm-caching-state";
|
|
42
|
+
static initialState = { caches: {} };
|
|
66
43
|
};
|
|
67
|
-
NgssmCachingStateSpecification = __decorate([
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
})
|
|
72
|
-
], NgssmCachingStateSpecification);
|
|
73
|
-
|
|
44
|
+
NgssmCachingStateSpecification = __decorate([NgSsmFeatureState({
|
|
45
|
+
featureStateKey: NgssmCachingStateSpecification.featureStateKey,
|
|
46
|
+
initialState: NgssmCachingStateSpecification.initialState
|
|
47
|
+
})], NgssmCachingStateSpecification);
|
|
74
48
|
const selectNgssmCachedItem = (state, key) => selectNgssmCachingState(state).caches[key];
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
49
|
+
var CachedItemReducer = class CachedItemReducer {
|
|
50
|
+
processedActions = [NgssmCachingActionType.setCachedItem, NgssmCachingActionType.unsetCachedItem];
|
|
51
|
+
updateState(state, action) {
|
|
52
|
+
switch (action.type) {
|
|
53
|
+
case NgssmCachingActionType.setCachedItem: {
|
|
54
|
+
const setCachedItemAction = action;
|
|
55
|
+
return updateNgssmCachingState(state, { caches: { [setCachedItemAction.cachedItemKey]: { $set: {
|
|
56
|
+
status: setCachedItemAction.status,
|
|
57
|
+
error: setCachedItemAction.error,
|
|
58
|
+
item: setCachedItemAction.cachedItem
|
|
59
|
+
} } } });
|
|
60
|
+
}
|
|
61
|
+
case NgssmCachingActionType.unsetCachedItem: {
|
|
62
|
+
const unsetCachedItemAction = action;
|
|
63
|
+
if (selectNgssmCachedItem(state, unsetCachedItemAction.cachedItemKey) === void 0) return state;
|
|
64
|
+
return updateNgssmCachingState(state, { caches: { $unset: [unsetCachedItemAction.cachedItemKey] } });
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return state;
|
|
68
|
+
}
|
|
69
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
70
|
+
minVersion: "12.0.0",
|
|
71
|
+
version: "22.2.0",
|
|
72
|
+
ngImport: i0,
|
|
73
|
+
type: CachedItemReducer,
|
|
74
|
+
deps: [],
|
|
75
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
76
|
+
});
|
|
77
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
78
|
+
minVersion: "12.0.0",
|
|
79
|
+
version: "22.2.0",
|
|
80
|
+
ngImport: i0,
|
|
81
|
+
type: CachedItemReducer
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
85
|
+
minVersion: "12.0.0",
|
|
86
|
+
version: "22.2.0",
|
|
87
|
+
ngImport: i0,
|
|
88
|
+
type: CachedItemReducer,
|
|
89
|
+
decorators: [{ type: Injectable }]
|
|
90
|
+
});
|
|
113
91
|
const provideNgssmCaching = () => {
|
|
114
|
-
|
|
92
|
+
return makeEnvironmentProviders([provideReducers(CachedItemReducer)]);
|
|
115
93
|
};
|
|
116
|
-
|
|
117
94
|
const cachedItemToSignal = (key, options) => {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
return {
|
|
136
|
-
key,
|
|
137
|
-
value: computed(() => selectNgssmCachedItem(store.state(), key)?.item ?? options?.defaultValue)
|
|
138
|
-
};
|
|
139
|
-
}
|
|
95
|
+
const store = inject(Store);
|
|
96
|
+
const usedOptions = options ?? { type: "item" };
|
|
97
|
+
if (!usedOptions.type) usedOptions.type = "item";
|
|
98
|
+
switch (usedOptions.type) {
|
|
99
|
+
case "status": return {
|
|
100
|
+
key,
|
|
101
|
+
value: computed(() => selectNgssmCachedItem(store.state(), key)?.status ?? options?.defaultValue ?? CachedItemStatus.notSet)
|
|
102
|
+
};
|
|
103
|
+
case "error": return {
|
|
104
|
+
key,
|
|
105
|
+
value: computed(() => selectNgssmCachedItem(store.state(), key)?.error ?? options?.defaultValue)
|
|
106
|
+
};
|
|
107
|
+
case "item": return {
|
|
108
|
+
key,
|
|
109
|
+
value: computed(() => selectNgssmCachedItem(store.state(), key)?.item ?? options?.defaultValue)
|
|
110
|
+
};
|
|
111
|
+
}
|
|
140
112
|
};
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Generated bundle index. Do not edit.
|
|
144
|
-
*/
|
|
145
|
-
|
|
146
113
|
export { CachedItemStatus, NgssmCachingActionType, NgssmCachingStateSpecification, SetCachedItemAction, UnsetCachedItemAction, cachedItemToSignal, provideNgssmCaching, selectNgssmCachedItem, selectNgssmCachingState, updateNgssmCachingState };
|
|
147
|
-
|
|
114
|
+
|
|
115
|
+
//# sourceMappingURL=ngssm-store-caching.mjs.map
|