fastevent 2.2.9 → 2.2.11
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/dist/eventbus/index.d.mts +59 -80
- package/dist/eventbus/index.d.ts +59 -80
- package/dist/eventbus/index.js +1 -1
- package/dist/eventbus/index.js.map +1 -1
- package/dist/eventbus/index.mjs +1 -1
- package/dist/eventbus/index.mjs.map +1 -1
- package/dist/executors/index.d.mts +2 -2
- package/dist/executors/index.d.ts +2 -2
- package/dist/index.d.mts +58 -79
- package/dist/index.d.ts +58 -79
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/pipes/index.d.mts +2 -2
- package/dist/pipes/index.d.ts +2 -2
- package/package.json +1 -1
|
@@ -2,6 +2,32 @@ type FastListenerExecutor = (listeners: FastListenerMeta[], message: TypedFastEv
|
|
|
2
2
|
|
|
3
3
|
type FastListenerPipe = (listener: TypedFastEventListener) => TypedFastEventListener;
|
|
4
4
|
|
|
5
|
+
type MergeUnion<T> = (T extends any ? (x: T) => void : never) extends (x: infer U) => void ? {
|
|
6
|
+
[K in keyof U]: U[K];
|
|
7
|
+
} : never;
|
|
8
|
+
type Split$1<S extends string, Delimiter extends string = '/'> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split$1<Tail, Delimiter>] : [S];
|
|
9
|
+
type MatchSegment<Input extends string, Pattern extends string> = Pattern extends '*' ? true : Pattern extends '**' ? true : Input extends Pattern ? true : false;
|
|
10
|
+
type MatchPatternArray<InputArr extends string[], PatternArr extends string[]> = InputArr extends [infer InputHead extends string, ...infer InputTail extends string[]] ? PatternArr extends [infer PatternHead extends string, ...infer PatternTail extends string[]] ? PatternHead extends '**' ? MatchPatternArray<InputTail, PatternTail> extends true ? true : MatchPatternArray<InputTail, PatternArr> extends true ? true : MatchPatternArray<InputArr, PatternTail> extends true ? true : false : MatchSegment<InputHead, PatternHead> extends true ? MatchPatternArray<InputTail, PatternTail> : false : false : PatternArr extends [infer PatternHead extends string, ...infer PatternTail extends string[]] ? PatternHead extends '**' ? MatchPatternArray<InputArr, PatternTail> : false : true;
|
|
11
|
+
type MatchPattern$1<T extends string, Pattern extends string> = MatchPatternArray<Split$1<T>, Split$1<Pattern>> extends true ? {
|
|
12
|
+
[K in Pattern]: any;
|
|
13
|
+
} : never;
|
|
14
|
+
type Fallback$1<T, F> = [T] extends [never] ? F : T extends undefined ? F : T;
|
|
15
|
+
type MatchEventType<T extends string, Events extends Record<string, any>> = MergeUnion<Fallback$1<{
|
|
16
|
+
[K in keyof Events]: MatchPattern$1<T, K & string> extends never ? never : {
|
|
17
|
+
[P in K]: Events[K];
|
|
18
|
+
};
|
|
19
|
+
}[keyof Events] extends infer Result ? Result extends Record<string, any> ? Result : any : any, {
|
|
20
|
+
[K in T]: any;
|
|
21
|
+
}>>;
|
|
22
|
+
|
|
23
|
+
type Split<S extends string, Delimiter extends string> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split<Tail, Delimiter>] : [S];
|
|
24
|
+
type MatchPattern<KeyParts extends string[], PrefixParts extends string[]> = PrefixParts['length'] extends 0 ? true : KeyParts['length'] extends 0 ? false : KeyParts[0] extends PrefixParts[0] | '*' ? MatchPattern<Slice<KeyParts, 1>, Slice<PrefixParts, 1>> : false;
|
|
25
|
+
type Slice<T extends any[], Start extends number, Result extends any[] = []> = Start extends 0 ? T : T extends [infer First, ...infer Rest] ? Slice<Rest, Decrement<Start>, Result> : Result;
|
|
26
|
+
type Decrement<N extends number> = N extends 0 ? 0 : N extends 1 ? 0 : N extends 2 ? 1 : N extends 3 ? 2 : N extends 4 ? 3 : N extends 5 ? 4 : N extends 6 ? 5 : N extends 7 ? 6 : N extends 8 ? 7 : N extends 9 ? 8 : number;
|
|
27
|
+
type ScopeEvents<Events extends Record<string, any>, Prefix extends string> = {
|
|
28
|
+
[K in keyof Events as K extends string ? MatchPattern<Split<K, '/'>, Split<Prefix, '/'>> extends true ? K : never : never]: Events[K];
|
|
29
|
+
};
|
|
30
|
+
|
|
5
31
|
interface FastEventMeta {
|
|
6
32
|
}
|
|
7
33
|
interface FastEventMessageExtends {
|
|
@@ -11,34 +37,34 @@ type FastEventMessage<P = any, M extends Record<string, any> = Record<string, an
|
|
|
11
37
|
payload: P;
|
|
12
38
|
meta?: M & Partial<FastEventMeta>;
|
|
13
39
|
} & FastEventMessageExtends;
|
|
14
|
-
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
40
|
+
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
15
41
|
[K in keyof Events]: {
|
|
16
42
|
type: Exclude<K, number | symbol>;
|
|
17
43
|
payload: Events[K];
|
|
18
44
|
meta: FastEventMeta & M & Record<string, any>;
|
|
19
45
|
};
|
|
20
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
21
|
-
type TypedFastEventMessageOptional<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
46
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
47
|
+
type TypedFastEventMessageOptional<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
22
48
|
[K in keyof Events]: {
|
|
23
49
|
type: Exclude<K, number | symbol>;
|
|
24
50
|
payload: Events[K];
|
|
25
51
|
meta?: DeepPartial<FastEventMeta & M & Record<string, any>>;
|
|
26
52
|
};
|
|
27
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
28
|
-
type FastEventEmitMessage<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
53
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
54
|
+
type FastEventEmitMessage<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
29
55
|
[K in keyof Events]: {
|
|
30
56
|
type: Exclude<K, number | symbol>;
|
|
31
57
|
payload?: Events[K];
|
|
32
58
|
meta?: DeepPartial<FastEventMeta & M & Record<string, any>>;
|
|
33
59
|
};
|
|
34
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
60
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
35
61
|
type TypedFastEventListener<T extends string = string, P = any, M = any, C = any> = (this: C, message: TypedFastEventMessage<{
|
|
36
62
|
[K in T]: P;
|
|
37
63
|
}, M>, args: FastEventListenerArgs<M>) => any | Promise<any>;
|
|
38
64
|
type TypedFastEventAnyListener<Events extends Record<string, any> = Record<string, any>, Meta = never, Context = any> = (this: Context, message: TypedFastEventMessage<Events, Meta>, args: FastEventListenerArgs<Meta>) => any | Promise<any>;
|
|
39
|
-
type FastEventListeners<Events extends Record<string, any> = Record<string, any>, M = any, C = any> =
|
|
65
|
+
type FastEventListeners<Events extends Record<string, any> = Record<string, any>, M = any, C = any> = {
|
|
40
66
|
[K in keyof Events]: TypedFastEventListener<Exclude<K, number | symbol>, Events[K], M, C>;
|
|
41
|
-
}
|
|
67
|
+
};
|
|
42
68
|
type FastEventListener<P = any, M extends Record<string, any> = Record<string, any>, T extends string = string> = (message: FastEventMessage<P, M, T>, args: FastEventListenerArgs<M>) => any | Promise<any>;
|
|
43
69
|
/**
|
|
44
70
|
* [
|
|
@@ -98,7 +124,7 @@ type FastEventOptions<Meta = Record<string, any>, Context = never> = {
|
|
|
98
124
|
onAddListener?: (type: string, listener: TypedFastEventListener, options: FastEventListenOptions<Record<string, any>, Meta>) => boolean | FastEventSubscriber | void;
|
|
99
125
|
onRemoveListener?: (type: string, listener: TypedFastEventListener) => void;
|
|
100
126
|
onClearListeners?: () => void;
|
|
101
|
-
onListenerError?: (
|
|
127
|
+
onListenerError?: (error: Error, listener: TypedFastEventListener, message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta> | undefined) => void;
|
|
102
128
|
onBeforeExecuteListener?: (message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta>) => boolean | void | any[];
|
|
103
129
|
onAfterExecuteListener?: (message: TypedFastEventMessage<any, Meta>, returns: any[], listeners: FastListenerNode[]) => void;
|
|
104
130
|
/**
|
|
@@ -110,10 +136,6 @@ type FastEventOptions<Meta = Record<string, any>, Context = never> = {
|
|
|
110
136
|
};
|
|
111
137
|
interface FastEvents {
|
|
112
138
|
}
|
|
113
|
-
type PickScopeEvents<T extends Record<string, any>, Prefix extends string> = {
|
|
114
|
-
[K in keyof T as K extends `${Prefix}/${infer Rest}` ? Rest : never]: T[K];
|
|
115
|
-
};
|
|
116
|
-
type ScopeEvents<T extends Record<string, any>, Prefix extends string> = PickScopeEvents<T, Prefix>;
|
|
117
139
|
type FastEventListenOptions<Events extends Record<string, any> = Record<string, any>, Meta = any> = {
|
|
118
140
|
count?: number;
|
|
119
141
|
prepend?: boolean;
|
|
@@ -160,9 +182,7 @@ type OptionalItems<T, K extends keyof T> = Expand<Omit<T, K> & {
|
|
|
160
182
|
type DeepPartial<T> = {
|
|
161
183
|
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
162
184
|
};
|
|
163
|
-
type Fallback<T, F> = [
|
|
164
|
-
T
|
|
165
|
-
] extends [never] ? F : T extends undefined ? F : T;
|
|
185
|
+
type Fallback<T, F> = [T] extends [never] ? F : T extends undefined ? F : T;
|
|
166
186
|
type ChangeFieldType<Record, Name extends string, Type = any> = Expand<Omit<Record, Name> & {
|
|
167
187
|
[K in Name]: Type;
|
|
168
188
|
}>;
|
|
@@ -191,16 +211,7 @@ type Overloads<T> = Unique<T extends {
|
|
|
191
211
|
(...args: infer A6): infer R6;
|
|
192
212
|
(...args: infer A7): infer R7;
|
|
193
213
|
(...args: infer A8): infer R8;
|
|
194
|
-
} ? [
|
|
195
|
-
(...args: A1) => R1,
|
|
196
|
-
((...args: A2) => R2),
|
|
197
|
-
((...args: A3) => R3),
|
|
198
|
-
((...args: A4) => R4),
|
|
199
|
-
((...args: A5) => R5),
|
|
200
|
-
((...args: A6) => R6),
|
|
201
|
-
((...args: A7) => R7),
|
|
202
|
-
((...args: A8) => R8)
|
|
203
|
-
] : T extends {
|
|
214
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6, (...args: A7) => R7, (...args: A8) => R8] : T extends {
|
|
204
215
|
(...args: infer A1): infer R1;
|
|
205
216
|
(...args: infer A2): infer R2;
|
|
206
217
|
(...args: infer A3): infer R3;
|
|
@@ -208,75 +219,42 @@ type Overloads<T> = Unique<T extends {
|
|
|
208
219
|
(...args: infer A5): infer R5;
|
|
209
220
|
(...args: infer A6): infer R6;
|
|
210
221
|
(...args: infer A7): infer R7;
|
|
211
|
-
} ? [
|
|
212
|
-
(...args: A1) => R1,
|
|
213
|
-
((...args: A2) => R2),
|
|
214
|
-
((...args: A3) => R3),
|
|
215
|
-
((...args: A4) => R4),
|
|
216
|
-
((...args: A5) => R5),
|
|
217
|
-
((...args: A6) => R6),
|
|
218
|
-
((...args: A7) => R7)
|
|
219
|
-
] : T extends {
|
|
222
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6, (...args: A7) => R7] : T extends {
|
|
220
223
|
(...args: infer A1): infer R1;
|
|
221
224
|
(...args: infer A2): infer R2;
|
|
222
225
|
(...args: infer A3): infer R3;
|
|
223
226
|
(...args: infer A4): infer R4;
|
|
224
227
|
(...args: infer A5): infer R5;
|
|
225
228
|
(...args: infer A6): infer R6;
|
|
226
|
-
} ? [
|
|
227
|
-
(...args: A1) => R1,
|
|
228
|
-
((...args: A2) => R2),
|
|
229
|
-
((...args: A3) => R3),
|
|
230
|
-
((...args: A4) => R4),
|
|
231
|
-
((...args: A5) => R5),
|
|
232
|
-
((...args: A6) => R6)
|
|
233
|
-
] : T extends {
|
|
229
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6] : T extends {
|
|
234
230
|
(...args: infer A1): infer R1;
|
|
235
231
|
(...args: infer A2): infer R2;
|
|
236
232
|
(...args: infer A3): infer R3;
|
|
237
233
|
(...args: infer A4): infer R4;
|
|
238
234
|
(...args: infer A5): infer R5;
|
|
239
|
-
} ? [
|
|
240
|
-
(...args: A1) => R1,
|
|
241
|
-
((...args: A2) => R2),
|
|
242
|
-
((...args: A3) => R3),
|
|
243
|
-
((...args: A4) => R4),
|
|
244
|
-
((...args: A5) => R5)
|
|
245
|
-
] : T extends {
|
|
235
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T extends {
|
|
246
236
|
(...args: infer A1): infer R1;
|
|
247
237
|
(...args: infer A2): infer R2;
|
|
248
238
|
(...args: infer A3): infer R3;
|
|
249
239
|
(...args: infer A4): infer R4;
|
|
250
|
-
} ? [
|
|
251
|
-
(...args: A1) => R1,
|
|
252
|
-
((...args: A2) => R2),
|
|
253
|
-
((...args: A3) => R3),
|
|
254
|
-
((...args: A4) => R4)
|
|
255
|
-
] : T extends {
|
|
240
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4] : T extends {
|
|
256
241
|
(...args: infer A1): infer R1;
|
|
257
242
|
(...args: infer A2): infer R2;
|
|
258
243
|
(...args: infer A3): infer R3;
|
|
259
|
-
} ? [
|
|
260
|
-
((...args: A1) => R1),
|
|
261
|
-
((...args: A2) => R2),
|
|
262
|
-
((...args: A3) => R3)
|
|
263
|
-
] : T extends {
|
|
244
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3] : T extends {
|
|
264
245
|
(...args: infer A1): infer R1;
|
|
265
246
|
(...args: infer A2): infer R2;
|
|
266
|
-
} ? [
|
|
267
|
-
((...args: A1) => R1),
|
|
268
|
-
((...args: A2) => R2)
|
|
269
|
-
] : T extends {
|
|
247
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2] : T extends {
|
|
270
248
|
(...args: infer A1): infer R1;
|
|
271
|
-
} ? [
|
|
272
|
-
(...args: A1) => R1
|
|
273
|
-
] : [
|
|
274
|
-
T
|
|
275
|
-
]>;
|
|
249
|
+
} ? [(...args: A1) => R1] : [T]>;
|
|
276
250
|
type Dict<V = any> = Record<Exclude<string, number | symbol>, V>;
|
|
277
251
|
type Union<T> = T extends infer O ? {
|
|
278
252
|
[K in keyof O]: O[K];
|
|
279
253
|
} : never;
|
|
254
|
+
type RecordValues<R extends Record<string, any>> = R[keyof R];
|
|
255
|
+
type RecordPrefix<P extends string, R extends Record<string, any>> = {
|
|
256
|
+
[K in keyof R as K extends `${P}/${infer S}` ? S : never]: R[K];
|
|
257
|
+
};
|
|
280
258
|
|
|
281
259
|
type FastEventBusMessage<Events extends Record<string, any> = Record<string, any>, M = any> = FastEventEmitMessage<Events, M> & {
|
|
282
260
|
from?: string;
|
|
@@ -342,7 +320,7 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
342
320
|
on<T extends string>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
343
321
|
on(type: '**', options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
344
322
|
on<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
345
|
-
on<T extends string>(type: T, listener: TypedFastEventListener<
|
|
323
|
+
on<T extends string>(type: T, listener: TypedFastEventListener<Exclude<keyof MatchEventType<T, Events>, number | symbol>, RecordValues<MatchEventType<T, Events>>, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
346
324
|
on(type: '**', listener: TypedFastEventAnyListener<Events, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
347
325
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
348
326
|
once<T extends string>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
@@ -362,9 +340,9 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
362
340
|
emit(type: Types, directive: symbol): void;
|
|
363
341
|
emit(type: string, directive: symbol): void;
|
|
364
342
|
emit<R = any, T extends Types = Types>(type: T, payload?: Events[T], retain?: boolean): R[];
|
|
365
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] :
|
|
343
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : RecordValues<MatchEventType<T, Events>>, retain?: boolean): R[];
|
|
366
344
|
emit<R = any>(type: Types, payload?: Events[Types], options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
367
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] :
|
|
345
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : RecordValues<MatchEventType<T, Events>>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
368
346
|
emit<R = any>(message: FastEventEmitMessage<Events, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
369
347
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
370
348
|
[K in T]: K extends Types ? Events[K] : any;
|
|
@@ -416,7 +394,7 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
416
394
|
* ```
|
|
417
395
|
*/
|
|
418
396
|
scope<E extends Record<string, any> = Record<string, any>, P extends string = string, M extends Record<string, any> = Record<string, any>, C = Context>(prefix: P, options?: DeepPartial<FastEventScopeOptions<Partial<FinalMeta> & M, C>>): FastEventScope<ScopeEvents<Events, P> & E, FinalMeta & M, C>;
|
|
419
|
-
scope<E extends Record<string, any> = Record<string, any>, P extends string = string, M extends Record<string, any> = Record<string, any>, C = Context, ScopeInstance extends FastEventScope<any, any, any> = FastEventScope<ScopeEvents<
|
|
397
|
+
scope<E extends Record<string, any> = Record<string, any>, P extends string = string, M extends Record<string, any> = Record<string, any>, C = Context, ScopeInstance extends FastEventScope<any, any, any> = FastEventScope<ScopeEvents<Events, P> & E, FinalMeta & M, C>>(prefix: P, scopeObj: ScopeInstance, options?: DeepPartial<FastEventScopeOptions<Partial<FinalMeta> & M, C>>): ScopeInstance & FastEventScope<ScopeEvents<Events, P> & E, FinalMeta & M, C>;
|
|
420
398
|
/**
|
|
421
399
|
* 当on/once/onAny未指定监听器时,此为默认监听器
|
|
422
400
|
* @param message
|
|
@@ -538,7 +516,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
538
516
|
on<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
539
517
|
on(type: '**', options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
540
518
|
on<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, AllEvents[T], Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
541
|
-
on<T extends string>(type: T, listener: TypedFastEventAnyListener<
|
|
519
|
+
on<T extends string>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, AllEvents>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
542
520
|
on(type: '**', listener: TypedFastEventAnyListener<Record<string, any>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
543
521
|
/**
|
|
544
522
|
* 注册一次性事件监听器
|
|
@@ -564,7 +542,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
564
542
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
565
543
|
once<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
566
544
|
once<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, AllEvents[T], Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
567
|
-
once<T extends string>(type: T, listener: TypedFastEventAnyListener<
|
|
545
|
+
once<T extends string>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, AllEvents>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
568
546
|
/**
|
|
569
547
|
* 注册一个监听器,用于监听所有事件
|
|
570
548
|
* @param listener 事件监听器函数,可以接收任意类型的事件数据
|
|
@@ -753,13 +731,13 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
753
731
|
emit<T extends Types = Types>(type: T, directive: symbol): any[];
|
|
754
732
|
emit(type: string, directive: symbol): any[];
|
|
755
733
|
emit<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], retain?: boolean): R[];
|
|
756
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] :
|
|
734
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : RecordValues<MatchEventType<T, AllEvents>>, retain?: boolean): R[];
|
|
757
735
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
758
736
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
759
737
|
}, Meta>, retain?: boolean): R[];
|
|
760
738
|
emit<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, retain?: boolean): R[];
|
|
761
739
|
emit<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], options?: FastEventListenerArgs<Meta>): R[];
|
|
762
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] :
|
|
740
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : RecordValues<MatchEventType<T, AllEvents>>, options?: FastEventListenerArgs<Meta>): R[];
|
|
763
741
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
764
742
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
765
743
|
}, Meta>, options?: FastEventListenerArgs<Meta>): R[];
|
|
@@ -892,6 +870,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
892
870
|
* userEvents.offAll(); // 清理 'user' 前缀下的所有事件
|
|
893
871
|
* ```
|
|
894
872
|
*/
|
|
873
|
+
scope<P extends string>(prefix: P, options?: DeepPartial<FastEventScopeOptions<Meta, Context>>): FastEventScope<ScopeEvents<AllEvents, P>, Meta, Context>;
|
|
895
874
|
scope<E extends Record<string, any> = Record<string, any>, P extends string = string, M extends Record<string, any> = Record<string, any>, C = Context>(prefix: P, options?: DeepPartial<FastEventScopeOptions<Meta & M, C>>): FastEventScope<ScopeEvents<AllEvents, P> & E, Meta & M, C>;
|
|
896
875
|
scope<E extends Record<string, any> = Record<string, any>, P extends string = string, M extends Record<string, any> = Record<string, any>, C = Context, ScopeObject extends FastEventScope<any, any, any> = FastEventScope<ScopeEvents<AllEvents, P> & E, Meta & M, C>>(prefix: P, scopeObj: ScopeObject, options?: DeepPartial<FastEventScopeOptions<Meta & M, C>>): ScopeObject;
|
|
897
876
|
}
|
|
@@ -924,7 +903,7 @@ declare class FastEventBusNode<Events extends Record<string, any> = Record<strin
|
|
|
924
903
|
* 加入事件总线
|
|
925
904
|
* @param eventBus 要加入的事件总线
|
|
926
905
|
*/
|
|
927
|
-
connect(eventbus: FastEventBus<any>): void;
|
|
906
|
+
connect(eventbus: FastEventBus<any, any, any>): void;
|
|
928
907
|
disconnect(): void;
|
|
929
908
|
/**
|
|
930
909
|
*
|
|
@@ -1152,4 +1131,4 @@ declare function isClass(target: unknown): target is new (...args: any[]) => any
|
|
|
1152
1131
|
|
|
1153
1132
|
declare function isFastEvent(target: any): target is FastEvent;
|
|
1154
1133
|
|
|
1155
|
-
export { AbortError, BroadcastEvent, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type Fallback, FastEvent, FastEventBus, type FastEventBusEventTypes, type FastEventBusEvents, type FastEventBusMessage, FastEventBusNode, type FastEventBusNodeIds, type FastEventBusNodeOptions, type FastEventBusNodes, type FastEventBusOptions, FastEventDirectives, type FastEventEmitMessage, FastEventError, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, type FastEventListeners, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListenerMeta, type FastListenerNode, type FastListeners, type Merge, NamespaceDelimiter, NodeDataEvent, type ObjectKeys, type OptionalItems, type Overloads, type OverrideOptions, type
|
|
1134
|
+
export { AbortError, BroadcastEvent, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type Fallback, FastEvent, FastEventBus, type FastEventBusEventTypes, type FastEventBusEvents, type FastEventBusMessage, FastEventBusNode, type FastEventBusNodeIds, type FastEventBusNodeOptions, type FastEventBusNodes, type FastEventBusOptions, FastEventDirectives, type FastEventEmitMessage, FastEventError, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, type FastEventListeners, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListenerMeta, type FastListenerNode, type FastListeners, type MatchEventType, type Merge, type MergeUnion, NamespaceDelimiter, NodeDataEvent, type ObjectKeys, type OptionalItems, type Overloads, type OverrideOptions, QueueOverflowError, type RecordPrefix, type RecordValues, type RequiredItems, type ScopeEvents, TimeoutError, type TypedFastEventAnyListener, type TypedFastEventListener, type TypedFastEventMessage, type TypedFastEventMessageOptional, UnboundError, type Union, type Unique, __FastEventScope__, __FastEvent__, __expandable__, expandable, isClass, isExpandable, isFastEvent, isFastEventMessage, isFastEventScope, isFunction, isPathMatched, isString, isSubsctiber };
|
package/dist/eventbus/index.d.ts
CHANGED
|
@@ -2,6 +2,32 @@ type FastListenerExecutor = (listeners: FastListenerMeta[], message: TypedFastEv
|
|
|
2
2
|
|
|
3
3
|
type FastListenerPipe = (listener: TypedFastEventListener) => TypedFastEventListener;
|
|
4
4
|
|
|
5
|
+
type MergeUnion<T> = (T extends any ? (x: T) => void : never) extends (x: infer U) => void ? {
|
|
6
|
+
[K in keyof U]: U[K];
|
|
7
|
+
} : never;
|
|
8
|
+
type Split$1<S extends string, Delimiter extends string = '/'> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split$1<Tail, Delimiter>] : [S];
|
|
9
|
+
type MatchSegment<Input extends string, Pattern extends string> = Pattern extends '*' ? true : Pattern extends '**' ? true : Input extends Pattern ? true : false;
|
|
10
|
+
type MatchPatternArray<InputArr extends string[], PatternArr extends string[]> = InputArr extends [infer InputHead extends string, ...infer InputTail extends string[]] ? PatternArr extends [infer PatternHead extends string, ...infer PatternTail extends string[]] ? PatternHead extends '**' ? MatchPatternArray<InputTail, PatternTail> extends true ? true : MatchPatternArray<InputTail, PatternArr> extends true ? true : MatchPatternArray<InputArr, PatternTail> extends true ? true : false : MatchSegment<InputHead, PatternHead> extends true ? MatchPatternArray<InputTail, PatternTail> : false : false : PatternArr extends [infer PatternHead extends string, ...infer PatternTail extends string[]] ? PatternHead extends '**' ? MatchPatternArray<InputArr, PatternTail> : false : true;
|
|
11
|
+
type MatchPattern$1<T extends string, Pattern extends string> = MatchPatternArray<Split$1<T>, Split$1<Pattern>> extends true ? {
|
|
12
|
+
[K in Pattern]: any;
|
|
13
|
+
} : never;
|
|
14
|
+
type Fallback$1<T, F> = [T] extends [never] ? F : T extends undefined ? F : T;
|
|
15
|
+
type MatchEventType<T extends string, Events extends Record<string, any>> = MergeUnion<Fallback$1<{
|
|
16
|
+
[K in keyof Events]: MatchPattern$1<T, K & string> extends never ? never : {
|
|
17
|
+
[P in K]: Events[K];
|
|
18
|
+
};
|
|
19
|
+
}[keyof Events] extends infer Result ? Result extends Record<string, any> ? Result : any : any, {
|
|
20
|
+
[K in T]: any;
|
|
21
|
+
}>>;
|
|
22
|
+
|
|
23
|
+
type Split<S extends string, Delimiter extends string> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split<Tail, Delimiter>] : [S];
|
|
24
|
+
type MatchPattern<KeyParts extends string[], PrefixParts extends string[]> = PrefixParts['length'] extends 0 ? true : KeyParts['length'] extends 0 ? false : KeyParts[0] extends PrefixParts[0] | '*' ? MatchPattern<Slice<KeyParts, 1>, Slice<PrefixParts, 1>> : false;
|
|
25
|
+
type Slice<T extends any[], Start extends number, Result extends any[] = []> = Start extends 0 ? T : T extends [infer First, ...infer Rest] ? Slice<Rest, Decrement<Start>, Result> : Result;
|
|
26
|
+
type Decrement<N extends number> = N extends 0 ? 0 : N extends 1 ? 0 : N extends 2 ? 1 : N extends 3 ? 2 : N extends 4 ? 3 : N extends 5 ? 4 : N extends 6 ? 5 : N extends 7 ? 6 : N extends 8 ? 7 : N extends 9 ? 8 : number;
|
|
27
|
+
type ScopeEvents<Events extends Record<string, any>, Prefix extends string> = {
|
|
28
|
+
[K in keyof Events as K extends string ? MatchPattern<Split<K, '/'>, Split<Prefix, '/'>> extends true ? K : never : never]: Events[K];
|
|
29
|
+
};
|
|
30
|
+
|
|
5
31
|
interface FastEventMeta {
|
|
6
32
|
}
|
|
7
33
|
interface FastEventMessageExtends {
|
|
@@ -11,34 +37,34 @@ type FastEventMessage<P = any, M extends Record<string, any> = Record<string, an
|
|
|
11
37
|
payload: P;
|
|
12
38
|
meta?: M & Partial<FastEventMeta>;
|
|
13
39
|
} & FastEventMessageExtends;
|
|
14
|
-
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
40
|
+
type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
15
41
|
[K in keyof Events]: {
|
|
16
42
|
type: Exclude<K, number | symbol>;
|
|
17
43
|
payload: Events[K];
|
|
18
44
|
meta: FastEventMeta & M & Record<string, any>;
|
|
19
45
|
};
|
|
20
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
21
|
-
type TypedFastEventMessageOptional<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
46
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
47
|
+
type TypedFastEventMessageOptional<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
22
48
|
[K in keyof Events]: {
|
|
23
49
|
type: Exclude<K, number | symbol>;
|
|
24
50
|
payload: Events[K];
|
|
25
51
|
meta?: DeepPartial<FastEventMeta & M & Record<string, any>>;
|
|
26
52
|
};
|
|
27
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
28
|
-
type FastEventEmitMessage<Events extends Record<string, any> = Record<string, any>, M = any> =
|
|
53
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
54
|
+
type FastEventEmitMessage<Events extends Record<string, any> = Record<string, any>, M = any> = {
|
|
29
55
|
[K in keyof Events]: {
|
|
30
56
|
type: Exclude<K, number | symbol>;
|
|
31
57
|
payload?: Events[K];
|
|
32
58
|
meta?: DeepPartial<FastEventMeta & M & Record<string, any>>;
|
|
33
59
|
};
|
|
34
|
-
}[Exclude<keyof Events, number | symbol>]
|
|
60
|
+
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
35
61
|
type TypedFastEventListener<T extends string = string, P = any, M = any, C = any> = (this: C, message: TypedFastEventMessage<{
|
|
36
62
|
[K in T]: P;
|
|
37
63
|
}, M>, args: FastEventListenerArgs<M>) => any | Promise<any>;
|
|
38
64
|
type TypedFastEventAnyListener<Events extends Record<string, any> = Record<string, any>, Meta = never, Context = any> = (this: Context, message: TypedFastEventMessage<Events, Meta>, args: FastEventListenerArgs<Meta>) => any | Promise<any>;
|
|
39
|
-
type FastEventListeners<Events extends Record<string, any> = Record<string, any>, M = any, C = any> =
|
|
65
|
+
type FastEventListeners<Events extends Record<string, any> = Record<string, any>, M = any, C = any> = {
|
|
40
66
|
[K in keyof Events]: TypedFastEventListener<Exclude<K, number | symbol>, Events[K], M, C>;
|
|
41
|
-
}
|
|
67
|
+
};
|
|
42
68
|
type FastEventListener<P = any, M extends Record<string, any> = Record<string, any>, T extends string = string> = (message: FastEventMessage<P, M, T>, args: FastEventListenerArgs<M>) => any | Promise<any>;
|
|
43
69
|
/**
|
|
44
70
|
* [
|
|
@@ -98,7 +124,7 @@ type FastEventOptions<Meta = Record<string, any>, Context = never> = {
|
|
|
98
124
|
onAddListener?: (type: string, listener: TypedFastEventListener, options: FastEventListenOptions<Record<string, any>, Meta>) => boolean | FastEventSubscriber | void;
|
|
99
125
|
onRemoveListener?: (type: string, listener: TypedFastEventListener) => void;
|
|
100
126
|
onClearListeners?: () => void;
|
|
101
|
-
onListenerError?: (
|
|
127
|
+
onListenerError?: (error: Error, listener: TypedFastEventListener, message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta> | undefined) => void;
|
|
102
128
|
onBeforeExecuteListener?: (message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta>) => boolean | void | any[];
|
|
103
129
|
onAfterExecuteListener?: (message: TypedFastEventMessage<any, Meta>, returns: any[], listeners: FastListenerNode[]) => void;
|
|
104
130
|
/**
|
|
@@ -110,10 +136,6 @@ type FastEventOptions<Meta = Record<string, any>, Context = never> = {
|
|
|
110
136
|
};
|
|
111
137
|
interface FastEvents {
|
|
112
138
|
}
|
|
113
|
-
type PickScopeEvents<T extends Record<string, any>, Prefix extends string> = {
|
|
114
|
-
[K in keyof T as K extends `${Prefix}/${infer Rest}` ? Rest : never]: T[K];
|
|
115
|
-
};
|
|
116
|
-
type ScopeEvents<T extends Record<string, any>, Prefix extends string> = PickScopeEvents<T, Prefix>;
|
|
117
139
|
type FastEventListenOptions<Events extends Record<string, any> = Record<string, any>, Meta = any> = {
|
|
118
140
|
count?: number;
|
|
119
141
|
prepend?: boolean;
|
|
@@ -160,9 +182,7 @@ type OptionalItems<T, K extends keyof T> = Expand<Omit<T, K> & {
|
|
|
160
182
|
type DeepPartial<T> = {
|
|
161
183
|
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
162
184
|
};
|
|
163
|
-
type Fallback<T, F> = [
|
|
164
|
-
T
|
|
165
|
-
] extends [never] ? F : T extends undefined ? F : T;
|
|
185
|
+
type Fallback<T, F> = [T] extends [never] ? F : T extends undefined ? F : T;
|
|
166
186
|
type ChangeFieldType<Record, Name extends string, Type = any> = Expand<Omit<Record, Name> & {
|
|
167
187
|
[K in Name]: Type;
|
|
168
188
|
}>;
|
|
@@ -191,16 +211,7 @@ type Overloads<T> = Unique<T extends {
|
|
|
191
211
|
(...args: infer A6): infer R6;
|
|
192
212
|
(...args: infer A7): infer R7;
|
|
193
213
|
(...args: infer A8): infer R8;
|
|
194
|
-
} ? [
|
|
195
|
-
(...args: A1) => R1,
|
|
196
|
-
((...args: A2) => R2),
|
|
197
|
-
((...args: A3) => R3),
|
|
198
|
-
((...args: A4) => R4),
|
|
199
|
-
((...args: A5) => R5),
|
|
200
|
-
((...args: A6) => R6),
|
|
201
|
-
((...args: A7) => R7),
|
|
202
|
-
((...args: A8) => R8)
|
|
203
|
-
] : T extends {
|
|
214
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6, (...args: A7) => R7, (...args: A8) => R8] : T extends {
|
|
204
215
|
(...args: infer A1): infer R1;
|
|
205
216
|
(...args: infer A2): infer R2;
|
|
206
217
|
(...args: infer A3): infer R3;
|
|
@@ -208,75 +219,42 @@ type Overloads<T> = Unique<T extends {
|
|
|
208
219
|
(...args: infer A5): infer R5;
|
|
209
220
|
(...args: infer A6): infer R6;
|
|
210
221
|
(...args: infer A7): infer R7;
|
|
211
|
-
} ? [
|
|
212
|
-
(...args: A1) => R1,
|
|
213
|
-
((...args: A2) => R2),
|
|
214
|
-
((...args: A3) => R3),
|
|
215
|
-
((...args: A4) => R4),
|
|
216
|
-
((...args: A5) => R5),
|
|
217
|
-
((...args: A6) => R6),
|
|
218
|
-
((...args: A7) => R7)
|
|
219
|
-
] : T extends {
|
|
222
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6, (...args: A7) => R7] : T extends {
|
|
220
223
|
(...args: infer A1): infer R1;
|
|
221
224
|
(...args: infer A2): infer R2;
|
|
222
225
|
(...args: infer A3): infer R3;
|
|
223
226
|
(...args: infer A4): infer R4;
|
|
224
227
|
(...args: infer A5): infer R5;
|
|
225
228
|
(...args: infer A6): infer R6;
|
|
226
|
-
} ? [
|
|
227
|
-
(...args: A1) => R1,
|
|
228
|
-
((...args: A2) => R2),
|
|
229
|
-
((...args: A3) => R3),
|
|
230
|
-
((...args: A4) => R4),
|
|
231
|
-
((...args: A5) => R5),
|
|
232
|
-
((...args: A6) => R6)
|
|
233
|
-
] : T extends {
|
|
229
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5, (...args: A6) => R6] : T extends {
|
|
234
230
|
(...args: infer A1): infer R1;
|
|
235
231
|
(...args: infer A2): infer R2;
|
|
236
232
|
(...args: infer A3): infer R3;
|
|
237
233
|
(...args: infer A4): infer R4;
|
|
238
234
|
(...args: infer A5): infer R5;
|
|
239
|
-
} ? [
|
|
240
|
-
(...args: A1) => R1,
|
|
241
|
-
((...args: A2) => R2),
|
|
242
|
-
((...args: A3) => R3),
|
|
243
|
-
((...args: A4) => R4),
|
|
244
|
-
((...args: A5) => R5)
|
|
245
|
-
] : T extends {
|
|
235
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4, (...args: A5) => R5] : T extends {
|
|
246
236
|
(...args: infer A1): infer R1;
|
|
247
237
|
(...args: infer A2): infer R2;
|
|
248
238
|
(...args: infer A3): infer R3;
|
|
249
239
|
(...args: infer A4): infer R4;
|
|
250
|
-
} ? [
|
|
251
|
-
(...args: A1) => R1,
|
|
252
|
-
((...args: A2) => R2),
|
|
253
|
-
((...args: A3) => R3),
|
|
254
|
-
((...args: A4) => R4)
|
|
255
|
-
] : T extends {
|
|
240
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3, (...args: A4) => R4] : T extends {
|
|
256
241
|
(...args: infer A1): infer R1;
|
|
257
242
|
(...args: infer A2): infer R2;
|
|
258
243
|
(...args: infer A3): infer R3;
|
|
259
|
-
} ? [
|
|
260
|
-
((...args: A1) => R1),
|
|
261
|
-
((...args: A2) => R2),
|
|
262
|
-
((...args: A3) => R3)
|
|
263
|
-
] : T extends {
|
|
244
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2, (...args: A3) => R3] : T extends {
|
|
264
245
|
(...args: infer A1): infer R1;
|
|
265
246
|
(...args: infer A2): infer R2;
|
|
266
|
-
} ? [
|
|
267
|
-
((...args: A1) => R1),
|
|
268
|
-
((...args: A2) => R2)
|
|
269
|
-
] : T extends {
|
|
247
|
+
} ? [(...args: A1) => R1, (...args: A2) => R2] : T extends {
|
|
270
248
|
(...args: infer A1): infer R1;
|
|
271
|
-
} ? [
|
|
272
|
-
(...args: A1) => R1
|
|
273
|
-
] : [
|
|
274
|
-
T
|
|
275
|
-
]>;
|
|
249
|
+
} ? [(...args: A1) => R1] : [T]>;
|
|
276
250
|
type Dict<V = any> = Record<Exclude<string, number | symbol>, V>;
|
|
277
251
|
type Union<T> = T extends infer O ? {
|
|
278
252
|
[K in keyof O]: O[K];
|
|
279
253
|
} : never;
|
|
254
|
+
type RecordValues<R extends Record<string, any>> = R[keyof R];
|
|
255
|
+
type RecordPrefix<P extends string, R extends Record<string, any>> = {
|
|
256
|
+
[K in keyof R as K extends `${P}/${infer S}` ? S : never]: R[K];
|
|
257
|
+
};
|
|
280
258
|
|
|
281
259
|
type FastEventBusMessage<Events extends Record<string, any> = Record<string, any>, M = any> = FastEventEmitMessage<Events, M> & {
|
|
282
260
|
from?: string;
|
|
@@ -342,7 +320,7 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
342
320
|
on<T extends string>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
343
321
|
on(type: '**', options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
344
322
|
on<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
345
|
-
on<T extends string>(type: T, listener: TypedFastEventListener<
|
|
323
|
+
on<T extends string>(type: T, listener: TypedFastEventListener<Exclude<keyof MatchEventType<T, Events>, number | symbol>, RecordValues<MatchEventType<T, Events>>, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
346
324
|
on(type: '**', listener: TypedFastEventAnyListener<Events, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
347
325
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
348
326
|
once<T extends string>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
@@ -362,9 +340,9 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
362
340
|
emit(type: Types, directive: symbol): void;
|
|
363
341
|
emit(type: string, directive: symbol): void;
|
|
364
342
|
emit<R = any, T extends Types = Types>(type: T, payload?: Events[T], retain?: boolean): R[];
|
|
365
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] :
|
|
343
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : RecordValues<MatchEventType<T, Events>>, retain?: boolean): R[];
|
|
366
344
|
emit<R = any>(type: Types, payload?: Events[Types], options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
367
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] :
|
|
345
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : RecordValues<MatchEventType<T, Events>>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
368
346
|
emit<R = any>(message: FastEventEmitMessage<Events, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
369
347
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
370
348
|
[K in T]: K extends Types ? Events[K] : any;
|
|
@@ -416,7 +394,7 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
416
394
|
* ```
|
|
417
395
|
*/
|
|
418
396
|
scope<E extends Record<string, any> = Record<string, any>, P extends string = string, M extends Record<string, any> = Record<string, any>, C = Context>(prefix: P, options?: DeepPartial<FastEventScopeOptions<Partial<FinalMeta> & M, C>>): FastEventScope<ScopeEvents<Events, P> & E, FinalMeta & M, C>;
|
|
419
|
-
scope<E extends Record<string, any> = Record<string, any>, P extends string = string, M extends Record<string, any> = Record<string, any>, C = Context, ScopeInstance extends FastEventScope<any, any, any> = FastEventScope<ScopeEvents<
|
|
397
|
+
scope<E extends Record<string, any> = Record<string, any>, P extends string = string, M extends Record<string, any> = Record<string, any>, C = Context, ScopeInstance extends FastEventScope<any, any, any> = FastEventScope<ScopeEvents<Events, P> & E, FinalMeta & M, C>>(prefix: P, scopeObj: ScopeInstance, options?: DeepPartial<FastEventScopeOptions<Partial<FinalMeta> & M, C>>): ScopeInstance & FastEventScope<ScopeEvents<Events, P> & E, FinalMeta & M, C>;
|
|
420
398
|
/**
|
|
421
399
|
* 当on/once/onAny未指定监听器时,此为默认监听器
|
|
422
400
|
* @param message
|
|
@@ -538,7 +516,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
538
516
|
on<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
539
517
|
on(type: '**', options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
540
518
|
on<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, AllEvents[T], Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
541
|
-
on<T extends string>(type: T, listener: TypedFastEventAnyListener<
|
|
519
|
+
on<T extends string>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, AllEvents>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
542
520
|
on(type: '**', listener: TypedFastEventAnyListener<Record<string, any>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
543
521
|
/**
|
|
544
522
|
* 注册一次性事件监听器
|
|
@@ -564,7 +542,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
564
542
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
565
543
|
once<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
566
544
|
once<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, AllEvents[T], Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
567
|
-
once<T extends string>(type: T, listener: TypedFastEventAnyListener<
|
|
545
|
+
once<T extends string>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, AllEvents>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
568
546
|
/**
|
|
569
547
|
* 注册一个监听器,用于监听所有事件
|
|
570
548
|
* @param listener 事件监听器函数,可以接收任意类型的事件数据
|
|
@@ -753,13 +731,13 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
753
731
|
emit<T extends Types = Types>(type: T, directive: symbol): any[];
|
|
754
732
|
emit(type: string, directive: symbol): any[];
|
|
755
733
|
emit<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], retain?: boolean): R[];
|
|
756
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] :
|
|
734
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : RecordValues<MatchEventType<T, AllEvents>>, retain?: boolean): R[];
|
|
757
735
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
758
736
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
759
737
|
}, Meta>, retain?: boolean): R[];
|
|
760
738
|
emit<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, retain?: boolean): R[];
|
|
761
739
|
emit<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T], options?: FastEventListenerArgs<Meta>): R[];
|
|
762
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] :
|
|
740
|
+
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : RecordValues<MatchEventType<T, AllEvents>>, options?: FastEventListenerArgs<Meta>): R[];
|
|
763
741
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
764
742
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
765
743
|
}, Meta>, options?: FastEventListenerArgs<Meta>): R[];
|
|
@@ -892,6 +870,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
892
870
|
* userEvents.offAll(); // 清理 'user' 前缀下的所有事件
|
|
893
871
|
* ```
|
|
894
872
|
*/
|
|
873
|
+
scope<P extends string>(prefix: P, options?: DeepPartial<FastEventScopeOptions<Meta, Context>>): FastEventScope<ScopeEvents<AllEvents, P>, Meta, Context>;
|
|
895
874
|
scope<E extends Record<string, any> = Record<string, any>, P extends string = string, M extends Record<string, any> = Record<string, any>, C = Context>(prefix: P, options?: DeepPartial<FastEventScopeOptions<Meta & M, C>>): FastEventScope<ScopeEvents<AllEvents, P> & E, Meta & M, C>;
|
|
896
875
|
scope<E extends Record<string, any> = Record<string, any>, P extends string = string, M extends Record<string, any> = Record<string, any>, C = Context, ScopeObject extends FastEventScope<any, any, any> = FastEventScope<ScopeEvents<AllEvents, P> & E, Meta & M, C>>(prefix: P, scopeObj: ScopeObject, options?: DeepPartial<FastEventScopeOptions<Meta & M, C>>): ScopeObject;
|
|
897
876
|
}
|
|
@@ -924,7 +903,7 @@ declare class FastEventBusNode<Events extends Record<string, any> = Record<strin
|
|
|
924
903
|
* 加入事件总线
|
|
925
904
|
* @param eventBus 要加入的事件总线
|
|
926
905
|
*/
|
|
927
|
-
connect(eventbus: FastEventBus<any>): void;
|
|
906
|
+
connect(eventbus: FastEventBus<any, any, any>): void;
|
|
928
907
|
disconnect(): void;
|
|
929
908
|
/**
|
|
930
909
|
*
|
|
@@ -1152,4 +1131,4 @@ declare function isClass(target: unknown): target is new (...args: any[]) => any
|
|
|
1152
1131
|
|
|
1153
1132
|
declare function isFastEvent(target: any): target is FastEvent;
|
|
1154
1133
|
|
|
1155
|
-
export { AbortError, BroadcastEvent, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type Fallback, FastEvent, FastEventBus, type FastEventBusEventTypes, type FastEventBusEvents, type FastEventBusMessage, FastEventBusNode, type FastEventBusNodeIds, type FastEventBusNodeOptions, type FastEventBusNodes, type FastEventBusOptions, FastEventDirectives, type FastEventEmitMessage, FastEventError, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, type FastEventListeners, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListenerMeta, type FastListenerNode, type FastListeners, type Merge, NamespaceDelimiter, NodeDataEvent, type ObjectKeys, type OptionalItems, type Overloads, type OverrideOptions, type
|
|
1134
|
+
export { AbortError, BroadcastEvent, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type Fallback, FastEvent, FastEventBus, type FastEventBusEventTypes, type FastEventBusEvents, type FastEventBusMessage, FastEventBusNode, type FastEventBusNodeIds, type FastEventBusNodeOptions, type FastEventBusNodes, type FastEventBusOptions, FastEventDirectives, type FastEventEmitMessage, FastEventError, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, type FastEventListeners, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListenerMeta, type FastListenerNode, type FastListeners, type MatchEventType, type Merge, type MergeUnion, NamespaceDelimiter, NodeDataEvent, type ObjectKeys, type OptionalItems, type Overloads, type OverrideOptions, QueueOverflowError, type RecordPrefix, type RecordValues, type RequiredItems, type ScopeEvents, TimeoutError, type TypedFastEventAnyListener, type TypedFastEventListener, type TypedFastEventMessage, type TypedFastEventMessageOptional, UnboundError, type Union, type Unique, __FastEventScope__, __FastEvent__, __expandable__, expandable, isClass, isExpandable, isFastEvent, isFastEventMessage, isFastEventScope, isFunction, isPathMatched, isString, isSubsctiber };
|