ng-simple-state 20.1.5 → 20.1.7
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 +31 -1
- package/fesm2022/ng-simple-state.mjs +62 -20
- package/fesm2022/ng-simple-state.mjs.map +1 -1
- package/index.d.ts +80 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -513,6 +513,21 @@ export abstract class NgSimpleStateBaseRxjsStore<S extends object | Array<any>>
|
|
|
513
513
|
* @returns True if the state is changed
|
|
514
514
|
*/
|
|
515
515
|
setState(stateFn: NgSimpleStateSetState<S>, actionName?: string): boolean;
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* Replace state
|
|
519
|
+
* @param newState New state
|
|
520
|
+
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
521
|
+
* @returns True if the state is changed
|
|
522
|
+
*/
|
|
523
|
+
replaceState(newState: S, actionName?: string): boolean;
|
|
524
|
+
/**
|
|
525
|
+
* Replace state
|
|
526
|
+
* @param selectFn State reducer
|
|
527
|
+
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
528
|
+
* @returns True if the state is changed
|
|
529
|
+
*/
|
|
530
|
+
replaceState(stateFn: NgSimpleStateReplaceState<S>, actionName?: string): boolean;
|
|
516
531
|
}
|
|
517
532
|
```
|
|
518
533
|
## Signal Store
|
|
@@ -960,7 +975,22 @@ export abstract class NgSimpleStateBaseSignalStore<S extends object | Array<any>
|
|
|
960
975
|
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
961
976
|
* @returns True if the state is changed
|
|
962
977
|
*/
|
|
963
|
-
setState(stateFn: NgSimpleStateSetState<S>, actionName?: string): boolean;
|
|
978
|
+
setState(stateFn: NgSimpleStateSetState<S>, actionName?: string): boolean;
|
|
979
|
+
|
|
980
|
+
/**
|
|
981
|
+
* Replace state
|
|
982
|
+
* @param newState New state
|
|
983
|
+
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
984
|
+
* @returns True if the state is changed
|
|
985
|
+
*/
|
|
986
|
+
replaceState(newState: S, actionName?: string): boolean;
|
|
987
|
+
/**
|
|
988
|
+
* Replace state
|
|
989
|
+
* @param selectFn State reducer
|
|
990
|
+
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
991
|
+
* @returns True if the state is changed
|
|
992
|
+
*/
|
|
993
|
+
replaceState(stateFn: NgSimpleStateReplaceState<S>, actionName?: string): boolean;
|
|
964
994
|
}
|
|
965
995
|
```
|
|
966
996
|
|
|
@@ -8,6 +8,7 @@ import { map, distinctUntilChanged, observeOn } from 'rxjs/operators';
|
|
|
8
8
|
*/
|
|
9
9
|
const NG_SIMPLE_STORE_CONFIG = new InjectionToken('ng-simple-state.config');
|
|
10
10
|
|
|
11
|
+
/** @deprecated use `provideNgSimpleState(ngSimpleStateConfig)` */
|
|
11
12
|
class NgSimpleStateModule {
|
|
12
13
|
static forRoot(ngSimpleStateConfig) {
|
|
13
14
|
return {
|
|
@@ -146,7 +147,6 @@ class NgSimpleStateSessionStorage extends NgSimpleStateStorage {
|
|
|
146
147
|
class NgSimpleStateBaseCommonStore {
|
|
147
148
|
constructor() {
|
|
148
149
|
this.devMode = isDevMode();
|
|
149
|
-
this.selectFnRef = this.selectFn.bind(this);
|
|
150
150
|
const globalConfig = inject(NG_SIMPLE_STORE_CONFIG, { optional: true });
|
|
151
151
|
const storeConfig = this.storeConfig();
|
|
152
152
|
const config = { ...globalConfig, ...storeConfig };
|
|
@@ -200,15 +200,15 @@ class NgSimpleStateBaseCommonStore {
|
|
|
200
200
|
* - otherwise the initial state provided from `initialState()` method.
|
|
201
201
|
*/
|
|
202
202
|
resetState() {
|
|
203
|
-
return this.
|
|
203
|
+
return this.replaceState(this.firstState, 'resetState');
|
|
204
204
|
}
|
|
205
205
|
/**
|
|
206
206
|
* Restart the store to initial state provided from `initialState()` method
|
|
207
207
|
*/
|
|
208
208
|
restartState() {
|
|
209
|
-
return this.
|
|
209
|
+
return this.replaceState(this.initState, 'restartState');
|
|
210
210
|
}
|
|
211
|
-
|
|
211
|
+
_setState(stateFnOrNewState, actionName) {
|
|
212
212
|
const currState = this.getCurrentState();
|
|
213
213
|
let newState;
|
|
214
214
|
if (typeof stateFnOrNewState === 'function') {
|
|
@@ -239,10 +239,26 @@ class NgSimpleStateBaseCommonStore {
|
|
|
239
239
|
this.storage && this.statePersist(state);
|
|
240
240
|
return state;
|
|
241
241
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
242
|
+
_replaceState(stateFnOrReplaceState, actionName) {
|
|
243
|
+
const currState = this.getCurrentState();
|
|
244
|
+
let newState;
|
|
245
|
+
if (typeof stateFnOrReplaceState === 'function') {
|
|
246
|
+
newState = stateFnOrReplaceState(currState);
|
|
247
|
+
}
|
|
248
|
+
else {
|
|
249
|
+
newState = stateFnOrReplaceState;
|
|
250
|
+
}
|
|
251
|
+
if (currState === newState) {
|
|
252
|
+
return undefined;
|
|
253
|
+
}
|
|
254
|
+
// If comparator is provided, use it to detect equality (avoids further work)
|
|
255
|
+
if (this.comparator && this.comparator(currState, newState)) {
|
|
256
|
+
return undefined;
|
|
257
|
+
}
|
|
258
|
+
// avoid function call if not necessary
|
|
259
|
+
this.devTool && this.devToolSend(newState, actionName);
|
|
260
|
+
this.storage && this.statePersist(newState);
|
|
261
|
+
return newState;
|
|
246
262
|
}
|
|
247
263
|
/**
|
|
248
264
|
* Send to dev tool a new state
|
|
@@ -324,7 +340,7 @@ class NgSimpleStateBaseRxjsStore extends NgSimpleStateBaseCommonStore {
|
|
|
324
340
|
constructor() {
|
|
325
341
|
super(...arguments);
|
|
326
342
|
this.stackPoint = 4;
|
|
327
|
-
this.state$ = new BehaviorSubject(this.
|
|
343
|
+
this.state$ = new BehaviorSubject(this.firstState);
|
|
328
344
|
this.stateObs = this.state$.asObservable();
|
|
329
345
|
}
|
|
330
346
|
/**
|
|
@@ -348,7 +364,9 @@ class NgSimpleStateBaseRxjsStore extends NgSimpleStateBaseCommonStore {
|
|
|
348
364
|
* @returns Observable of the selected state
|
|
349
365
|
*/
|
|
350
366
|
selectState(selectFn, comparator) {
|
|
351
|
-
selectFn
|
|
367
|
+
if (!selectFn) {
|
|
368
|
+
return this.stateObs;
|
|
369
|
+
}
|
|
352
370
|
return this.state$.pipe(map(state => selectFn(state)), distinctUntilChanged(comparator ?? this.comparator), observeOn(asyncScheduler));
|
|
353
371
|
}
|
|
354
372
|
/**
|
|
@@ -359,7 +377,15 @@ class NgSimpleStateBaseRxjsStore extends NgSimpleStateBaseCommonStore {
|
|
|
359
377
|
return this.devMode ? this.deepFreeze(this.state$.getValue()) : this.state$.getValue();
|
|
360
378
|
}
|
|
361
379
|
setState(stateFnOrNewState, actionName) {
|
|
362
|
-
const state = this.
|
|
380
|
+
const state = this._setState(stateFnOrNewState, actionName);
|
|
381
|
+
if (typeof state !== 'undefined') {
|
|
382
|
+
this.state$.next(state);
|
|
383
|
+
return true;
|
|
384
|
+
}
|
|
385
|
+
return false;
|
|
386
|
+
}
|
|
387
|
+
replaceState(stateFnOrNewState, actionName) {
|
|
388
|
+
const state = this._replaceState(stateFnOrNewState, actionName);
|
|
363
389
|
if (typeof state !== 'undefined') {
|
|
364
390
|
this.state$.next(state);
|
|
365
391
|
return true;
|
|
@@ -381,7 +407,7 @@ class NgSimpleStateBaseSignalStore extends NgSimpleStateBaseCommonStore {
|
|
|
381
407
|
constructor() {
|
|
382
408
|
super(...arguments);
|
|
383
409
|
this.stackPoint = 4;
|
|
384
|
-
this.stateSig = signal(this.
|
|
410
|
+
this.stateSig = signal(this.firstState);
|
|
385
411
|
this.stateSigRo = this.stateSig.asReadonly();
|
|
386
412
|
}
|
|
387
413
|
/**
|
|
@@ -398,7 +424,9 @@ class NgSimpleStateBaseSignalStore extends NgSimpleStateBaseCommonStore {
|
|
|
398
424
|
* @returns Signal of the selected state
|
|
399
425
|
*/
|
|
400
426
|
selectState(selectFn, comparator) {
|
|
401
|
-
selectFn
|
|
427
|
+
if (!selectFn) {
|
|
428
|
+
return this.stateSigRo;
|
|
429
|
+
}
|
|
402
430
|
return computed(() => selectFn(this.stateSig()), { equal: comparator ?? this.comparator });
|
|
403
431
|
}
|
|
404
432
|
/**
|
|
@@ -409,7 +437,15 @@ class NgSimpleStateBaseSignalStore extends NgSimpleStateBaseCommonStore {
|
|
|
409
437
|
return this.devMode ? this.deepFreeze(this.stateSig()) : this.stateSig();
|
|
410
438
|
}
|
|
411
439
|
setState(stateFnOrNewState, actionName) {
|
|
412
|
-
const state = this.
|
|
440
|
+
const state = this._setState(stateFnOrNewState, actionName);
|
|
441
|
+
if (typeof state !== 'undefined') {
|
|
442
|
+
this.stateSig.set(state);
|
|
443
|
+
return true;
|
|
444
|
+
}
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
replaceState(stateFnOrReplaceState, actionName) {
|
|
448
|
+
const state = this._replaceState(stateFnOrReplaceState, actionName);
|
|
413
449
|
if (typeof state !== 'undefined') {
|
|
414
450
|
this.stateSig.set(state);
|
|
415
451
|
return true;
|
|
@@ -426,15 +462,21 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.0.0", ngImpor
|
|
|
426
462
|
type: Directive
|
|
427
463
|
}] });
|
|
428
464
|
|
|
465
|
+
/**
|
|
466
|
+
* Provide NgSimpleState with optional global configuration
|
|
467
|
+
* @param {NgSimpleStateConfig} ngSimpleStateConfig
|
|
468
|
+
* @returns {EnvironmentProviders[]}
|
|
469
|
+
*/
|
|
429
470
|
function provideNgSimpleState(ngSimpleStateConfig) {
|
|
430
|
-
const providers = [];
|
|
431
471
|
if (ngSimpleStateConfig) {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
472
|
+
return [
|
|
473
|
+
makeEnvironmentProviders([{
|
|
474
|
+
provide: NG_SIMPLE_STORE_CONFIG,
|
|
475
|
+
useValue: ngSimpleStateConfig,
|
|
476
|
+
}])
|
|
477
|
+
];
|
|
436
478
|
}
|
|
437
|
-
return
|
|
479
|
+
return [];
|
|
438
480
|
}
|
|
439
481
|
|
|
440
482
|
/*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ng-simple-state.mjs","sources":["../../../projects/ng-simple-state/src/lib/ng-simple-state-models.ts","../../../projects/ng-simple-state/src/lib/ng-simple-state.module.ts","../../../projects/ng-simple-state/src/lib/tool/ng-simple-state-dev-tool.ts","../../../projects/ng-simple-state/src/lib/storage/ng-simple-state-browser-storage.ts","../../../projects/ng-simple-state/src/lib/storage/ng-simple-state-local-storage.ts","../../../projects/ng-simple-state/src/lib/storage/ng-simple-state-session-storage.ts","../../../projects/ng-simple-state/src/lib/ng-simple-state-common.ts","../../../projects/ng-simple-state/src/lib/rxjs/ng-simple-state-base-store.ts","../../../projects/ng-simple-state/src/lib/signal/ng-simple-state-base-store.ts","../../../projects/ng-simple-state/src/lib/ng-simple-state-provider.ts","../../../projects/ng-simple-state/src/public-api.ts","../../../projects/ng-simple-state/src/ng-simple-state.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\nimport type { NgSimpleStateStorage } from './storage/ng-simple-state-browser-storage';\n\nexport type NgSimpleStateSetState<S> = (currentState: Readonly<S>) => Partial<S>;\nexport type NgSimpleStateSelectState<S, K> = (state: Readonly<S>) => K;\n/* eslint-disable-next-line @typescript-eslint/no-explicit-any */\nexport type NgSimpleStateComparator<K = any> = (previous: K, current: K) => boolean;\n\n/**\n * NgSimpleState config option\n */\n/* eslint-disable-next-line @typescript-eslint/no-explicit-any */\nexport interface NgSimpleStateConfig<K = any> {\n /**\n * if `true` enable `Redux DevTools` browser extension for inspect the state of the store.\n */\n enableDevTool?: boolean;\n /**\n * Set the persistent storage `local`, `session` or instance of `NgSimpleStateStorage`.\n */\n persistentStorage?: 'session' | 'local' | NgSimpleStateStorage;\n /**\n * A function used to compare the previous and current state for equality. \n */\n comparator?: NgSimpleStateComparator<K>;\n /**\n * A function used to serialize the state to a string.\n */\n serializeState?: (state: K) => string;\n /**\n * A function used to deserialize the state from a string. \n */\n deserializeState?: (state: string) => K;\n}\n\n/**\n * NgSimpleState config option for store\n */\n/* eslint-disable-next-line @typescript-eslint/no-explicit-any */\nexport interface NgSimpleStateStoreConfig<K = any> extends NgSimpleStateConfig<K> {\n /** \n * The store name \n */\n storeName: string;\n}\n\n/**\n * NgSimpleState config InjectionToken\n */\nexport const NG_SIMPLE_STORE_CONFIG = new InjectionToken<NgSimpleStateConfig>(\n 'ng-simple-state.config'\n);\n\nexport type StateFnOrNewState<S> = Partial<S> | NgSimpleStateSetState<S>;\n","import { ModuleWithProviders, NgModule } from '@angular/core';\r\nimport { NgSimpleStateConfig, NG_SIMPLE_STORE_CONFIG } from './ng-simple-state-models';\r\n\r\n@NgModule()\r\nexport class NgSimpleStateModule {\r\n static forRoot(\r\n ngSimpleStateConfig?: NgSimpleStateConfig\r\n ): ModuleWithProviders<NgSimpleStateModule> {\r\n return {\r\n ngModule: NgSimpleStateModule,\r\n providers: [\r\n {\r\n provide: NG_SIMPLE_STORE_CONFIG,\r\n useValue: ngSimpleStateConfig,\r\n },\r\n ],\r\n };\r\n }\r\n}\r\n","import { inject, Injectable, NgZone } from '@angular/core';\n\ninterface DevtoolsLocal {\n init: (state: object) => void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n send: <T>(action: string, state: Record<string, T>, options: any, instanceId: string) => void;\n}\ninterface Devtools {\n connect(options: { name: string, instanceId: string }): DevtoolsLocal;\n}\n\ndeclare global {\n interface Window {\n __REDUX_DEVTOOLS_EXTENSION__: Devtools;\n devToolsExtension: Devtools;\n }\n}\n\nconst instanceId = `ng-simple-state-${Date.now()}-${Math.random()}`;\n\n@Injectable({ providedIn: 'root' })\nexport class NgSimpleStateDevTool {\n\n private readonly globalDevtools: Devtools = window.__REDUX_DEVTOOLS_EXTENSION__ || window.devToolsExtension;\n private localDevTool!: DevtoolsLocal;\n private readonly baseState: Record<string, object> = {};\n\n constructor() {\n if (this.globalDevtools) {\n // The `connect` method adds `message` event listener since it communicates\n // with an extension through `window.postMessage` and message events.\n // We handle only 2 events; thus, we don't want to run many change detections\n // because the extension sends events that we don't have to handle.\n inject(NgZone).runOutsideAngular(() => {\n this.localDevTool = this.globalDevtools.connect({\n name: 'NgSimpleState',\n instanceId: instanceId\n });\n if (this.localDevTool) {\n this.localDevTool.init(this.baseState);\n }\n });\n }\n }\n\n /**\n * Return true if dev tool is active\n * @returns True if dev tool is active\n */\n isActive(): boolean {\n return !!this.localDevTool;\n }\n\n /**\n * Send to dev tool a new state\n * @param storeName The store name\n * @param actionName The action name\n * @param state the state\n * @returns True if dev tool is enabled and action is send\n */\n send<T>(storeName: string, actionName: string, state: T): boolean {\n if (this.localDevTool) {\n this.localDevTool.send<T>(`${storeName}.${actionName}`, Object.assign(this.baseState, { [storeName]: state }), false, instanceId);\n return true;\n }\n return false;\n }\n}\n","import { NgSimpleStateStoreConfig } from \"../ng-simple-state-models\";\n\nexport const BASE_KEY = 'NgSimpleState::';\n\nexport abstract class NgSimpleStateStorage<K = unknown> {\n\n /**\n * A function used to serialize the state to a string.\n */\n private serializeState: (state: K) => string;\n \n /**\n * A function used to deserialize the state from a string. \n */\n private deserializeState: (state: string) => K;\n\n constructor(private storage: Storage, config?: NgSimpleStateStoreConfig<K>) { \n this.serializeState = config?.serializeState ? config.serializeState : JSON.stringify;\n this.deserializeState = config?.deserializeState ? config.deserializeState : JSON.parse;\n }\n\n /**\n * Set item into storage\n * @param key key name\n * @param state state value\n * @returns True if item is stored into storage\n */\n setItem(key: string, state: K): boolean {\n this.storage.setItem(BASE_KEY + key, this.serializeState(state));\n return true;\n }\n\n /**\n * Return item from storage\n * @param key key name\n * @returns the item\n */\n getItem(key: string): K | null {\n const state = this.storage.getItem(BASE_KEY + key);\n if (state) {\n return this.deserializeState(state);\n }\n return null;\n }\n\n /**\n * Remove item from storage\n * @param {string} key key name\n * @returns True if item is removed\n */\n removeItem(key: string): boolean {\n this.storage.removeItem(BASE_KEY + key);\n return true;\n }\n\n /**\n * Removes all key/value pairs, if there are any.\n * @returns True if storage is cleared\n */\n clear(): boolean {\n for (let i = this.storage.length; i >= 0; i--) {\n const key = this.storage.key(i);\n if (key && key.startsWith(BASE_KEY)) {\n this.storage.removeItem(key);\n }\n }\n return true;\n }\n}\n","import { NgSimpleStateStoreConfig } from '../ng-simple-state-models';\nimport { NgSimpleStateStorage } from './ng-simple-state-browser-storage';\n\nexport class NgSimpleStateLocalStorage<K = unknown> extends NgSimpleStateStorage<K> {\n constructor(config?: NgSimpleStateStoreConfig<K>) {\n super(localStorage, config);\n }\n}\n","\nimport { NgSimpleStateStoreConfig } from '../ng-simple-state-models';\nimport { NgSimpleStateStorage } from './ng-simple-state-browser-storage';\n\nexport class NgSimpleStateSessionStorage<K = unknown> extends NgSimpleStateStorage<K> {\n constructor(config?: NgSimpleStateStoreConfig<K>) {\n super(sessionStorage, config);\n }\n}\n","import { Injectable, OnDestroy, Directive, isDevMode, inject } from '@angular/core';\nimport { NgSimpleStateDevTool } from './tool/ng-simple-state-dev-tool';\nimport type { NgSimpleStateStorage } from './storage/ng-simple-state-browser-storage';\nimport { NgSimpleStateLocalStorage } from './storage/ng-simple-state-local-storage';\nimport { NgSimpleStateSessionStorage } from './storage/ng-simple-state-session-storage';\nimport { type NgSimpleStateStoreConfig, NG_SIMPLE_STORE_CONFIG, type NgSimpleStateSetState, type NgSimpleStateComparator, type NgSimpleStateSelectState, type StateFnOrNewState, NgSimpleStateConfig } from './ng-simple-state-models';\n\n\n@Injectable()\n@Directive()\nexport abstract class NgSimpleStateBaseCommonStore<S extends object | Array<unknown>> implements OnDestroy {\n\n protected abstract stackPoint: number;\n protected devTool?: NgSimpleStateDevTool;\n protected storage?: NgSimpleStateStorage<S>;\n protected storeName: string;\n protected firstState!: S;\n protected initState!: S;\n protected isArray: boolean;\n protected devMode: boolean = isDevMode();\n protected comparator?: NgSimpleStateComparator<S>;\n protected readonly selectFnRef = this.selectFn.bind(this);\n\n constructor() {\n\n const globalConfig: NgSimpleStateConfig<S> | null = inject(NG_SIMPLE_STORE_CONFIG, { optional: true })\n const storeConfig = this.storeConfig();\n const config = { ...globalConfig, ...storeConfig };\n\n if (config.persistentStorage === 'local') {\n this.storage = new NgSimpleStateLocalStorage(config);\n } else if (config.persistentStorage === 'session') {\n this.storage = new NgSimpleStateSessionStorage(config);\n } else if (typeof config.persistentStorage === 'object') {\n this.storage = config.persistentStorage as NgSimpleStateStorage<S>;\n }\n\n if (config.enableDevTool) {\n this.devTool = inject(NgSimpleStateDevTool);\n }\n\n this.storeName = config.storeName;\n\n if (typeof config.comparator === 'function') {\n this.comparator = config.comparator;\n }\n\n if (this.storage) {\n const firstState = this.storage.getItem(this.storeName);\n if (firstState) {\n this.firstState = firstState;\n }\n }\n\n this.initState = this.initialState();\n if (!this.firstState) {\n this.firstState = this.initState;\n }\n\n this.devToolSend(this.firstState, 'initialState');\n\n this.isArray = Array.isArray(this.firstState);\n }\n\n /**\n * When you override this method, you have to call the `super.ngOnDestroy()` method in your `ngOnDestroy()` method.\n */\n ngOnDestroy(): void {\n this.devToolSend(undefined, 'ngOnDestroy');\n }\n\n /**\n * Override this method for set a specific config for the store\n * @returns NgSimpleStateStoreConfig\n */\n protected abstract storeConfig(): NgSimpleStateStoreConfig;\n\n /**\n * Set into the store the initial state\n * @returns The state object\n */\n protected abstract initialState(): S;\n\n /**\n * Select a store state\n * @param selectFn State selector (if not provided return full state)\n * @param comparator A function used to compare the previous and current state for equality. Defaults to a `===` check.\n * @returns Observable of the selected state\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n abstract selectState<K = Partial<S>>(selectFn?: NgSimpleStateSelectState<S, K>, comparator?: NgSimpleStateComparator<K>): any;\n\n /**\n * Set a new state\n * @param newState New state\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n abstract setState(newState: Partial<S>, actionName?: string): boolean;\n\n /**\n * Set a new state\n * @param selectFn State reducer\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n abstract setState(stateFn: NgSimpleStateSetState<S>, actionName?: string): boolean;\n\n /**\n * Return the current store state (snapshot)\n * @returns The current state\n */\n abstract getCurrentState(): Readonly<S>;\n\n /**\n * Return the first loaded store state:\n * the last saved state\n * otherwise the initial state provided from `initialState()` method.\n * @returns The first state\n */\n getFirstState(): Readonly<S> | null {\n return this.deepFreeze(this.firstState);\n }\n\n /**\n * Reset store to first loaded store state:\n * - the last saved state\n * - otherwise the initial state provided from `initialState()` method.\n */\n resetState(): boolean {\n return this.setState(this.firstState, 'resetState');\n }\n\n /**\n * Restart the store to initial state provided from `initialState()` method\n */\n restartState(): boolean {\n return this.setState(this.initState, 'restartState');\n }\n\n /**\n * Set a new state\n * @param newState New state\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns state\n */\n protected patchState(newState: Partial<S>, actionName?: string): S | undefined;\n /**\n * Set a new state\n * @param selectFn State reducer\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns state\n */\n protected patchState(stateFn: NgSimpleStateSetState<S>, actionName?: string): S | undefined;\n /**\n * Set a new state\n * @param stateFnOrNewState State reducer or new state\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns state\n */\n protected patchState(stateFnOrNewState: StateFnOrNewState<S>, actionName?: string): S | undefined;\n protected patchState(stateFnOrNewState: StateFnOrNewState<S>, actionName?: string): S | undefined {\n const currState = this.getCurrentState();\n let newState: Partial<S>;\n if (typeof stateFnOrNewState === 'function') {\n newState = stateFnOrNewState(currState);\n } else {\n newState = stateFnOrNewState;\n }\n if (currState === newState) {\n return undefined;\n }\n let state: S;\n if (this.isArray) {\n // when working with arrays we treat payload as full replacement; avoid copying currState\n state = (newState as unknown as S);\n } else {\n // shallow merge using Object.assign (faster than spread in hot paths)\n // create a new object to avoid mutating current state\n state = Object.assign({}, currState, newState) as S;\n }\n\n // If comparator is provided, use it to detect equality (avoids further work)\n if (this.comparator && this.comparator(currState, state)) {\n return undefined;\n }\n // avoid function call if not necessary\n this.devTool && this.devToolSend(state, actionName);\n this.storage && this.statePersist(state);\n return state;\n }\n\n protected selectFn<K>(tmpState: Readonly<S>) {\n // Return the state as-is to avoid an extra shallow clone on every select.\n // Consumers should treat selected value as read-only. In dev mode deepFreeze will help.\n return tmpState as unknown as K;\n }\n\n /**\n * Send to dev tool a new state\n * @param newState new state\n * @param actionName The action name\n * @returns True if dev tools are enabled\n */\n protected devToolSend(newState: S | undefined, actionName?: string): boolean {\n if (!this.devTool) {\n return false;\n }\n if (!actionName) {\n // retrieve the parent (of parent) method into the stack trace\n try {\n actionName = new Error().stack\n ?.split('\\n')[this.stackPoint]\n ?.trim()\n ?.split(' ')[1]\n ?.split('.')[1] || 'unknown';\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars */\n } catch (_) {\n /* istanbul ignore next */\n actionName = 'unknown';\n }\n }\n if (!this.devTool.send(this.storeName, actionName, newState)) {\n /* istanbul ignore next */\n console.log(this.storeName + '.' + actionName, newState);\n }\n return true;\n }\n\n /**\n * Recursively Object.freeze simple Javascript structures consisting of plain objects, arrays, and primitives.\n * Make the data immutable.\n * @returns immutable object\n */\n protected deepFreeze(object: S): Readonly<S> {\n // No freezing in production (for better performance).\n if (!this.devMode || !object) {\n return object as Readonly<S>;\n }\n\n // When already frozen, we assume its children are frozen (for better performance).\n // This should be true if you always use `deepFreeze` to freeze objects.\n //\n // Note that Object.isFrozen will also return `true` for primitives (numbers,\n // strings, booleans, undefined, null), so there is no need to check for\n // those explicitly.\n if (Object.isFrozen(object)) {\n return object as Readonly<S>;\n }\n\n // At this point we know that we're dealing with either an array or plain object, so\n // just freeze it and recurse on its values.\n Object.freeze(object);\n /* eslint-disable @typescript-eslint/no-explicit-any */\n Object.keys(object).forEach(key => this.deepFreeze((object as any)[key]));\n\n return object as Readonly<S>;\n }\n\n /**\n * Persist state to storage\n */\n protected statePersist(state: S) {\n if (this.storage) {\n this.storage.setItem(this.storeName, state);\n }\n }\n}\n","import { Injectable, OnDestroy, Directive } from '@angular/core';\nimport { BehaviorSubject, Observable, asyncScheduler } from 'rxjs';\nimport { map, distinctUntilChanged, observeOn } from 'rxjs/operators';\nimport { NgSimpleStateBaseCommonStore } from '../ng-simple-state-common';\nimport type { NgSimpleStateComparator, NgSimpleStateSelectState, NgSimpleStateSetState, StateFnOrNewState } from '../ng-simple-state-models';\n\n@Injectable()\n@Directive()\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport abstract class NgSimpleStateBaseRxjsStore<S extends object | Array<any>> extends NgSimpleStateBaseCommonStore<S> implements OnDestroy {\n\n protected stackPoint: number = 4;\n private readonly state$: BehaviorSubject<S> = new BehaviorSubject<S>(this.selectFn(this.firstState));\n private readonly stateObs: Observable<S> = this.state$.asObservable();\n\n /**\n * Return the observable of the state\n * @returns Observable of the state\n */\n public get state(): Observable<S> {\n return this.stateObs;\n }\n\n /**\n * When you override this method, you have to call the `super.ngOnDestroy()` method in your `ngOnDestroy()` method.\n */\n override ngOnDestroy(): void {\n super.ngOnDestroy();\n this.state$.complete();\n }\n\n /**\n * Select a store state\n * @param selectFn State selector (if not provided return full state)\n * @param comparator A function used to compare the previous and current state for equality. Defaults to a `===` check.\n * @returns Observable of the selected state\n */\n selectState<K = Partial<S>>(selectFn?: NgSimpleStateSelectState<S, K>, comparator?: NgSimpleStateComparator<K>): Observable<K> {\n selectFn ??= this.selectFnRef;\n return this.state$.pipe(\n map(state => selectFn(state as Readonly<S>)),\n distinctUntilChanged(comparator ?? this.comparator as NgSimpleStateComparator),\n observeOn(asyncScheduler)\n );\n }\n\n /**\n * Return the current store state (snapshot)\n * @returns The current state\n */\n getCurrentState(): Readonly<S> {\n return this.devMode ? this.deepFreeze(this.state$.getValue()) : this.state$.getValue();\n }\n\n /**\n * Set a new state\n * @param newState New state\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n setState(newState: Partial<S>, actionName?: string): boolean;\n /**\n * Set a new state\n * @param selectFn State reducer\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n setState(stateFn: NgSimpleStateSetState<S>, actionName?: string): boolean;\n setState(stateFnOrNewState: StateFnOrNewState<S>, actionName?: string): boolean {\n const state = this.patchState(stateFnOrNewState, actionName);\n if (typeof state !== 'undefined') {\n this.state$.next(state);\n return true;\n }\n return false;\n }\n}\n","import { Injectable, Directive, Signal, signal, computed, WritableSignal } from '@angular/core';\nimport { NgSimpleStateBaseCommonStore } from '../ng-simple-state-common';\nimport type { NgSimpleStateComparator, NgSimpleStateSelectState, NgSimpleStateSetState, StateFnOrNewState } from '../ng-simple-state-models';\n\n@Injectable()\n@Directive()\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport abstract class NgSimpleStateBaseSignalStore<S extends object | Array<any>> extends NgSimpleStateBaseCommonStore<S> {\n\n protected stackPoint: number = 4;\n private readonly stateSig: WritableSignal<S> = signal<S>(this.selectFn(this.firstState));\n private readonly stateSigRo: Signal<S> = this.stateSig.asReadonly();\n\n /**\n * Return the Signal of the state\n * @returns Signal of the state\n */\n public get state(): Signal<S> {\n return this.stateSigRo;\n }\n\n /**\n * Select a store state\n * @param selectFn State selector (if not provided return full state)\n * @param comparator A function used to compare the previous and current state for equality. Defaults to a `===` check.\n * @returns Signal of the selected state\n */\n selectState<K = Partial<S>>(selectFn?: NgSimpleStateSelectState<S, K>, comparator?: NgSimpleStateComparator<K>): Signal<K> {\n selectFn ??= this.selectFnRef;\n return computed(() => selectFn(this.stateSig() as Readonly<S>), { equal: comparator ?? this.comparator as NgSimpleStateComparator });\n }\n\n /**\n * Return the current store state (snapshot)\n * @returns The current state\n */\n getCurrentState(): Readonly<S> {\n return this.devMode ? this.deepFreeze(this.stateSig()) : this.stateSig();\n }\n\n /**\n * Set a new state\n * @param newState New state\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n setState(newState: Partial<S>, actionName?: string): boolean;\n /**\n * Set a new state\n * @param selectFn State reducer\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n setState(stateFn: NgSimpleStateSetState<S>, actionName?: string): boolean;\n setState(stateFnOrNewState: StateFnOrNewState<S>, actionName?: string): boolean {\n const state = this.patchState(stateFnOrNewState, actionName);\n if (typeof state !== 'undefined') {\n this.stateSig.set(state);\n return true;\n }\n return false;\n }\n}\n","import { EnvironmentProviders, makeEnvironmentProviders } from \"@angular/core\";\r\nimport { NG_SIMPLE_STORE_CONFIG, NgSimpleStateConfig } from \"./ng-simple-state-models\";\r\n\r\nexport function provideNgSimpleState(ngSimpleStateConfig?: NgSimpleStateConfig): EnvironmentProviders[] {\r\n const providers: EnvironmentProviders[] = [];\r\n if (ngSimpleStateConfig) {\r\n providers.push(makeEnvironmentProviders([{\r\n provide: NG_SIMPLE_STORE_CONFIG,\r\n useValue: ngSimpleStateConfig,\r\n }]));\r\n }\r\n return providers;\r\n}\r\n","/*\r\n * Public API Surface of ng-simple-state\r\n */\r\nexport * from './lib/ng-simple-state.module';\r\nexport * from './lib/rxjs/ng-simple-state-base-store';\r\nexport * from './lib/signal/ng-simple-state-base-store';\r\nexport * from './lib/tool/ng-simple-state-dev-tool';\r\nexport * from './lib/storage/ng-simple-state-local-storage';\r\nexport * from './lib/storage/ng-simple-state-session-storage';\r\nexport * from './lib/ng-simple-state-models';\r\nexport * from './lib/ng-simple-state-common';\r\nexport * from './lib/ng-simple-state-provider';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AA8CA;;AAEG;MACU,sBAAsB,GAAG,IAAI,cAAc,CACpD,wBAAwB;;MC9Cf,mBAAmB,CAAA;IAC5B,OAAO,OAAO,CACV,mBAAyC,EAAA;QAEzC,OAAO;AACH,YAAA,QAAQ,EAAE,mBAAmB;AAC7B,YAAA,SAAS,EAAE;AACP,gBAAA;AACI,oBAAA,OAAO,EAAE,sBAAsB;AAC/B,oBAAA,QAAQ,EAAE,mBAAmB;AAChC,iBAAA;AACJ,aAAA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ACZA;;AAEG;;ACFH;;AAEG;;;;"}
|
|
1
|
+
{"version":3,"file":"ng-simple-state.mjs","sources":["../../../projects/ng-simple-state/src/lib/ng-simple-state-models.ts","../../../projects/ng-simple-state/src/lib/ng-simple-state.module.ts","../../../projects/ng-simple-state/src/lib/tool/ng-simple-state-dev-tool.ts","../../../projects/ng-simple-state/src/lib/storage/ng-simple-state-browser-storage.ts","../../../projects/ng-simple-state/src/lib/storage/ng-simple-state-local-storage.ts","../../../projects/ng-simple-state/src/lib/storage/ng-simple-state-session-storage.ts","../../../projects/ng-simple-state/src/lib/ng-simple-state-common.ts","../../../projects/ng-simple-state/src/lib/rxjs/ng-simple-state-base-store.ts","../../../projects/ng-simple-state/src/lib/signal/ng-simple-state-base-store.ts","../../../projects/ng-simple-state/src/lib/ng-simple-state-provider.ts","../../../projects/ng-simple-state/src/public-api.ts","../../../projects/ng-simple-state/src/ng-simple-state.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\nimport type { NgSimpleStateStorage } from './storage/ng-simple-state-browser-storage';\n\nexport type NgSimpleStateReplaceState<S> = (currentState: Readonly<S>) => S;\nexport type NgSimpleStateSetState<S> = (currentState: Readonly<S>) => Partial<S>;\nexport type NgSimpleStateSelectState<S, K> = (state: Readonly<S>) => K;\n/* eslint-disable-next-line @typescript-eslint/no-explicit-any */\nexport type NgSimpleStateComparator<K = any> = (previous: K, current: K) => boolean;\n\n/**\n * NgSimpleState config option\n */\n/* eslint-disable-next-line @typescript-eslint/no-explicit-any */\nexport interface NgSimpleStateConfig<K = any> {\n /**\n * if `true` enable `Redux DevTools` browser extension for inspect the state of the store.\n */\n enableDevTool?: boolean;\n /**\n * Set the persistent storage `local`, `session` or instance of `NgSimpleStateStorage`.\n */\n persistentStorage?: 'session' | 'local' | NgSimpleStateStorage;\n /**\n * A function used to compare the previous and current state for equality. \n */\n comparator?: NgSimpleStateComparator<K>;\n /**\n * A function used to serialize the state to a string.\n */\n serializeState?: (state: K) => string;\n /**\n * A function used to deserialize the state from a string. \n */\n deserializeState?: (state: string) => K;\n}\n\n/**\n * NgSimpleState config option for store\n */\n/* eslint-disable-next-line @typescript-eslint/no-explicit-any */\nexport interface NgSimpleStateStoreConfig<K = any> extends NgSimpleStateConfig<K> {\n /** \n * The store name \n */\n storeName: string;\n}\n\n/**\n * NgSimpleState config InjectionToken\n */\nexport const NG_SIMPLE_STORE_CONFIG = new InjectionToken<NgSimpleStateConfig>(\n 'ng-simple-state.config'\n);\n\nexport type StateFnOrNewState<S> = Partial<S> | NgSimpleStateSetState<S>;\nexport type StateFnOrReplaceState<S> = S | NgSimpleStateReplaceState<S>;\n","import { ModuleWithProviders, NgModule } from '@angular/core';\r\nimport { NgSimpleStateConfig, NG_SIMPLE_STORE_CONFIG } from './ng-simple-state-models';\r\n\r\n@NgModule()\r\n/** @deprecated use `provideNgSimpleState(ngSimpleStateConfig)` */\r\nexport class NgSimpleStateModule {\r\n static forRoot(\r\n ngSimpleStateConfig?: NgSimpleStateConfig\r\n ): ModuleWithProviders<NgSimpleStateModule> {\r\n return {\r\n ngModule: NgSimpleStateModule,\r\n providers: [\r\n {\r\n provide: NG_SIMPLE_STORE_CONFIG,\r\n useValue: ngSimpleStateConfig,\r\n },\r\n ],\r\n };\r\n }\r\n}\r\n","import { inject, Injectable, NgZone } from '@angular/core';\n\ninterface DevtoolsLocal {\n init: (state: object) => void;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n send: <T>(action: string, state: Record<string, T>, options: any, instanceId: string) => void;\n}\ninterface Devtools {\n connect(options: { name: string, instanceId: string }): DevtoolsLocal;\n}\n\ndeclare global {\n interface Window {\n __REDUX_DEVTOOLS_EXTENSION__: Devtools;\n devToolsExtension: Devtools;\n }\n}\n\nconst instanceId = `ng-simple-state-${Date.now()}-${Math.random()}`;\n\n@Injectable({ providedIn: 'root' })\nexport class NgSimpleStateDevTool {\n\n private readonly globalDevtools: Devtools = window.__REDUX_DEVTOOLS_EXTENSION__ || window.devToolsExtension;\n private localDevTool!: DevtoolsLocal;\n private readonly baseState: Record<string, object> = {};\n\n constructor() {\n if (this.globalDevtools) {\n // The `connect` method adds `message` event listener since it communicates\n // with an extension through `window.postMessage` and message events.\n // We handle only 2 events; thus, we don't want to run many change detections\n // because the extension sends events that we don't have to handle.\n inject(NgZone).runOutsideAngular(() => {\n this.localDevTool = this.globalDevtools.connect({\n name: 'NgSimpleState',\n instanceId: instanceId\n });\n if (this.localDevTool) {\n this.localDevTool.init(this.baseState);\n }\n });\n }\n }\n\n /**\n * Return true if dev tool is active\n * @returns True if dev tool is active\n */\n isActive(): boolean {\n return !!this.localDevTool;\n }\n\n /**\n * Send to dev tool a new state\n * @param storeName The store name\n * @param actionName The action name\n * @param state the state\n * @returns True if dev tool is enabled and action is send\n */\n send<T>(storeName: string, actionName: string, state: T): boolean {\n if (this.localDevTool) {\n this.localDevTool.send<T>(`${storeName}.${actionName}`, Object.assign(this.baseState, { [storeName]: state }), false, instanceId);\n return true;\n }\n return false;\n }\n}\n","import { NgSimpleStateStoreConfig } from \"../ng-simple-state-models\";\n\nexport const BASE_KEY = 'NgSimpleState::';\n\nexport abstract class NgSimpleStateStorage<K = unknown> {\n\n /**\n * A function used to serialize the state to a string.\n */\n private serializeState: (state: K) => string;\n \n /**\n * A function used to deserialize the state from a string. \n */\n private deserializeState: (state: string) => K;\n\n constructor(private storage: Storage, config?: NgSimpleStateStoreConfig<K>) { \n this.serializeState = config?.serializeState ? config.serializeState : JSON.stringify;\n this.deserializeState = config?.deserializeState ? config.deserializeState : JSON.parse;\n }\n\n /**\n * Set item into storage\n * @param key key name\n * @param state state value\n * @returns True if item is stored into storage\n */\n setItem(key: string, state: K): boolean {\n this.storage.setItem(BASE_KEY + key, this.serializeState(state));\n return true;\n }\n\n /**\n * Return item from storage\n * @param key key name\n * @returns the item\n */\n getItem(key: string): K | null {\n const state = this.storage.getItem(BASE_KEY + key);\n if (state) {\n return this.deserializeState(state);\n }\n return null;\n }\n\n /**\n * Remove item from storage\n * @param {string} key key name\n * @returns True if item is removed\n */\n removeItem(key: string): boolean {\n this.storage.removeItem(BASE_KEY + key);\n return true;\n }\n\n /**\n * Removes all key/value pairs, if there are any.\n * @returns True if storage is cleared\n */\n clear(): boolean {\n for (let i = this.storage.length; i >= 0; i--) {\n const key = this.storage.key(i);\n if (key && key.startsWith(BASE_KEY)) {\n this.storage.removeItem(key);\n }\n }\n return true;\n }\n}\n","import { NgSimpleStateStoreConfig } from '../ng-simple-state-models';\nimport { NgSimpleStateStorage } from './ng-simple-state-browser-storage';\n\nexport class NgSimpleStateLocalStorage<K = unknown> extends NgSimpleStateStorage<K> {\n constructor(config?: NgSimpleStateStoreConfig<K>) {\n super(localStorage, config);\n }\n}\n","\nimport { NgSimpleStateStoreConfig } from '../ng-simple-state-models';\nimport { NgSimpleStateStorage } from './ng-simple-state-browser-storage';\n\nexport class NgSimpleStateSessionStorage<K = unknown> extends NgSimpleStateStorage<K> {\n constructor(config?: NgSimpleStateStoreConfig<K>) {\n super(sessionStorage, config);\n }\n}\n","import { Injectable, OnDestroy, Directive, isDevMode, inject } from '@angular/core';\nimport { NgSimpleStateDevTool } from './tool/ng-simple-state-dev-tool';\nimport type { NgSimpleStateStorage } from './storage/ng-simple-state-browser-storage';\nimport { NgSimpleStateLocalStorage } from './storage/ng-simple-state-local-storage';\nimport { NgSimpleStateSessionStorage } from './storage/ng-simple-state-session-storage';\nimport { type NgSimpleStateStoreConfig, NG_SIMPLE_STORE_CONFIG, type NgSimpleStateSetState, type NgSimpleStateComparator, type NgSimpleStateSelectState, type StateFnOrNewState, NgSimpleStateConfig, NgSimpleStateReplaceState, StateFnOrReplaceState } from './ng-simple-state-models';\n\n\n@Injectable()\n@Directive()\nexport abstract class NgSimpleStateBaseCommonStore<S extends object | Array<unknown>> implements OnDestroy {\n\n protected abstract stackPoint: number;\n protected devTool?: NgSimpleStateDevTool;\n protected storage?: NgSimpleStateStorage<S>;\n protected storeName: string;\n protected firstState!: S;\n protected initState!: S;\n protected isArray: boolean;\n protected devMode: boolean = isDevMode();\n protected comparator?: NgSimpleStateComparator<S>;\n\n constructor() {\n\n const globalConfig: NgSimpleStateConfig<S> | null = inject(NG_SIMPLE_STORE_CONFIG, { optional: true })\n const storeConfig = this.storeConfig();\n const config = { ...globalConfig, ...storeConfig };\n\n if (config.persistentStorage === 'local') {\n this.storage = new NgSimpleStateLocalStorage(config);\n } else if (config.persistentStorage === 'session') {\n this.storage = new NgSimpleStateSessionStorage(config);\n } else if (typeof config.persistentStorage === 'object') {\n this.storage = config.persistentStorage as NgSimpleStateStorage<S>;\n }\n\n if (config.enableDevTool) {\n this.devTool = inject(NgSimpleStateDevTool);\n }\n\n this.storeName = config.storeName;\n\n if (typeof config.comparator === 'function') {\n this.comparator = config.comparator;\n }\n\n if (this.storage) {\n const firstState = this.storage.getItem(this.storeName);\n if (firstState) {\n this.firstState = firstState;\n }\n }\n\n this.initState = this.initialState();\n if (!this.firstState) {\n this.firstState = this.initState;\n }\n\n this.devToolSend(this.firstState, 'initialState');\n\n this.isArray = Array.isArray(this.firstState);\n }\n\n /**\n * When you override this method, you have to call the `super.ngOnDestroy()` method in your `ngOnDestroy()` method.\n */\n ngOnDestroy(): void {\n this.devToolSend(undefined, 'ngOnDestroy');\n }\n\n /**\n * Override this method for set a specific config for the store\n * @returns NgSimpleStateStoreConfig\n */\n protected abstract storeConfig(): NgSimpleStateStoreConfig;\n\n /**\n * Set into the store the initial state\n * @returns The state object\n */\n protected abstract initialState(): S;\n\n /**\n * Select a store state\n * @param selectFn State selector (if not provided return full state)\n * @param comparator A function used to compare the previous and current state for equality. Defaults to a `===` check.\n * @returns Observable of the selected state\n */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n abstract selectState<K = Partial<S>>(selectFn?: NgSimpleStateSelectState<S, K>, comparator?: NgSimpleStateComparator<K>): any;\n\n /**\n * Set a new state\n * @param newState New state\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n abstract setState(newState: Partial<S>, actionName?: string): boolean;\n\n /**\n * Set a new state\n * @param selectFn State reducer\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n abstract setState(stateFn: NgSimpleStateSetState<S>, actionName?: string): boolean;\n\n /**\n * Replace state\n * @param newState New state\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n abstract replaceState(newState: S, actionName?: string): boolean;\n\n /**\n * Replace state\n * @param selectFn State reducer\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n abstract replaceState(stateFn: NgSimpleStateReplaceState<S>, actionName?: string): boolean;\n\n /**\n * Return the current store state (snapshot)\n * @returns The current state\n */\n abstract getCurrentState(): Readonly<S>;\n\n /**\n * Return the first loaded store state:\n * the last saved state\n * otherwise the initial state provided from `initialState()` method.\n * @returns The first state\n */\n getFirstState(): Readonly<S> | null {\n return this.deepFreeze(this.firstState);\n }\n\n /**\n * Reset store to first loaded store state:\n * - the last saved state\n * - otherwise the initial state provided from `initialState()` method.\n */\n resetState(): boolean {\n return this.replaceState(this.firstState, 'resetState');\n }\n\n /**\n * Restart the store to initial state provided from `initialState()` method\n */\n restartState(): boolean {\n return this.replaceState(this.initState, 'restartState');\n }\n\n /**\n * Set a new state\n * @param newState New state\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns state\n * @private\n */\n protected _setState(newState: Partial<S>, actionName?: string): S | undefined;\n /**\n * Set a new state\n * @param selectFn State reducer\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns state\n * @private\n */\n protected _setState(stateFn: NgSimpleStateSetState<S>, actionName?: string): S | undefined;\n /**\n * Set a new state\n * @param stateFnOrNewState State reducer or new state\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns state\n * @private\n */\n protected _setState(stateFnOrNewState: StateFnOrNewState<S>, actionName?: string): S | undefined;\n protected _setState(stateFnOrNewState: StateFnOrNewState<S>, actionName?: string): S | undefined {\n const currState = this.getCurrentState();\n let newState: Partial<S>;\n if (typeof stateFnOrNewState === 'function') {\n newState = stateFnOrNewState(currState);\n } else {\n newState = stateFnOrNewState;\n }\n if (currState === newState) {\n return undefined;\n }\n let state: S;\n if (this.isArray) {\n // when working with arrays we treat payload as full replacement; avoid copying currState\n state = (newState as unknown as S);\n } else {\n // shallow merge using Object.assign (faster than spread in hot paths)\n // create a new object to avoid mutating current state\n state = Object.assign({}, currState, newState) as S;\n }\n\n // If comparator is provided, use it to detect equality (avoids further work)\n if (this.comparator && this.comparator(currState, state)) {\n return undefined;\n }\n // avoid function call if not necessary\n this.devTool && this.devToolSend(state, actionName);\n this.storage && this.statePersist(state);\n return state;\n }\n\n /**\n * Replace state\n * @param newState state\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns state\n * @private\n */\n protected _replaceState(newState: S, actionName?: string): S | undefined;\n /**\n * Replace state\n * @param selectFn State reducer\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns state\n * @private\n */\n protected _replaceState(stateFn: NgSimpleStateReplaceState<S>, actionName?: string): S | undefined;\n /**\n * Replace state\n * @param stateFnOrReplaceState State reducer or state\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns state\n * @private\n */\n protected _replaceState(stateFnOrReplaceState: StateFnOrReplaceState<S>, actionName?: string): S | undefined;\n protected _replaceState(stateFnOrReplaceState: StateFnOrReplaceState<S>, actionName?: string): S | undefined {\n const currState = this.getCurrentState();\n let newState: S;\n if (typeof stateFnOrReplaceState === 'function') {\n newState = stateFnOrReplaceState(currState);\n } else {\n newState = stateFnOrReplaceState;\n }\n if (currState === newState) {\n return undefined;\n }\n // If comparator is provided, use it to detect equality (avoids further work)\n if (this.comparator && this.comparator(currState, newState)) {\n return undefined;\n }\n // avoid function call if not necessary\n this.devTool && this.devToolSend(newState, actionName);\n this.storage && this.statePersist(newState);\n return newState;\n }\n\n /**\n * Send to dev tool a new state\n * @param newState new state\n * @param actionName The action name\n * @returns True if dev tools are enabled\n */\n protected devToolSend(newState: S | undefined, actionName?: string): boolean {\n if (!this.devTool) {\n return false;\n }\n if (!actionName) {\n // retrieve the parent (of parent) method into the stack trace\n try {\n actionName = new Error().stack\n ?.split('\\n')[this.stackPoint]\n ?.trim()\n ?.split(' ')[1]\n ?.split('.')[1] || 'unknown';\n /* eslint-disable-next-line @typescript-eslint/no-unused-vars */\n } catch (_) {\n /* istanbul ignore next */\n actionName = 'unknown';\n }\n }\n if (!this.devTool.send(this.storeName, actionName, newState)) {\n /* istanbul ignore next */\n console.log(this.storeName + '.' + actionName, newState);\n }\n return true;\n }\n\n /**\n * Recursively Object.freeze simple Javascript structures consisting of plain objects, arrays, and primitives.\n * Make the data immutable.\n * @returns immutable object\n */\n protected deepFreeze(object: S): Readonly<S> {\n // No freezing in production (for better performance).\n if (!this.devMode || !object) {\n return object as Readonly<S>;\n }\n\n // When already frozen, we assume its children are frozen (for better performance).\n // This should be true if you always use `deepFreeze` to freeze objects.\n //\n // Note that Object.isFrozen will also return `true` for primitives (numbers,\n // strings, booleans, undefined, null), so there is no need to check for\n // those explicitly.\n if (Object.isFrozen(object)) {\n return object as Readonly<S>;\n }\n\n // At this point we know that we're dealing with either an array or plain object, so\n // just freeze it and recurse on its values.\n Object.freeze(object);\n /* eslint-disable @typescript-eslint/no-explicit-any */\n Object.keys(object).forEach(key => this.deepFreeze((object as any)[key]));\n\n return object as Readonly<S>;\n }\n\n /**\n * Persist state to storage\n */\n protected statePersist(state: S) {\n if (this.storage) {\n this.storage.setItem(this.storeName, state);\n }\n }\n}\n","import { Injectable, OnDestroy, Directive } from '@angular/core';\nimport { BehaviorSubject, Observable, asyncScheduler } from 'rxjs';\nimport { map, distinctUntilChanged, observeOn } from 'rxjs/operators';\nimport { NgSimpleStateBaseCommonStore } from '../ng-simple-state-common';\nimport type { NgSimpleStateComparator, NgSimpleStateReplaceState, NgSimpleStateSelectState, NgSimpleStateSetState, StateFnOrNewState, StateFnOrReplaceState } from '../ng-simple-state-models';\n\n@Injectable()\n@Directive()\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport abstract class NgSimpleStateBaseRxjsStore<S extends object | Array<any>> extends NgSimpleStateBaseCommonStore<S> implements OnDestroy {\n\n protected stackPoint: number = 4;\n private readonly state$: BehaviorSubject<S> = new BehaviorSubject<S>(this.firstState);\n private readonly stateObs: Observable<S> = this.state$.asObservable();\n\n /**\n * Return the observable of the state\n * @returns Observable of the state\n */\n public get state(): Observable<S> {\n return this.stateObs;\n }\n\n /**\n * When you override this method, you have to call the `super.ngOnDestroy()` method in your `ngOnDestroy()` method.\n */\n override ngOnDestroy(): void {\n super.ngOnDestroy();\n this.state$.complete();\n }\n\n /**\n * Select a store state\n * @param selectFn State selector (if not provided return full state)\n * @param comparator A function used to compare the previous and current state for equality. Defaults to a `===` check.\n * @returns Observable of the selected state\n */\n selectState<K = Partial<S>>(selectFn?: NgSimpleStateSelectState<S, K>, comparator?: NgSimpleStateComparator<K>): Observable<K> {\n if (!selectFn) {\n return this.stateObs as unknown as Observable<K>;\n }\n return this.state$.pipe(\n map(state => selectFn(state as Readonly<S>)),\n distinctUntilChanged(comparator ?? this.comparator as NgSimpleStateComparator),\n observeOn(asyncScheduler)\n );\n }\n\n /**\n * Return the current store state (snapshot)\n * @returns The current state\n */\n getCurrentState(): Readonly<S> {\n return this.devMode ? this.deepFreeze(this.state$.getValue()) : this.state$.getValue();\n }\n\n /**\n * Set a new state\n * @param newState New state\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n setState(newState: Partial<S>, actionName?: string): boolean;\n /**\n * Set a new state\n * @param selectFn State reducer\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n setState(stateFn: NgSimpleStateSetState<S>, actionName?: string): boolean;\n setState(stateFnOrNewState: StateFnOrNewState<S>, actionName?: string): boolean {\n const state = this._setState(stateFnOrNewState, actionName);\n if (typeof state !== 'undefined') {\n this.state$.next(state);\n return true;\n }\n return false;\n }\n\n /**\n * Replace state\n * @param newState New state\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n replaceState(newState: S, actionName?: string): boolean;\n /**\n * Replace state\n * @param selectFn State reducer\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n replaceState(stateFn: NgSimpleStateReplaceState<S>, actionName?: string): boolean;\n replaceState(stateFnOrNewState: StateFnOrReplaceState<S>, actionName?: string): boolean {\n const state = this._replaceState(stateFnOrNewState, actionName);\n if (typeof state !== 'undefined') {\n this.state$.next(state);\n return true;\n }\n return false;\n }\n}\n","import { Injectable, Directive, Signal, signal, computed, WritableSignal } from '@angular/core';\nimport { NgSimpleStateBaseCommonStore } from '../ng-simple-state-common';\nimport type { NgSimpleStateComparator, NgSimpleStateReplaceState, NgSimpleStateSelectState, NgSimpleStateSetState, StateFnOrNewState, StateFnOrReplaceState } from '../ng-simple-state-models';\n\n@Injectable()\n@Directive()\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport abstract class NgSimpleStateBaseSignalStore<S extends object | Array<any>> extends NgSimpleStateBaseCommonStore<S> {\n\n protected stackPoint: number = 4;\n private readonly stateSig: WritableSignal<S> = signal<S>(this.firstState);\n private readonly stateSigRo: Signal<S> = this.stateSig.asReadonly();\n\n /**\n * Return the Signal of the state\n * @returns Signal of the state\n */\n public get state(): Signal<S> {\n return this.stateSigRo;\n }\n\n /**\n * Select a store state\n * @param selectFn State selector (if not provided return full state)\n * @param comparator A function used to compare the previous and current state for equality. Defaults to a `===` check.\n * @returns Signal of the selected state\n */\n selectState<K = Partial<S>>(selectFn?: NgSimpleStateSelectState<S, K>, comparator?: NgSimpleStateComparator<K>): Signal<K> {\n if (!selectFn) {\n return this.stateSigRo as unknown as Signal<K>;\n }\n return computed(() => selectFn(this.stateSig() as Readonly<S>), { equal: comparator ?? this.comparator as NgSimpleStateComparator });\n }\n\n /**\n * Return the current store state (snapshot)\n * @returns The current state\n */\n getCurrentState(): Readonly<S> {\n return this.devMode ? this.deepFreeze(this.stateSig()) : this.stateSig();\n }\n\n /**\n * Set a new state\n * @param newState New state\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n setState(newState: Partial<S>, actionName?: string): boolean;\n /**\n * Set a new state\n * @param selectFn State reducer\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n setState(stateFn: NgSimpleStateSetState<S>, actionName?: string): boolean;\n setState(stateFnOrNewState: StateFnOrNewState<S>, actionName?: string): boolean {\n const state = this._setState(stateFnOrNewState, actionName);\n if (typeof state !== 'undefined') {\n this.stateSig.set(state);\n return true;\n }\n return false;\n }\n\n /**\n * Replace state\n * @param newState New state\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n replaceState(newState: S, actionName?: string): boolean;\n /**\n * Replace state\n * @param selectFn State reducer\n * @param actionName The action label into Redux DevTools (default is parent function name)\n * @returns True if the state is changed\n */\n replaceState(stateFn: NgSimpleStateReplaceState<S>, actionName?: string): boolean;\n replaceState(stateFnOrReplaceState: StateFnOrReplaceState<S>, actionName?: string): boolean {\n const state = this._replaceState(stateFnOrReplaceState, actionName);\n if (typeof state !== 'undefined') {\n this.stateSig.set(state);\n return true;\n }\n return false;\n }\n}\n","import { EnvironmentProviders, makeEnvironmentProviders } from \"@angular/core\";\r\nimport { NG_SIMPLE_STORE_CONFIG, NgSimpleStateConfig } from \"./ng-simple-state-models\";\r\n\r\n/**\r\n * Provide NgSimpleState with optional global configuration\r\n * @param {NgSimpleStateConfig} ngSimpleStateConfig \r\n * @returns {EnvironmentProviders[]}\r\n */\r\nexport function provideNgSimpleState(ngSimpleStateConfig?: NgSimpleStateConfig): EnvironmentProviders[] {\r\n if (ngSimpleStateConfig) {\r\n return [\r\n makeEnvironmentProviders([{\r\n provide: NG_SIMPLE_STORE_CONFIG,\r\n useValue: ngSimpleStateConfig,\r\n }])\r\n ];\r\n }\r\n return [];\r\n}\r\n","/*\r\n * Public API Surface of ng-simple-state\r\n */\r\nexport * from './lib/ng-simple-state.module';\r\nexport * from './lib/rxjs/ng-simple-state-base-store';\r\nexport * from './lib/signal/ng-simple-state-base-store';\r\nexport * from './lib/tool/ng-simple-state-dev-tool';\r\nexport * from './lib/storage/ng-simple-state-local-storage';\r\nexport * from './lib/storage/ng-simple-state-session-storage';\r\nexport * from './lib/ng-simple-state-models';\r\nexport * from './lib/ng-simple-state-common';\r\nexport * from './lib/ng-simple-state-provider';\r\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;AA+CA;;AAEG;MACU,sBAAsB,GAAG,IAAI,cAAc,CACpD,wBAAwB;;AC/C5B;MACa,mBAAmB,CAAA;IAC5B,OAAO,OAAO,CACV,mBAAyC,EAAA;QAEzC,OAAO;AACH,YAAA,QAAQ,EAAE,mBAAmB;AAC7B,YAAA,SAAS,EAAE;AACP,gBAAA;AACI,oBAAA,OAAO,EAAE,sBAAsB;AAC/B,oBAAA,QAAQ,EAAE,mBAAmB;AAChC,iBAAA;AACJ,aAAA;SACJ;;8GAZI,mBAAmB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,QAAA,EAAA,CAAA,CAAA;+GAAnB,mBAAmB,EAAA,CAAA,CAAA;+GAAnB,mBAAmB,EAAA,CAAA,CAAA;;2FAAnB,mBAAmB,EAAA,UAAA,EAAA,CAAA;kBAF/B;;;ACeD,MAAM,UAAU,GAAG,CAAmB,gBAAA,EAAA,IAAI,CAAC,GAAG,EAAE,CAAA,CAAA,EAAI,IAAI,CAAC,MAAM,EAAE,EAAE;MAGtD,oBAAoB,CAAA;AAM7B,IAAA,WAAA,GAAA;QAJiB,IAAc,CAAA,cAAA,GAAa,MAAM,CAAC,4BAA4B,IAAI,MAAM,CAAC,iBAAiB;QAE1F,IAAS,CAAA,SAAA,GAA2B,EAAE;AAGnD,QAAA,IAAI,IAAI,CAAC,cAAc,EAAE;;;;;AAKrB,YAAA,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EAAA,eAAA,EAAA,IAAA,EAAA,QAAA,EAAA,EAAA,EAAA,CAAA,CAAA;kHAA5B,4BAA4B,EAAA,CAAA,CAAA;;2FAA5B,4BAA4B,EAAA,UAAA,EAAA,CAAA;kBAHjD;;kBACA;;;ACFD;;;;AAIG;AACG,SAAU,oBAAoB,CAAC,mBAAyC,EAAA;IAC1E,IAAI,mBAAmB,EAAE;QACrB,OAAO;AACH,YAAA,wBAAwB,CAAC,CAAC;AACtB,oBAAA,OAAO,EAAE,sBAAsB;AAC/B,oBAAA,QAAQ,EAAE,mBAAmB;AAChC,iBAAA,CAAC;SACL;;AAEL,IAAA,OAAO,EAAE;AACb;;AClBA;;AAEG;;ACFH;;AAEG;;;;"}
|
package/index.d.ts
CHANGED
|
@@ -39,6 +39,7 @@ declare abstract class NgSimpleStateStorage<K = unknown> {
|
|
|
39
39
|
clear(): boolean;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
type NgSimpleStateReplaceState<S> = (currentState: Readonly<S>) => S;
|
|
42
43
|
type NgSimpleStateSetState<S> = (currentState: Readonly<S>) => Partial<S>;
|
|
43
44
|
type NgSimpleStateSelectState<S, K> = (state: Readonly<S>) => K;
|
|
44
45
|
type NgSimpleStateComparator<K = any> = (previous: K, current: K) => boolean;
|
|
@@ -81,6 +82,7 @@ interface NgSimpleStateStoreConfig<K = any> extends NgSimpleStateConfig<K> {
|
|
|
81
82
|
*/
|
|
82
83
|
declare const NG_SIMPLE_STORE_CONFIG: InjectionToken<NgSimpleStateConfig<any>>;
|
|
83
84
|
type StateFnOrNewState<S> = Partial<S> | NgSimpleStateSetState<S>;
|
|
85
|
+
type StateFnOrReplaceState<S> = S | NgSimpleStateReplaceState<S>;
|
|
84
86
|
|
|
85
87
|
declare class NgSimpleStateModule {
|
|
86
88
|
static forRoot(ngSimpleStateConfig?: NgSimpleStateConfig): ModuleWithProviders<NgSimpleStateModule>;
|
|
@@ -137,7 +139,6 @@ declare abstract class NgSimpleStateBaseCommonStore<S extends object | Array<unk
|
|
|
137
139
|
protected isArray: boolean;
|
|
138
140
|
protected devMode: boolean;
|
|
139
141
|
protected comparator?: NgSimpleStateComparator<S>;
|
|
140
|
-
protected readonly selectFnRef: <K>(tmpState: Readonly<S>) => K;
|
|
141
142
|
constructor();
|
|
142
143
|
/**
|
|
143
144
|
* When you override this method, you have to call the `super.ngOnDestroy()` method in your `ngOnDestroy()` method.
|
|
@@ -174,6 +175,20 @@ declare abstract class NgSimpleStateBaseCommonStore<S extends object | Array<unk
|
|
|
174
175
|
* @returns True if the state is changed
|
|
175
176
|
*/
|
|
176
177
|
abstract setState(stateFn: NgSimpleStateSetState<S>, actionName?: string): boolean;
|
|
178
|
+
/**
|
|
179
|
+
* Replace state
|
|
180
|
+
* @param newState New state
|
|
181
|
+
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
182
|
+
* @returns True if the state is changed
|
|
183
|
+
*/
|
|
184
|
+
abstract replaceState(newState: S, actionName?: string): boolean;
|
|
185
|
+
/**
|
|
186
|
+
* Replace state
|
|
187
|
+
* @param selectFn State reducer
|
|
188
|
+
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
189
|
+
* @returns True if the state is changed
|
|
190
|
+
*/
|
|
191
|
+
abstract replaceState(stateFn: NgSimpleStateReplaceState<S>, actionName?: string): boolean;
|
|
177
192
|
/**
|
|
178
193
|
* Return the current store state (snapshot)
|
|
179
194
|
* @returns The current state
|
|
@@ -201,23 +216,49 @@ declare abstract class NgSimpleStateBaseCommonStore<S extends object | Array<unk
|
|
|
201
216
|
* @param newState New state
|
|
202
217
|
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
203
218
|
* @returns state
|
|
219
|
+
* @private
|
|
204
220
|
*/
|
|
205
|
-
protected
|
|
221
|
+
protected _setState(newState: Partial<S>, actionName?: string): S | undefined;
|
|
206
222
|
/**
|
|
207
223
|
* Set a new state
|
|
208
224
|
* @param selectFn State reducer
|
|
209
225
|
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
210
226
|
* @returns state
|
|
227
|
+
* @private
|
|
211
228
|
*/
|
|
212
|
-
protected
|
|
229
|
+
protected _setState(stateFn: NgSimpleStateSetState<S>, actionName?: string): S | undefined;
|
|
213
230
|
/**
|
|
214
231
|
* Set a new state
|
|
215
232
|
* @param stateFnOrNewState State reducer or new state
|
|
216
233
|
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
217
234
|
* @returns state
|
|
235
|
+
* @private
|
|
236
|
+
*/
|
|
237
|
+
protected _setState(stateFnOrNewState: StateFnOrNewState<S>, actionName?: string): S | undefined;
|
|
238
|
+
/**
|
|
239
|
+
* Replace state
|
|
240
|
+
* @param newState state
|
|
241
|
+
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
242
|
+
* @returns state
|
|
243
|
+
* @private
|
|
244
|
+
*/
|
|
245
|
+
protected _replaceState(newState: S, actionName?: string): S | undefined;
|
|
246
|
+
/**
|
|
247
|
+
* Replace state
|
|
248
|
+
* @param selectFn State reducer
|
|
249
|
+
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
250
|
+
* @returns state
|
|
251
|
+
* @private
|
|
252
|
+
*/
|
|
253
|
+
protected _replaceState(stateFn: NgSimpleStateReplaceState<S>, actionName?: string): S | undefined;
|
|
254
|
+
/**
|
|
255
|
+
* Replace state
|
|
256
|
+
* @param stateFnOrReplaceState State reducer or state
|
|
257
|
+
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
258
|
+
* @returns state
|
|
259
|
+
* @private
|
|
218
260
|
*/
|
|
219
|
-
protected
|
|
220
|
-
protected selectFn<K>(tmpState: Readonly<S>): K;
|
|
261
|
+
protected _replaceState(stateFnOrReplaceState: StateFnOrReplaceState<S>, actionName?: string): S | undefined;
|
|
221
262
|
/**
|
|
222
263
|
* Send to dev tool a new state
|
|
223
264
|
* @param newState new state
|
|
@@ -279,6 +320,20 @@ declare abstract class NgSimpleStateBaseRxjsStore<S extends object | Array<any>>
|
|
|
279
320
|
* @returns True if the state is changed
|
|
280
321
|
*/
|
|
281
322
|
setState(stateFn: NgSimpleStateSetState<S>, actionName?: string): boolean;
|
|
323
|
+
/**
|
|
324
|
+
* Replace state
|
|
325
|
+
* @param newState New state
|
|
326
|
+
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
327
|
+
* @returns True if the state is changed
|
|
328
|
+
*/
|
|
329
|
+
replaceState(newState: S, actionName?: string): boolean;
|
|
330
|
+
/**
|
|
331
|
+
* Replace state
|
|
332
|
+
* @param selectFn State reducer
|
|
333
|
+
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
334
|
+
* @returns True if the state is changed
|
|
335
|
+
*/
|
|
336
|
+
replaceState(stateFn: NgSimpleStateReplaceState<S>, actionName?: string): boolean;
|
|
282
337
|
static ɵfac: i0.ɵɵFactoryDeclaration<NgSimpleStateBaseRxjsStore<any>, never>;
|
|
283
338
|
static ɵdir: i0.ɵɵDirectiveDeclaration<NgSimpleStateBaseRxjsStore<any>, never, never, {}, {}, never, never, true, never>;
|
|
284
339
|
static ɵprov: i0.ɵɵInjectableDeclaration<NgSimpleStateBaseRxjsStore<any>>;
|
|
@@ -319,6 +374,20 @@ declare abstract class NgSimpleStateBaseSignalStore<S extends object | Array<any
|
|
|
319
374
|
* @returns True if the state is changed
|
|
320
375
|
*/
|
|
321
376
|
setState(stateFn: NgSimpleStateSetState<S>, actionName?: string): boolean;
|
|
377
|
+
/**
|
|
378
|
+
* Replace state
|
|
379
|
+
* @param newState New state
|
|
380
|
+
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
381
|
+
* @returns True if the state is changed
|
|
382
|
+
*/
|
|
383
|
+
replaceState(newState: S, actionName?: string): boolean;
|
|
384
|
+
/**
|
|
385
|
+
* Replace state
|
|
386
|
+
* @param selectFn State reducer
|
|
387
|
+
* @param actionName The action label into Redux DevTools (default is parent function name)
|
|
388
|
+
* @returns True if the state is changed
|
|
389
|
+
*/
|
|
390
|
+
replaceState(stateFn: NgSimpleStateReplaceState<S>, actionName?: string): boolean;
|
|
322
391
|
static ɵfac: i0.ɵɵFactoryDeclaration<NgSimpleStateBaseSignalStore<any>, never>;
|
|
323
392
|
static ɵdir: i0.ɵɵDirectiveDeclaration<NgSimpleStateBaseSignalStore<any>, never, never, {}, {}, never, never, true, never>;
|
|
324
393
|
static ɵprov: i0.ɵɵInjectableDeclaration<NgSimpleStateBaseSignalStore<any>>;
|
|
@@ -332,7 +401,12 @@ declare class NgSimpleStateSessionStorage<K = unknown> extends NgSimpleStateStor
|
|
|
332
401
|
constructor(config?: NgSimpleStateStoreConfig<K>);
|
|
333
402
|
}
|
|
334
403
|
|
|
404
|
+
/**
|
|
405
|
+
* Provide NgSimpleState with optional global configuration
|
|
406
|
+
* @param {NgSimpleStateConfig} ngSimpleStateConfig
|
|
407
|
+
* @returns {EnvironmentProviders[]}
|
|
408
|
+
*/
|
|
335
409
|
declare function provideNgSimpleState(ngSimpleStateConfig?: NgSimpleStateConfig): EnvironmentProviders[];
|
|
336
410
|
|
|
337
411
|
export { NG_SIMPLE_STORE_CONFIG, NgSimpleStateBaseCommonStore, NgSimpleStateBaseRxjsStore, NgSimpleStateBaseSignalStore, NgSimpleStateDevTool, NgSimpleStateLocalStorage, NgSimpleStateModule, NgSimpleStateSessionStorage, provideNgSimpleState };
|
|
338
|
-
export type { NgSimpleStateComparator, NgSimpleStateConfig, NgSimpleStateSelectState, NgSimpleStateSetState, NgSimpleStateStoreConfig, StateFnOrNewState };
|
|
412
|
+
export type { NgSimpleStateComparator, NgSimpleStateConfig, NgSimpleStateReplaceState, NgSimpleStateSelectState, NgSimpleStateSetState, NgSimpleStateStoreConfig, StateFnOrNewState, StateFnOrReplaceState };
|