-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.d.ts
77 lines (77 loc) · 3.21 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import EventEmitter from 'eventemitter3';
export interface IFSM extends FSM {
}
declare const abortCtrl: unique symbol;
declare const cacheResult: unique symbol;
export declare type State = string | MiddleState;
declare type contextType = string | object;
export interface ChangeOption {
ignoreError?: boolean;
action?: string;
success?: (result: any) => any;
fail?: (err: unknown) => any;
/**
* 用于组合一组状态,当一个类里面有多个状态机时,可以用此属性来区分
*/
context?: ((this: IFSM, ...args: any[]) => contextType) | contextType;
/**
* 用于中断状态机,当状态机处于中间状态时,调用此函数,会中断状态机。
*/
abortAction?: string;
sync?: boolean;
}
export declare class MiddleState {
oldState: State;
newState: string;
action: string;
aborted: boolean;
constructor(oldState: State, newState: string, action: string);
abort(fsm: IFSM): void;
toString(): string;
}
export declare class FSMError extends Error {
state: State;
message: string;
cause?: Error | undefined;
/************* ✨ Codeium Command ⭐ *************/
/**
* Create a new instance of FSMError.
* @param state current state.
* @param message error message.
* @param cause original error.
/****** 625fa23f-3ee1-42ac-94bd-4f6ffd4578ff *******/
constructor(state: State, message: string, cause?: Error | undefined);
}
export declare function ChangeState(from: string | string[], to: string, opt?: ChangeOption): (target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => void;
export declare function tryChangeState(from: string | string[], to: string, opt?: ChangeOption): void;
export declare function Includes(...states: string[]): (target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => void;
export declare function Excludes(...states: string[]): (target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => void;
export declare function ActionState(name?: string): (target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<any>) => void;
interface FSMEventTypes {
stateChanged: [State, State, any];
}
export declare class FSM<EventTypes extends EventEmitter.ValidEventTypes = string | symbol, Context extends any = any> extends EventEmitter<EventTypes | FSMEventTypes, Context> {
name?: string | undefined;
groupName?: string | undefined;
get stateDiagram(): string[];
static readonly STATECHANGED = "stateChanged";
static readonly UPDATEAFSM = "updateAFSM";
static readonly INIT = "[*]";
static readonly ON = "on";
static readonly OFF = "off";
static instances: Map<string, IFSM>;
static instances2: WeakMap<object, IFSM>;
static get(context: string | object): IFSM;
static getState(context: string | object): State;
_state: State;
[cacheResult]: any;
[abortCtrl]?: {
aborted: boolean;
};
constructor(name?: string | undefined, groupName?: string | undefined, prototype?: any);
updateDevTools(payload?: any): void;
get state(): State;
set state(value: State);
}
export {};
//# sourceMappingURL=index.d.ts.map