@angular-architects/ngrx-toolkit 0.0.4 → 0.0.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 +208 -24
- package/esm2022/index.mjs +4 -1
- package/esm2022/lib/redux-connector/create-redux.mjs +41 -0
- package/esm2022/lib/redux-connector/index.mjs +2 -0
- package/esm2022/lib/redux-connector/model.mjs +2 -0
- package/esm2022/lib/redux-connector/rxjs-interop/index.mjs +2 -0
- package/esm2022/lib/redux-connector/rxjs-interop/redux-method.mjs +22 -0
- package/esm2022/lib/redux-connector/signal-redux-store.mjs +43 -0
- package/esm2022/lib/redux-connector/util.mjs +13 -0
- package/esm2022/lib/with-call-state.mjs +1 -1
- package/esm2022/lib/with-redux.mjs +2 -2
- package/esm2022/lib/with-storage-sync.mjs +56 -0
- package/fesm2022/angular-architects-ngrx-toolkit.mjs +182 -19
- package/fesm2022/angular-architects-ngrx-toolkit.mjs.map +1 -1
- package/index.d.ts +3 -0
- package/lib/redux-connector/create-redux.d.ts +13 -0
- package/lib/redux-connector/index.d.ts +1 -0
- package/lib/redux-connector/model.d.ts +36 -0
- package/lib/redux-connector/rxjs-interop/index.d.ts +1 -0
- package/lib/redux-connector/rxjs-interop/redux-method.d.ts +11 -0
- package/lib/redux-connector/signal-redux-store.d.ts +11 -0
- package/lib/redux-connector/util.d.ts +5 -0
- package/lib/with-call-state.d.ts +4 -3
- package/lib/with-redux.d.ts +2 -2
- package/lib/with-storage-sync.d.ts +58 -0
- package/package.json +6 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ActionCreator, ActionType } from "@ngrx/store/src/models";
|
|
2
|
+
import { CreateReduxState, MapperTypes, Store } from "./model";
|
|
3
|
+
export declare function mapAction<Creators extends readonly ActionCreator[]>(...args: [
|
|
4
|
+
...creators: Creators,
|
|
5
|
+
storeMethod: (action: ActionType<Creators[number]>) => unknown
|
|
6
|
+
]): MapperTypes<Creators>;
|
|
7
|
+
export declare function mapAction<Creators extends readonly ActionCreator[], T>(...args: [
|
|
8
|
+
...creators: Creators,
|
|
9
|
+
storeMethod: (action: ActionType<Creators[number]>, resultMethod: (input: T) => unknown) => unknown,
|
|
10
|
+
resultMethod: (input: T) => unknown
|
|
11
|
+
]): MapperTypes<Creators>;
|
|
12
|
+
export declare function withActionMappers(...mappers: MapperTypes<ActionCreator<any, any>[]>[]): MapperTypes<ActionCreator<any, any>[]>[];
|
|
13
|
+
export declare function createReduxState<StoreName extends string, STORE extends Store>(storeName: StoreName, signalStore: STORE, withActionMappers: (store: InstanceType<STORE>) => MapperTypes<ActionCreator<any, any>[]>[]): CreateReduxState<StoreName, STORE>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { createReduxState, mapAction, withActionMappers } from './create-redux';
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { EnvironmentProviders, Signal, Type } from "@angular/core";
|
|
2
|
+
import { DeepSignal } from "@ngrx/signals/src/deep-signal";
|
|
3
|
+
import { SignalStoreFeatureResult } from "@ngrx/signals/src/signal-store-models";
|
|
4
|
+
import { StateSignal } from "@ngrx/signals/src/state-signal";
|
|
5
|
+
import { Action, ActionCreator, ActionType, Prettify } from "@ngrx/store/src/models";
|
|
6
|
+
import { Observable, Unsubscribable } from "rxjs";
|
|
7
|
+
export type IncludePropType<T, V, WithNevers = {
|
|
8
|
+
[K in keyof T]: Exclude<T[K], undefined> extends V ? T[K] extends Record<string, unknown> ? IncludePropType<T[K], V> : T[K] : never;
|
|
9
|
+
}> = Prettify<Pick<WithNevers, {
|
|
10
|
+
[K in keyof WithNevers]: WithNevers[K] extends never ? never : K extends string ? K : never;
|
|
11
|
+
}[keyof WithNevers]>>;
|
|
12
|
+
export type Store = Type<Record<string, unknown> & StateSignal<SignalStoreFeatureResult['state']>>;
|
|
13
|
+
export type CreateReduxState<StoreName extends string, STORE extends Store> = {
|
|
14
|
+
[K in StoreName as `provide${Capitalize<K>}Store`]: (connectReduxDevtools?: boolean) => EnvironmentProviders;
|
|
15
|
+
} & {
|
|
16
|
+
[K in StoreName as `inject${Capitalize<K>}Store`]: () => InjectableReduxSlice<STORE>;
|
|
17
|
+
};
|
|
18
|
+
export type Selectors<STORE extends Store> = IncludePropType<InstanceType<STORE>, Signal<unknown> | DeepSignal<unknown>>;
|
|
19
|
+
export type Dispatch = {
|
|
20
|
+
dispatch: (input: Action | Observable<Action> | Signal<Action>) => Unsubscribable;
|
|
21
|
+
};
|
|
22
|
+
export type InjectableReduxSlice<STORE extends Store> = Selectors<STORE> & Dispatch;
|
|
23
|
+
export type ExtractActionTypes<Creators extends readonly ActionCreator[]> = {
|
|
24
|
+
[Key in keyof Creators]: Creators[Key] extends ActionCreator<infer T> ? T : never;
|
|
25
|
+
};
|
|
26
|
+
export interface ActionMethod<T, V extends Action = Action> {
|
|
27
|
+
(action: V): T;
|
|
28
|
+
}
|
|
29
|
+
export interface StoreMethod<Creators extends readonly ActionCreator[], ResultState = unknown> {
|
|
30
|
+
(action: ActionType<Creators[number]>): ResultState;
|
|
31
|
+
}
|
|
32
|
+
export interface MapperTypes<Creators extends readonly ActionCreator[]> {
|
|
33
|
+
types: ExtractActionTypes<Creators>;
|
|
34
|
+
storeMethod: StoreMethod<Creators>;
|
|
35
|
+
resultMethod?: (...args: unknown[]) => unknown;
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { reduxMethod } from './redux-method';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Injector, Signal } from "@angular/core";
|
|
2
|
+
import { Observable, Unsubscribable } from "rxjs";
|
|
3
|
+
type RxMethodInput<Input> = Input | Observable<Input> | Signal<Input>;
|
|
4
|
+
type RxMethod<Input, MethodInput = Input, MethodResult = unknown> = ((input: RxMethodInput<Input>, resultMethod: (input: MethodInput) => MethodResult) => Unsubscribable) & Unsubscribable;
|
|
5
|
+
export declare function reduxMethod<Input, MethodInput = Input>(generator: (source$: Observable<Input>) => Observable<MethodInput>, config?: {
|
|
6
|
+
injector?: Injector;
|
|
7
|
+
}): RxMethod<Input, MethodInput>;
|
|
8
|
+
export declare function reduxMethod<Input, MethodInput = Input, MethodResult = unknown>(generator: (source$: Observable<Input>) => Observable<MethodInput>, resultMethod: (input: MethodInput) => MethodResult, config?: {
|
|
9
|
+
injector?: Injector;
|
|
10
|
+
}): RxMethod<Input, MethodInput, MethodResult>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Action, ActionCreator } from "@ngrx/store";
|
|
2
|
+
import { MapperTypes } from "./model";
|
|
3
|
+
import * as i0 from "@angular/core";
|
|
4
|
+
export declare class SignalReduxStore {
|
|
5
|
+
private mapperDict;
|
|
6
|
+
dispatch: ((input: Action | import("rxjs").Observable<Action> | import("@angular/core").Signal<Action>) => import("rxjs").Unsubscribable) & import("rxjs").Unsubscribable;
|
|
7
|
+
connectFeatureStore(mappers: MapperTypes<ActionCreator<any, any>[]>[]): void;
|
|
8
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SignalReduxStore, never>;
|
|
9
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<SignalReduxStore>;
|
|
10
|
+
}
|
|
11
|
+
export declare function injectReduxDispatch(): ((input: Action | import("rxjs").Observable<Action> | import("@angular/core").Signal<Action>) => import("rxjs").Unsubscribable) & import("rxjs").Unsubscribable;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Action } from '@ngrx/store';
|
|
2
|
+
import { Unsubscribable } from 'rxjs';
|
|
3
|
+
export declare function isUnsubscribable<F extends (...args: unknown[]) => unknown>(fn: F | (F & Unsubscribable)): fn is F & Unsubscribable;
|
|
4
|
+
export declare function capitalize(str: string): string;
|
|
5
|
+
export declare function isActionCreator(action: any): action is Action;
|
package/lib/with-call-state.d.ts
CHANGED
|
@@ -22,6 +22,7 @@ export type CallStateSignals = {
|
|
|
22
22
|
loaded: Signal<boolean>;
|
|
23
23
|
error: Signal<string | null>;
|
|
24
24
|
};
|
|
25
|
+
export type SetCallState<Prop extends string | undefined> = Prop extends string ? NamedCallStateSlice<Prop> : CallStateSlice;
|
|
25
26
|
export declare function getCallStateKeys(config?: {
|
|
26
27
|
collection?: string;
|
|
27
28
|
}): {
|
|
@@ -50,6 +51,6 @@ export declare function withCallState(): SignalStoreFeature<{
|
|
|
50
51
|
signals: CallStateSignals;
|
|
51
52
|
methods: Emtpy;
|
|
52
53
|
}>;
|
|
53
|
-
export declare function setLoading<Prop extends string>(prop?: Prop):
|
|
54
|
-
export declare function setLoaded<Prop extends string>(prop?: Prop):
|
|
55
|
-
export declare function setError<Prop extends string>(error: unknown, prop?: Prop):
|
|
54
|
+
export declare function setLoading<Prop extends string | undefined = undefined>(prop?: Prop): SetCallState<Prop>;
|
|
55
|
+
export declare function setLoaded<Prop extends string | undefined = undefined>(prop?: Prop): SetCallState<Prop>;
|
|
56
|
+
export declare function setError<Prop extends string | undefined = undefined>(error: unknown, prop?: Prop): SetCallState<Prop>;
|
package/lib/with-redux.d.ts
CHANGED
|
@@ -29,10 +29,10 @@ type PublicActionFns<Spec extends ActionsFnSpecs> = Spec extends {
|
|
|
29
29
|
export declare function payload<Type extends Payload>(): Type;
|
|
30
30
|
export declare const noPayload: {};
|
|
31
31
|
/** Reducer **/
|
|
32
|
-
type ReducerFunction<ReducerAction, State> = (action: ActionFnPayload<ReducerAction
|
|
32
|
+
type ReducerFunction<ReducerAction, State> = (state: State, action: ActionFnPayload<ReducerAction>) => void;
|
|
33
33
|
type ReducerFactory<StateActionFns extends ActionFns, State> = (actions: StateActionFns, on: <ReducerAction extends {
|
|
34
34
|
type: string;
|
|
35
|
-
}>(action: ReducerAction, reducerFn: ReducerFunction<
|
|
35
|
+
}>(action: ReducerAction, reducerFn: ReducerFunction<ReducerAction, State>) => void) => void;
|
|
36
36
|
/** Effect **/
|
|
37
37
|
type EffectsFactory<StateActionFns extends ActionFns> = (actions: StateActionFns, create: <EffectAction extends {
|
|
38
38
|
type: string;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { SignalStoreFeature } from '@ngrx/signals';
|
|
2
|
+
import { Emtpy } from './shared/empty';
|
|
3
|
+
type SignalStoreFeatureInput<State> = Pick<Parameters<SignalStoreFeature>[0], 'signals' | 'methods'> & {
|
|
4
|
+
state: State;
|
|
5
|
+
};
|
|
6
|
+
type WithStorageSyncFeatureResult = {
|
|
7
|
+
state: Emtpy;
|
|
8
|
+
signals: Emtpy;
|
|
9
|
+
methods: {
|
|
10
|
+
clearStorage(): void;
|
|
11
|
+
readFromStorage(): void;
|
|
12
|
+
writeToStorage(): void;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export type SyncConfig<State> = {
|
|
16
|
+
/**
|
|
17
|
+
* The key which is used to access the storage.
|
|
18
|
+
*/
|
|
19
|
+
key: string;
|
|
20
|
+
/**
|
|
21
|
+
* Flag indicating if the store should read from storage on init and write to storage on every state change.
|
|
22
|
+
*
|
|
23
|
+
* `true` by default
|
|
24
|
+
*/
|
|
25
|
+
autoSync?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Function to select that portion of the state which should be stored.
|
|
28
|
+
*
|
|
29
|
+
* Returns the whole state object by default
|
|
30
|
+
*/
|
|
31
|
+
select?: (state: State) => Partial<State>;
|
|
32
|
+
/**
|
|
33
|
+
* Function used to parse the state coming from storage.
|
|
34
|
+
*
|
|
35
|
+
* `JSON.parse()` by default
|
|
36
|
+
*/
|
|
37
|
+
parse?: (stateString: string) => State;
|
|
38
|
+
/**
|
|
39
|
+
* Function used to tranform the state into a string representation.
|
|
40
|
+
*
|
|
41
|
+
* `JSON.stringify()` by default
|
|
42
|
+
*/
|
|
43
|
+
stringify?: (state: State) => string;
|
|
44
|
+
/**
|
|
45
|
+
* Factory function used to select the storage.
|
|
46
|
+
*
|
|
47
|
+
* `localstorage` by default
|
|
48
|
+
*/
|
|
49
|
+
storage?: () => Storage;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Enables store synchronization with storage.
|
|
53
|
+
*
|
|
54
|
+
* Only works on browser platform.
|
|
55
|
+
*/
|
|
56
|
+
export declare function withStorageSync<State extends object, Input extends SignalStoreFeatureInput<State>>(key: string): SignalStoreFeature<Input, WithStorageSyncFeatureResult>;
|
|
57
|
+
export declare function withStorageSync<State extends object, Input extends SignalStoreFeatureInput<State>>(config: SyncConfig<Input['state']>): SignalStoreFeature<Input, WithStorageSyncFeatureResult>;
|
|
58
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@angular-architects/ngrx-toolkit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "GitHub",
|
|
7
|
+
"url": "https://github.com/angular-architects/ngrx-toolkit"
|
|
8
|
+
},
|
|
4
9
|
"peerDependencies": {
|
|
5
10
|
"@angular/common": "^17.0.0",
|
|
6
11
|
"@angular/core": "^17.0.0",
|