ngssm-store 22.1.0 → 22.2.1

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.
@@ -1,245 +1,196 @@
1
- import * as i0 from '@angular/core';
2
- import { InjectionToken, EnvironmentProviders, OnDestroy, Type, Signal } from '@angular/core';
3
- import { Observable } from 'rxjs';
4
-
5
- interface FeatureStateSpecification {
6
- readonly featureStateKey: string;
7
- readonly initialState: object;
8
- }
9
- declare const NGSSM_COMPONENT_WITH_FEATURE_STATE: InjectionToken<FeatureStateSpecification>;
10
-
11
- declare const provideNgssmFeatureState: (featureStateKey: string, initialValue: object) => EnvironmentProviders;
12
-
13
- declare class ProvideNgssmFeatureStateDirective implements OnDestroy {
14
- private readonly component;
15
- private store;
16
- constructor();
17
- ngOnDestroy(): void;
18
- static ɵfac: i0.ɵɵFactoryDeclaration<ProvideNgssmFeatureStateDirective, never>;
19
- static ɵdir: i0.ɵɵDirectiveDeclaration<ProvideNgssmFeatureStateDirective, "[provideNgssmFeatureState]", never, {}, {}, never, never, true, never>;
20
- }
21
-
22
- interface Action {
23
- type: string;
24
- }
25
-
26
- type State = Record<string, object>;
27
-
28
- interface Reducer {
29
- processedActions: string[];
30
- updateState(state: State, action: Action): State;
31
- }
32
- declare const NGSSM_REDUCER: InjectionToken<Reducer>;
33
- declare const provideReducer: (reducer: Type<unknown>) => EnvironmentProviders;
34
- declare const provideReducers: (...reducers: Type<unknown>[]) => EnvironmentProviders;
35
-
36
- declare class FeatureStateReducer implements Reducer {
37
- readonly processedActions: string[];
38
- updateState(state: State, action: Action): State;
39
- static ɵfac: i0.ɵɵFactoryDeclaration<FeatureStateReducer, never>;
40
- static ɵprov: i0.ɵɵInjectableDeclaration<FeatureStateReducer>;
41
- }
42
-
43
- interface ActionDispatcher {
44
- dispatchAction(action: Action): void;
45
- dispatchActionType(type: string): void;
46
- }
47
-
48
- declare const NgSsmFeatureState: (specification: FeatureStateSpecification) => (target: object) => void;
1
+ import * as i0 from "@angular/core";
2
+ import { EnvironmentProviders, InjectionToken, OnDestroy, Signal, Type } from "@angular/core";
3
+ import { Observable } from "rxjs";
4
+ export interface FeatureStateSpecification {
5
+ readonly featureStateKey: string;
6
+ readonly initialState: object;
7
+ }
8
+ export declare const NGSSM_COMPONENT_WITH_FEATURE_STATE: InjectionToken<FeatureStateSpecification>;
9
+ export declare const provideNgssmFeatureState: (featureStateKey: string, initialValue: object) => EnvironmentProviders;
10
+ export declare class ProvideNgssmFeatureStateDirective implements OnDestroy {
11
+ private readonly component;
12
+ private store;
13
+ constructor();
14
+ ngOnDestroy(): void;
15
+ static ɵfac: i0.ɵɵFactoryDeclaration<ProvideNgssmFeatureStateDirective, never>;
16
+ static ɵdir: i0.ɵɵDirectiveDeclaration<ProvideNgssmFeatureStateDirective, "[provideNgssmFeatureState]", never, {}, {}, never, never, true, never>;
17
+ }
18
+ export interface Action {
19
+ type: string;
20
+ }
21
+ export type State = Record<string, object>;
22
+ export interface Reducer {
23
+ processedActions: string[];
24
+ updateState(state: State, action: Action): State;
25
+ }
26
+ export declare const NGSSM_REDUCER: InjectionToken<Reducer>;
27
+ export declare const provideReducer: (reducer: Type<unknown>) => EnvironmentProviders;
28
+ export declare const provideReducers: (...reducers: Type<unknown>[]) => EnvironmentProviders;
29
+ export declare class FeatureStateReducer implements Reducer {
30
+ readonly processedActions: string[];
31
+ updateState(state: State, action: Action): State;
32
+ static ɵfac: i0.ɵɵFactoryDeclaration<FeatureStateReducer, never>;
33
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
34
+ }
35
+ export interface ActionDispatcher {
36
+ dispatchAction(action: Action): void;
37
+ dispatchActionType(type: string): void;
38
+ }
39
+ export declare const NgSsmFeatureState: (specification: FeatureStateSpecification) => (target: object) => void;
49
40
  /**
50
41
  * The `Store` class is a centralized state management system for Angular applications.
51
42
  * It manages the application state, processes actions using reducers, and handles side effects using effects.
52
- * The class integrates both RxJS (`BehaviorSubject`) and Angular signals for reactive state management.
43
+ * The class exposes Angular signals for reactive state management.
53
44
  *
54
45
  * ### Features:
55
46
  * - Centralized state management with support for reducers and effects.
56
- * - Reactive state updates using both RxJS and Angular signals.
47
+ * - Reactive state updates using Angular signals.
57
48
  * - Modular initialization of feature states, reducers, and effects.
58
49
  * - Sequential action processing with an action queue.
59
50
  * - Logging for debugging and monitoring state changes and action processing.
60
51
  *
61
52
  * ### Usage:
62
53
  * - Dispatch actions using `dispatchAction` or `dispatchActionType`.
63
- * - Subscribe to state updates using `state$` (RxJS) or `state` (Angular signal).
54
+ * - Read state updates using `state` (Angular signal).
64
55
  */
