@tramvai/types-actions-state-context 2.108.1 → 2.109.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.
- package/lib/events.d.ts +4 -0
- package/lib/events.es.js +5 -0
- package/lib/events.js +9 -0
- package/lib/index.es.js +1 -0
- package/lib/index.js +2 -0
- package/lib/state.d.ts +12 -4
- package/package.json +2 -1
package/lib/events.d.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import type { Reducer } from './state';
|
|
1
2
|
export type Event<Payload = void> = {
|
|
2
3
|
readonly type: string;
|
|
3
4
|
readonly payload: Payload;
|
|
5
|
+
store?: Reducer<any, any>;
|
|
4
6
|
};
|
|
5
7
|
export type BaseEventCreator<Payload> = {
|
|
6
8
|
getType(): string;
|
|
9
|
+
store?: Reducer<any, any>;
|
|
7
10
|
};
|
|
8
11
|
export type EmptyEventCreator = BaseEventCreator<void> & (() => Event<void>);
|
|
9
12
|
export type EventCreator0<Payload> = BaseEventCreator<Payload> & (() => Event<Payload>);
|
|
@@ -27,3 +30,4 @@ export type AnyPayloadTransformer = PayloadTransformer0<any> | PayloadTransforme
|
|
|
27
30
|
export type EventCreators = {
|
|
28
31
|
[K: string]: AnyEventCreator;
|
|
29
32
|
};
|
|
33
|
+
export declare const isEvent: (event: any) => event is Event<void>;
|
package/lib/events.es.js
ADDED
package/lib/events.js
ADDED
package/lib/index.es.js
CHANGED
package/lib/index.js
CHANGED
package/lib/state.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { AnyEventCreator, EmptyEventCreator, EventCreator1, Event } from './events';
|
|
2
2
|
import type { AnyAction, TramvaiAction } from './actions';
|
|
3
|
+
export type EmptyEventHandler<State> = (state: State) => State;
|
|
3
4
|
export type EventHandler<State, Payload = void> = (state: State, payload: Payload) => State;
|
|
5
|
+
export type EventHandlersToEventCreators<State, Model extends {
|
|
6
|
+
[K: string]: EventHandler<State, any>;
|
|
7
|
+
}> = {
|
|
8
|
+
[K in keyof Model]: Model[K] extends EmptyEventHandler<State> ? EmptyEventCreator : Model[K] extends EventHandler<State, infer Payload> ? EventCreator1<Payload> : null;
|
|
9
|
+
};
|
|
4
10
|
/**
|
|
5
11
|
* @deprecated
|
|
6
12
|
*/
|
|
@@ -26,16 +32,18 @@ export interface ReduceBaseStore<State> {
|
|
|
26
32
|
rehydrate(state: Partial<State> | void): void;
|
|
27
33
|
handle(payload: any, eventName: string, meta?: any): any;
|
|
28
34
|
}
|
|
29
|
-
export interface Reducer<State, Name extends string = string> {
|
|
35
|
+
export interface Reducer<State, Name extends string = string, Events = any> {
|
|
30
36
|
storeName: Name;
|
|
31
37
|
handlers: Record<string, Function | string>;
|
|
38
|
+
events: Events;
|
|
32
39
|
new (): ReduceBaseStore<State>;
|
|
33
40
|
on<Payload>(event: AnyEventCreator<Payload> | string | Array<AnyEventCreator | string>, handler: EventHandler<State, Payload>): this;
|
|
41
|
+
/**
|
|
42
|
+
* @deprecated Use object initializer for the createReducer call to define events
|
|
43
|
+
*/
|
|
34
44
|
createEvents<Model extends {
|
|
35
45
|
[K: string]: EventHandler<State, any>;
|
|
36
|
-
}>(model: Model):
|
|
37
|
-
[K in keyof Model]: Model[K] extends EventHandler<State, void> ? EmptyEventCreator : Model[K] extends EventHandler<State, infer Payload> ? EventCreator1<Payload, Payload> : null;
|
|
38
|
-
};
|
|
46
|
+
}>(model: Model): EventHandlersToEventCreators<State, Model>;
|
|
39
47
|
}
|
|
40
48
|
export type StoreInstance = InstanceType<StoreClass>;
|
|
41
49
|
export interface GetState {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/types-actions-state-context",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.109.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
"watch": "tsc -w"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
+
"node-abort-controller": "^3.0.1",
|
|
20
21
|
"tslib": "^2.4.0"
|
|
21
22
|
},
|
|
22
23
|
"peerDependencies": {
|