@tramvai/types-actions-state-context 2.39.3 → 2.44.2
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/actions.d.ts +7 -7
- package/lib/events.d.ts +16 -16
- package/lib/state.d.ts +6 -6
- package/package.json +1 -1
package/lib/actions.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AbortController, AbortSignal } from 'node-abort-controller';
|
|
2
2
|
import type { ProvideDepsIterator } from '@tinkoff/dippy';
|
|
3
3
|
import type { ConsumerContext, Dispatch, GetState } from './state';
|
|
4
|
-
export
|
|
5
|
-
export
|
|
4
|
+
export type ActionContext = ConsumerContext;
|
|
5
|
+
export type ActionConditionsParameters = {
|
|
6
6
|
requiredCoreRoles?: string[];
|
|
7
7
|
requiredRoles?: string[];
|
|
8
8
|
onlyBrowser?: boolean;
|
|
@@ -21,7 +21,7 @@ export interface ActionParameters<Payload, Result, Deps = {}> {
|
|
|
21
21
|
conditionsFailResult?: 'reject' | 'empty';
|
|
22
22
|
}
|
|
23
23
|
export declare const ACTION_PARAMETERS = "__action_parameters__";
|
|
24
|
-
export
|
|
24
|
+
export type Action<Payload = any, Result = any, Deps = any> = ActionParameters<Payload, Result, Deps>['fn'] & {
|
|
25
25
|
[ACTION_PARAMETERS]: ActionParameters<Payload, Result, Deps>;
|
|
26
26
|
};
|
|
27
27
|
/**
|
|
@@ -35,7 +35,7 @@ export interface PlatformAction<Payload = any, Result = any, Context extends Act
|
|
|
35
35
|
requiredRoles?: boolean;
|
|
36
36
|
cancelOnUrlChange?: boolean;
|
|
37
37
|
}
|
|
38
|
-
export
|
|
38
|
+
export type TramvaiActionType = 'page' | 'standalone';
|
|
39
39
|
export interface TramvaiActionContext<CurrentDeps> {
|
|
40
40
|
abortController: AbortController;
|
|
41
41
|
abortSignal: AbortSignal;
|
|
@@ -56,6 +56,6 @@ export interface TramvaiActionDefinition<Params extends any[], Result, Deps> {
|
|
|
56
56
|
export interface TramvaiAction<Params extends any[], Result, Deps> extends TramvaiActionDefinition<Params, Result, Deps> {
|
|
57
57
|
tramvaiActionVersion: number;
|
|
58
58
|
}
|
|
59
|
-
export
|
|
60
|
-
export
|
|
61
|
-
export
|
|
59
|
+
export type UnknownAction<Result = any> = (...args: any[]) => Result;
|
|
60
|
+
export type AnyAction<Payload = any, Result = any, Deps = any> = Action<Payload, Result, Deps> | PlatformAction<Payload, Result> | UnknownAction;
|
|
61
|
+
export type PageAction = Action<void, void, any> | TramvaiAction<[], void, any>;
|
package/lib/events.d.ts
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type Event<Payload = void> = {
|
|
2
2
|
readonly type: string;
|
|
3
3
|
readonly payload: Payload;
|
|
4
4
|
};
|
|
5
|
-
export
|
|
5
|
+
export type BaseEventCreator<Payload> = {
|
|
6
6
|
getType(): string;
|
|
7
7
|
};
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
8
|
+
export type EmptyEventCreator = BaseEventCreator<void> & (() => Event<void>);
|
|
9
|
+
export type EventCreator0<Payload> = BaseEventCreator<Payload> & (() => Event<Payload>);
|
|
10
|
+
export type EventCreator1<A1, Payload = A1> = BaseEventCreator<Payload> & ((arg1: A1) => Event<Payload>);
|
|
11
|
+
export type EventCreator2<A1, A2, Payload = A1> = BaseEventCreator<Payload> & ((arg1: A1, arg2: A2) => Event<Payload>);
|
|
12
|
+
export type EventCreator3<A1, A2, A3, Payload = A1> = BaseEventCreator<Payload> & ((arg1: A1, arg2: A2, arg3: A3) => Event<Payload>);
|
|
13
|
+
export type EventCreatorN<Payload = any> = BaseEventCreator<Payload> & ((...args: any) => Event<Payload>);
|
|
14
|
+
export type PayloadTransformer0<Payload> = () => Payload;
|
|
15
|
+
export type PayloadTransformer1<A1, Payload> = (arg1: A1) => Payload;
|
|
16
|
+
export type PayloadTransformer2<A1, A2, Payload> = (arg1: A1, arg2: A2) => Payload;
|
|
17
|
+
export type PayloadTransformer3<A1, A2, A3, Payload> = (arg1: A1, arg2: A2, arg3: A3) => Payload;
|
|
18
|
+
export type PayloadTransformerN<Payload> = (...args: any) => Payload;
|
|
19
19
|
/**
|
|
20
20
|
* @private
|
|
21
21
|
*/
|
|
22
|
-
export
|
|
22
|
+
export type AnyEventCreator<Payload = any> = EmptyEventCreator | EventCreator1<any, Payload> | EventCreator2<any, any, Payload> | EventCreator3<any, any, any, Payload>;
|
|
23
23
|
/**
|
|
24
24
|
* @private
|
|
25
25
|
*/
|
|
26
|
-
export
|
|
27
|
-
export
|
|
26
|
+
export type AnyPayloadTransformer = PayloadTransformer0<any> | PayloadTransformer1<any, any> | PayloadTransformer2<any, any, any> | PayloadTransformer3<any, any, any, any>;
|
|
27
|
+
export type EventCreators = {
|
|
28
28
|
[K: string]: AnyEventCreator;
|
|
29
29
|
};
|
package/lib/state.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { AnyEventCreator, EmptyEventCreator, EventCreator1, Event } from './events';
|
|
2
2
|
import type { AnyAction, TramvaiAction } from './actions';
|
|
3
|
-
export
|
|
3
|
+
export type EventHandler<State, Payload = void> = (state: State, payload: Payload) => State;
|
|
4
4
|
/**
|
|
5
5
|
* @deprecated
|
|
6
6
|
*/
|
|
7
|
-
export
|
|
7
|
+
export type BaseStoreConstructor<State, Name extends string = string> = {
|
|
8
8
|
storeName: Name;
|
|
9
9
|
handlers: Record<string, Function | string>;
|
|
10
10
|
new (dispatcher: any): BaseStore<State>;
|
|
@@ -37,7 +37,7 @@ export interface Reducer<State, Name extends string = string> {
|
|
|
37
37
|
[K in keyof Model]: Model[K] extends EventHandler<State, void> ? EmptyEventCreator : Model[K] extends EventHandler<State, infer Payload> ? EventCreator1<Payload, Payload> : null;
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
|
-
export
|
|
40
|
+
export type StoreInstance = InstanceType<StoreClass>;
|
|
41
41
|
export interface GetState {
|
|
42
42
|
(): Record<string, any>;
|
|
43
43
|
<S>(reducer: Reducer<S>): S;
|
|
@@ -46,7 +46,7 @@ export interface SubscribeHandler {
|
|
|
46
46
|
(handler: (state: Record<string, any>) => void): () => void;
|
|
47
47
|
<S>(reducer: Reducer<S>, callback: (state: S) => void): () => void;
|
|
48
48
|
}
|
|
49
|
-
export
|
|
49
|
+
export type Dispatch = <Payload>(event: Event<Payload>) => Payload;
|
|
50
50
|
export interface ConsumerContext {
|
|
51
51
|
executeAction<Params extends any[], Result, Deps>(action: TramvaiAction<Params, Result, Deps>, ...params: Params): Result extends Promise<any> ? Result : Promise<Result>;
|
|
52
52
|
executeAction<Payload = any, Result = any, Deps extends Record<string, any> = any>(action: AnyAction<Payload, Result, Deps>, payload?: Payload): Promise<Result extends PromiseLike<infer U> ? U : Result>;
|
|
@@ -78,7 +78,7 @@ export interface StoreClass {
|
|
|
78
78
|
}>;
|
|
79
79
|
new (dispatcher: DispatcherContext<any>['dispatcherInterface']): any;
|
|
80
80
|
}
|
|
81
|
-
export
|
|
81
|
+
export type DispatcherContext<TContext> = {
|
|
82
82
|
getStore<T extends StoreClass>(storeClass: T | string | {
|
|
83
83
|
store: T | string;
|
|
84
84
|
optional: true;
|
|
@@ -96,4 +96,4 @@ export interface MiddlewareApi {
|
|
|
96
96
|
subscribe: SubscribeHandler;
|
|
97
97
|
getState: GetState;
|
|
98
98
|
}
|
|
99
|
-
export
|
|
99
|
+
export type Middleware = (api: MiddlewareApi) => (next: Dispatch) => (event: Event) => any;
|