65
- declare class Store implements ActionDispatcher {
66
- useMacroTasks: boolean;
67
- forceChangeDetectionAfterActionProcessed: boolean;
68
- private readonly logger;
69
- private readonly reducers;
70
- private readonly effects;
71
- private readonly initializers;
72
- private readonly injector;
73
- private readonly applicationRef;
74
- private readonly _state$;
75
- private readonly actionQueue;
76
- private readonly reducersPerActionType;
77
- private readonly effectsPerActionType;
78
- private readonly _stateSignal;
79
- private readonly _processedAction;
80
- private readonly _processedAction$;
81
- /**
82
- * Initializes the `Store` with reducers, effects, and state initializers.
83
- * Also sets up the initial state and registers reducers and effects.
84
- */
85
- constructor();
86
- /**
87
- * Returns the current state as an RxJS observable.
88
- * Useful for subscribing to state changes in a reactive manner.
89
- */
90
- get state$(): Observable<State>;
91
- /**
92
- * Returns the most recently action processed by reducers as an Angular signal.
93
- * Useful for accessing the last processed action in a reactive manner.
94
- * This signal is updated before processing the effects.
95
- */
96
- get processedAction(): Signal<Action>;
97
- /**
98
- * Returns the most recently action processed by reducers as an observale.
99
- * Useful for accessing the last processed action in a reactive manner.
100
- * This signal is updated before processing the effects.
101
- */
102
- get processedAction$(): Observable<Action>;
103
- /**
104
- * Returns the current state as an Angular signal.
105
- * Useful for signal-based reactivity in Angular components.
106
- */
107
- get state(): Signal<State>;
108
- /**
109
- * Dispatches an action to the store.
110
- * The action is added to the action queue and processed sequentially.
111
- *
112
- * @param action - The action to dispatch.
113
- */
114
- dispatchAction(action: Action): void;
115
- /**
116
- * Dispatches an action by its type.
117
- * This is a shorthand for dispatching actions without additional payload.
118
- *
119
- * @param type - The type of the action to dispatch.
120
- */
121
- dispatchActionType(type: string): void;
122
- /**
123
- * Processes the next action in the action queue.
124
- * Applies reducers to update the state and executes effects for side effects.
125
- */
126
- private processNextAction;
127
- /**
128
- * Applies reducers to the current state based on the dispatched action.
129
- * Updates the state if there are changes and sets the processed action signal.
130
- *
131
- * @param nextAction - The action being processed.
132
- * @returns The updated state after applying reducers.
133
- */
134
- private applyReducers;
135
- /**
136
- * Executes an effect for a given action.
137
- * Handles any errors that occur during effect execution.
138
- *
139
- * @param effect - The effect to execute.
140
- * @param updatedState - The updated state after reducers have been applied.
141
- * @param nextAction - The action being processed.
142
- */
143
- private runEffect;
144
- /**
145
- * Initializes reducers or effects and maps them to their corresponding action types.
146
- *
147
- * @param processors - The array of reducers or effects to initialize.
148
- * @param processorMap - The map to store processors by action type.
149
- * @param getProcessedActions - A function to retrieve the action types processed by a processor.
150
- */
151
- private initializeProcessors;
152
- private addTaskForNextAction;
153
- static ɵfac: i0.ɵɵFactoryDeclaration<Store, never>;
154
- static ɵprov: i0.ɵɵInjectableDeclaration<Store>;
155
- }
156
-
157
- type EffectFunc = (state: State, action: Action) => void;
158
- interface Effect {
159
- isFunc?: boolean;
160
- processedActions: string[];
161
- processAction(actiondispatcher: ActionDispatcher, state: State, action: Action): void;
162
- }
163
- declare const NGSSM_EFFECT: InjectionToken<Effect>;
164
- declare const provideEffect: (effect: Type<unknown>) => EnvironmentProviders;
165
- declare const provideEffects: (...effects: Type<unknown>[]) => EnvironmentProviders;
166
- declare const provideEffectFunc: (actionType: string, effectFunc: EffectFunc) => EnvironmentProviders;
167
-
168
- declare class NgSsmComponent implements OnDestroy {
169
- protected store: Store;
170
- private readonly _unsubscribeAll$;
171
- protected get unsubscribeAll$(): Observable<void>;
172
- ngOnDestroy(): void;
173
- watch<T>(selector: (state: State) => T): Observable<T>;
174
- dispatchAction(action: Action): void;
175
- dispatchActionType(actionType: string): void;
176
- static ɵfac: i0.ɵɵFactoryDeclaration<NgSsmComponent, never>;
177
- static ɵdir: i0.ɵɵDirectiveDeclaration<NgSsmComponent, never, never, {}, {}, never, never, true, never>;
178
- }
179
-
180
- interface StateInitializer {
181
- initializeState(state: State): State;
182
- }
183
- declare const NGSSM_STATE_INITIALIZER: InjectionToken<StateInitializer>;
184
-
185
- declare enum LogLevel {
186
- debug = "Debug",
187
- information = "Information",
188
- error = "Error"
189
- }
190
-
191
- interface LogEvent {
192
- level: LogLevel;
193
- message: string;
194
- payload?: unknown;
195
- }
196
-
197
- declare class Logger {
198
- private readonly _logEvents$;
199
- get logEvents$(): Observable<LogEvent>;
200
- debug(message: string, payload?: unknown): void;
201
- information(message: string, payload?: unknown): void;
202
- error(message: string, payload?: unknown): void;
203
- log(level: LogLevel, message: string, payload?: unknown): void;
204
- static ɵfac: i0.ɵɵFactoryDeclaration<Logger, never>;
205
- static ɵprov: i0.ɵɵInjectableDeclaration<Logger>;
206
- }
207
-
208
- declare class ConsoleAppender {
209
- private logger;
210
- private readonly stopEvent$;
211
- start(contextName?: string): void;
212
- stop(): void;
213
- static ɵfac: i0.ɵɵFactoryDeclaration<ConsoleAppender, never>;
214
- static ɵprov: i0.ɵɵInjectableDeclaration<ConsoleAppender>;
215
- }
216
-
217
- declare const NGSSM_CONSOLE_APPENDER_NAME: InjectionToken<string>;
218
- declare const startConsoleAppenderFactory: () => (() => void);
219
- declare const provideConsoleAppender: (name: string) => EnvironmentProviders;
220
-
221
- declare enum NgssmStoreActionType {
222
- registerFeatureState = "[NgssmStoreActionType] registerFeatureState",
223
- unregisterFeatureState = "[NgssmStoreActionType] unregisterFeatureState"
224
- }
225
-
226
- declare class NgssmRegisterFeatureStateAction implements Action {
227
- readonly featureStateKey: string;
228
- readonly initialValue: object;
229
- readonly type: string;
230
- constructor(featureStateKey: string, initialValue: object);
231
- }
232
-
233
- declare class NgssmUnregisterFeatureStateAction implements Action {
234
- readonly featureStateKey: string;
235
- readonly type: string;
236
- constructor(featureStateKey: string);
237
- }
238
-
239
- declare const ACTION_DISPATCHER: InjectionToken<ActionDispatcher>;
240
- declare const provideNgssmStore: () => EnvironmentProviders;
241
-
242
- declare const createSignal: <T = unknown>(selector: (state: State) => T) => Signal<T>;
243
-
244
- export { ACTION_DISPATCHER, ConsoleAppender, FeatureStateReducer, LogLevel, Logger, NGSSM_COMPONENT_WITH_FEATURE_STATE, NGSSM_CONSOLE_APPENDER_NAME, NGSSM_EFFECT, NGSSM_REDUCER, NGSSM_STATE_INITIALIZER, NgSsmComponent, NgSsmFeatureState, NgssmRegisterFeatureStateAction, NgssmStoreActionType, NgssmUnregisterFeatureStateAction, ProvideNgssmFeatureStateDirective, Store, createSignal, provideConsoleAppender, provideEffect, provideEffectFunc, provideEffects, provideNgssmFeatureState, provideNgssmStore, provideReducer, provideReducers, startConsoleAppenderFactory };
245
- export type { Action, ActionDispatcher, Effect, EffectFunc, FeatureStateSpecification, LogEvent, Reducer, State, StateInitializer };
56
+ export declare class Store implements ActionDispatcher {
57
+ useMacroTasks: boolean;
58
+ forceChangeDetectionAfterActionProcessed: boolean;
59
+ private readonly logger;
60
+ private readonly reducers;
61
+ private readonly effects;
62
+ private readonly initializers;
63
+ private readonly injector;
64
+ private readonly applicationRef;
65
+ private readonly actionQueue;
66
+ private readonly reducersPerActionType;
67
+ private readonly effectsPerActionType;
68
+ private readonly _stateSignal;
69
+ private readonly _processedAction;
70
+ /**
71
+ * Initializes the `Store` with reducers, effects, and state initializers.
72
+ * Also sets up the initial state and registers reducers and effects.
73
+ */
74
+ constructor();
75
+ /**
76
+ * Returns the most recently action processed by reducers as an Angular signal.
77
+ * Useful for accessing the last processed action in a reactive manner.
78
+ * This signal is updated before processing the effects.
79
+ */
80
+ get processedAction(): Signal<Action>;
81
+ /**
82
+ * Returns the current state as an Angular signal.
83
+ * Useful for signal-based reactivity in Angular components.
84
+ */
85
+ get state(): Signal<State>;
86
+ /**
87
+ * Dispatches an action to the store.
88
+ * The action is added to the action queue and processed sequentially.
89
+ *
90
+ * @param action - The action to dispatch.
91
+ */
92
+ dispatchAction(action: Action): void;
93
+ /**
94
+ * Dispatches an action by its type.
95
+ * This is a shorthand for dispatching actions without additional payload.
96
+ *
97
+ * @param type - The type of the action to dispatch.
98
+ */
99
+ dispatchActionType(type: string): void;
100
+ /**
101
+ * Processes the next action in the action queue.
102
+ * Applies reducers to update the state and executes effects for side effects.
103
+ */
104
+ private processNextAction;
105
+ /**
106
+ * Applies reducers to the current state based on the dispatched action.
107
+ * Updates the state if there are changes and sets the processed action signal.
108
+ *
109
+ * @param nextAction - The action being processed.
110
+ * @returns The updated state after applying reducers.
111
+ */
112
+ private applyReducers;
113
+ /**
114
+ * Executes an effect for a given action.
115
+ * Handles any errors that occur during effect execution.
116
+ *
117
+ * @param effect - The effect to execute.
118
+ * @param updatedState - The updated state after reducers have been applied.
119
+ * @param nextAction - The action being processed.
120
+ */
121
+ private runEffect;
122
+ /**
123
+ * Initializes reducers or effects and maps them to their corresponding action types.
124
+ *
125
+ * @param processors - The array of reducers or effects to initialize.
126
+ * @param processorMap - The map to store processors by action type.
127
+ * @param getProcessedActions - A function to retrieve the action types processed by a processor.
128
+ */
129
+ private initializeProcessors;
130
+ private addTaskForNextAction;
131
+ static ɵfac: i0.ɵɵFactoryDeclaration<Store, never>;
132
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
133
+ }
134
+ export type EffectFunc<TActionType extends Action = Action> = (state: State, action: TActionType) => void;
135
+ export interface Effect {
136
+ isFunc?: boolean;
137
+ processedActions: string[];
138
+ processAction(actiondispatcher: ActionDispatcher, state: State, action: Action): void;
139
+ }
140
+ export declare const NGSSM_EFFECT: InjectionToken<Effect>;
141
+ export declare const provideEffect: (effect: Type<unknown>) => EnvironmentProviders;
142
+ export declare const provideEffects: (...effects: Type<unknown>[]) => EnvironmentProviders;
143
+ export declare const provideEffectFunc: <TActionType extends Action = Action>(actionType: string, effectFunc: EffectFunc<TActionType>) => EnvironmentProviders;
144
+ export interface StateInitializer {
145
+ initializeState(state: State): State;
146
+ }
147
+ export declare const NGSSM_STATE_INITIALIZER: InjectionToken<StateInitializer>;
148
+ export declare enum LogLevel {
149
+ debug = "Debug",
150
+ information = "Information",
151
+ error = "Error"
152
+ }
153
+ export interface LogEvent {
154
+ level: LogLevel;
155
+ message: string;
156
+ payload?: unknown;
157
+ }
158
+ export declare class Logger {
159
+ private readonly _logEvents$;
160
+ get logEvents$(): Observable<LogEvent>;
161
+ debug(message: string, payload?: unknown): void;
162
+ information(message: string, payload?: unknown): void;
163
+ error(message: string, payload?: unknown): void;
164
+ log(level: LogLevel, message: string, payload?: unknown): void;
165
+ static ɵfac: i0.ɵɵFactoryDeclaration<Logger, never>;
166
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
167
+ }
168
+ export declare class ConsoleAppender {
169
+ private logger;
170
+ private readonly stopEvent$;
171
+ start(contextName?: string): void;
172
+ stop(): void;
173
+ static ɵfac: i0.ɵɵFactoryDeclaration<ConsoleAppender, never>;
174
+ static ɵprov: i0.ɵɵInjectableDeclaration<any>;
175
+ }
176
+ export declare const NGSSM_CONSOLE_APPENDER_NAME: InjectionToken<string>;
177
+ export declare const startConsoleAppenderFactory: () => (() => void);
178
+ export declare const provideConsoleAppender: (name: string) => EnvironmentProviders;
179
+ export declare enum NgssmStoreActionType {
180
+ registerFeatureState = "[NgssmStoreActionType] registerFeatureState",
181
+ unregisterFeatureState = "[NgssmStoreActionType] unregisterFeatureState"
182
+ }
183
+ export declare class NgssmRegisterFeatureStateAction implements Action {
184
+ readonly featureStateKey: string;
185
+ readonly initialValue: object;
186
+ readonly type: string;
187
+ constructor(featureStateKey: string, initialValue: object);
188
+ }
189
+ export declare class NgssmUnregisterFeatureStateAction implements Action {
190
+ readonly featureStateKey: string;
191
+ readonly type: string;
192
+ constructor(featureStateKey: string);
193
+ }
194
+ export declare const ACTION_DISPATCHER: InjectionToken<ActionDispatcher>;
195
+ export declare const provideNgssmStore: () => EnvironmentProviders;
196
+ export declare const createSignal: <T = unknown>(selector: (state: State) => T) => Signal<T>;