@tramvai/types-actions-state-context 2.6.2 → 2.10.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 +22 -1
- package/lib/state.d.ts +36 -3
- package/package.json +2 -2
package/lib/actions.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ProvideDepsIterator } from '@tinkoff/dippy';
|
|
2
|
-
import type { ConsumerContext } from './state';
|
|
2
|
+
import type { ConsumerContext, Dispatch, GetState } from './state';
|
|
3
3
|
export declare type ActionContext = ConsumerContext;
|
|
4
4
|
export declare type ActionConditionsParameters = {
|
|
5
5
|
requiredCoreRoles?: string[];
|
|
@@ -16,6 +16,7 @@ export interface ActionParameters<Payload, Result, Deps = {}> {
|
|
|
16
16
|
fn: (context: ActionContext, payload: Payload, deps: ProvideDepsIterator<Deps>) => Result;
|
|
17
17
|
deps?: Deps;
|
|
18
18
|
conditions?: ActionConditionsParameters;
|
|
19
|
+
conditionsFailResult?: 'reject' | 'empty';
|
|
19
20
|
}
|
|
20
21
|
export declare const ACTION_PARAMETERS = "__action_parameters__";
|
|
21
22
|
export declare type Action<Payload = any, Result = any, Deps = any> = ActionParameters<Payload, Result, Deps>['fn'] & {
|
|
@@ -32,5 +33,25 @@ export interface PlatformAction<Payload extends any = any, Result = any, Context
|
|
|
32
33
|
requiredRoles?: boolean;
|
|
33
34
|
cancelOnUrlChange?: boolean;
|
|
34
35
|
}
|
|
36
|
+
export declare type TramvaiActionType = 'page' | 'standalone';
|
|
37
|
+
export interface TramvaiActionContext<CurrentDeps> {
|
|
38
|
+
abortSignal: AbortSignal;
|
|
39
|
+
executeAction<Params extends any[], Result, Deps>(action: TramvaiAction<Params, Result, Deps>, ...params: Params): Result extends Promise<any> ? Result : Promise<Result>;
|
|
40
|
+
executeAction<Payload, Result, Deps>(action: Action<Payload, Result, Deps>, payload?: Payload): Result extends Promise<any> ? Result : Promise<Result>;
|
|
41
|
+
deps: ProvideDepsIterator<CurrentDeps>;
|
|
42
|
+
actionType: TramvaiActionType;
|
|
43
|
+
dispatch: Dispatch;
|
|
44
|
+
getState: GetState;
|
|
45
|
+
}
|
|
46
|
+
export interface TramvaiActionDefinition<Params extends any[], Result, Deps> {
|
|
47
|
+
name: string;
|
|
48
|
+
fn: (this: TramvaiActionContext<Deps>, ...params: Params) => Result;
|
|
49
|
+
deps?: Deps;
|
|
50
|
+
conditions?: ActionConditionsParameters;
|
|
51
|
+
conditionsFailResult?: 'reject' | 'empty';
|
|
52
|
+
}
|
|
53
|
+
export interface TramvaiAction<Params extends any[], Result, Deps> extends TramvaiActionDefinition<Params, Result, Deps> {
|
|
54
|
+
tramvaiActionVersion: number;
|
|
55
|
+
}
|
|
35
56
|
export declare type UnknownAction<Result = any> = (...args: any[]) => Result;
|
|
36
57
|
export declare type AnyAction<Payload = any, Result = any, Deps = any> = Action<Payload, Result, Deps> | PlatformAction<Payload, Result> | UnknownAction;
|
package/lib/state.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AnyEventCreator, EmptyEventCreator, EventCreator1, Event } from './events';
|
|
2
|
-
import type { AnyAction } from './actions';
|
|
2
|
+
import type { AnyAction, TramvaiAction } from './actions';
|
|
3
3
|
export declare type EventHandler<State, Payload = void> = (state: State, payload: Payload) => State;
|
|
4
4
|
/**
|
|
5
5
|
* @deprecated
|
|
@@ -37,12 +37,18 @@ 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 declare type StoreInstance = InstanceType<StoreClass>;
|
|
41
|
+
export interface GetState {
|
|
42
|
+
(): Record<string, any>;
|
|
43
|
+
<S>(reducer: Reducer<S>): S;
|
|
44
|
+
}
|
|
45
|
+
export declare type Dispatch = <Payload>(event: Event<Payload>) => Payload;
|
|
40
46
|
export interface ConsumerContext {
|
|
47
|
+
executeAction<Params extends any[], Result, Deps>(action: TramvaiAction<Params, Result, Deps>, ...params: Params): Result extends Promise<any> ? Result : Promise<Result>;
|
|
41
48
|
executeAction<Payload extends any = any, Result = any, Deps extends Record<string, any> = any>(action: AnyAction<Payload, Result, Deps>, payload?: Payload): Promise<Result extends PromiseLike<infer U> ? U : Result>;
|
|
42
49
|
dispatch: <Payload extends any = any>(actionOrNameEvent: string | Event<Payload>, payload?: Payload) => Promise<Payload>;
|
|
43
50
|
dispatchWith: <CreateActionOrType extends (...args: unknown[]) => Event | Event = (...args: unknown[]) => Event | Event, Options extends Record<string, any> = Record<string, any>>(createActionOrType: CreateActionOrType, options?: Options) => <Result extends any = any>(...args: any[]) => Promise<Result>;
|
|
44
|
-
getState
|
|
45
|
-
getState<S>(reducer: Reducer<S>): S;
|
|
51
|
+
getState: GetState;
|
|
46
52
|
/**
|
|
47
53
|
* @deprecated используйте метод `context.getState(reducer)`
|
|
48
54
|
*/
|
|
@@ -59,3 +65,30 @@ export interface ConsumerContext {
|
|
|
59
65
|
registerStore(store: Reducer<any>): void;
|
|
60
66
|
unregisterStore(store: Reducer<any>): void;
|
|
61
67
|
}
|
|
68
|
+
export interface StoreClass {
|
|
69
|
+
handlers: Record<string, Function | string>;
|
|
70
|
+
storeName: string;
|
|
71
|
+
dependencies?: Array<StoreClass | string | {
|
|
72
|
+
store: StoreClass | string;
|
|
73
|
+
optional: true;
|
|
74
|
+
}>;
|
|
75
|
+
new (dispatcher: DispatcherContext<any>['dispatcherInterface']): any;
|
|
76
|
+
}
|
|
77
|
+
export declare type DispatcherContext<TContext> = {
|
|
78
|
+
getStore<T extends StoreClass>(storeClass: T | string | {
|
|
79
|
+
store: T | string;
|
|
80
|
+
optional: true;
|
|
81
|
+
}): InstanceType<T> | null;
|
|
82
|
+
subscribe(handler: () => void): () => void;
|
|
83
|
+
getState: GetState;
|
|
84
|
+
dispatcherInterface: {
|
|
85
|
+
getContext: () => TContext;
|
|
86
|
+
getStore: DispatcherContext<TContext>['getStore'];
|
|
87
|
+
};
|
|
88
|
+
};
|
|
89
|
+
export interface MiddlewareApi {
|
|
90
|
+
dispatch: Dispatch;
|
|
91
|
+
subscribe(handler: () => void): () => void;
|
|
92
|
+
getState: GetState;
|
|
93
|
+
}
|
|
94
|
+
export declare type Middleware = (api: MiddlewareApi) => (next: Dispatch) => (event: Event) => any;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/types-actions-state-context",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.10.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"tslib": "^2.0.3"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
|
-
"@tinkoff/dippy": "0.7.
|
|
24
|
+
"@tinkoff/dippy": "0.7.45"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {},
|
|
27
27
|
"license": "Apache-2.0",
|