fastevent 2.2.11 → 2.3.0
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 +135 -43
- package/dist/eventbus/index.d.ts +135 -43
- 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 +15 -3
- package/dist/executors/index.d.ts +15 -3
- package/dist/index.d.mts +133 -41
- package/dist/index.d.ts +133 -41
- 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 +15 -3
- package/dist/pipes/index.d.ts +15 -3
- package/package.json +1 -1
|
@@ -2,30 +2,44 @@ type FastListenerExecutor = (listeners: FastListenerMeta[], message: TypedFastEv
|
|
|
2
2
|
|
|
3
3
|
type FastListenerPipe = (listener: TypedFastEventListener) => TypedFastEventListener;
|
|
4
4
|
|
|
5
|
+
type Expand$1<T> = T extends infer O ? {
|
|
6
|
+
[K in keyof O]: O[K];
|
|
7
|
+
} : never;
|
|
8
|
+
type ContainsWildcard<T extends string> = T extends `${string}/*/${string}` ? true : T extends `${string}/*` ? true : T extends `*/${string}` ? true : T extends `*` ? true : false;
|
|
9
|
+
type ReplaceWildcard<T extends string> = T extends `*${infer Rest}` ? `${string}${ReplaceWildcard<Rest>}` : T extends `${infer Head}*${infer Rest}` ? `${Head}${string}${ReplaceWildcard<Rest>}` : T;
|
|
10
|
+
type WildcardKeys<T> = {
|
|
11
|
+
[K in keyof T]: K extends string ? (ContainsWildcard<K> extends true ? K : never) : never;
|
|
12
|
+
}[keyof T];
|
|
13
|
+
type ExpandWildcard<T extends Record<string, any>> = Expand$1<T & {
|
|
14
|
+
[K in WildcardKeys<T> as ReplaceWildcard<K>]: T[K];
|
|
15
|
+
}>;
|
|
16
|
+
|
|
5
17
|
type MergeUnion<T> = (T extends any ? (x: T) => void : never) extends (x: infer U) => void ? {
|
|
6
18
|
[K in keyof U]: U[K];
|
|
7
19
|
} : never;
|
|
8
20
|
type Split$1<S extends string, Delimiter extends string = '/'> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split$1<Tail, Delimiter>] : [S];
|
|
9
21
|
type MatchSegment<Input extends string, Pattern extends string> = Pattern extends '*' ? true : Pattern extends '**' ? true : Input extends Pattern ? true : false;
|
|
10
22
|
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
|
|
23
|
+
type MatchPattern<T extends string, Pattern extends string> = MatchPatternArray<Split$1<T>, Split$1<Pattern>> extends true ? {
|
|
12
24
|
[K in Pattern]: any;
|
|
13
25
|
} : never;
|
|
14
26
|
type Fallback$1<T, F> = [T] extends [never] ? F : T extends undefined ? F : T;
|
|
15
27
|
type MatchEventType<T extends string, Events extends Record<string, any>> = MergeUnion<Fallback$1<{
|
|
16
|
-
[K in keyof Events]: MatchPattern
|
|
28
|
+
[K in keyof Events]: MatchPattern<T, K & string> extends never ? never : {
|
|
17
29
|
[P in K]: Events[K];
|
|
18
30
|
};
|
|
19
|
-
}[keyof Events] extends infer Result ? Result extends Record<string, any> ? Result : any :
|
|
31
|
+
}[keyof Events] extends infer Result ? Result extends Record<string, any> ? Result : Record<string, any> : Record<string, any>, {
|
|
20
32
|
[K in T]: any;
|
|
21
33
|
}>>;
|
|
34
|
+
type MatchEventPayload<Events extends Record<string, any>, T> = T extends keyof Events ? Events[T] : T extends string ? T extends keyof MatchEventType<T, Events> ? MatchEventType<T, Events>[T] : any : any;
|
|
22
35
|
|
|
23
36
|
type Split<S extends string, Delimiter extends string> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split<Tail, Delimiter>] : [S];
|
|
24
|
-
type
|
|
37
|
+
type MatchPatternAndGetRemainder<KeyParts extends string[], PrefixParts extends string[], Result extends string[] = []> = PrefixParts['length'] extends 0 ? KeyParts['length'] extends 0 ? never : KeyParts : KeyParts['length'] extends 0 ? never : KeyParts[0] extends PrefixParts[0] | '*' ? MatchPatternAndGetRemainder<Slice<KeyParts, 1>, Slice<PrefixParts, 1>, Result> : never;
|
|
25
38
|
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
39
|
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;
|
|
40
|
+
type Join<T extends string[], Delimiter extends string = '/'> = T extends [infer First extends string, ...infer Rest extends string[]] ? Rest['length'] extends 0 ? First : `${First}${Delimiter}${Join<Rest, Delimiter>}` : '';
|
|
27
41
|
type ScopeEvents<Events extends Record<string, any>, Prefix extends string> = {
|
|
28
|
-
[K in keyof Events as K extends string ?
|
|
42
|
+
[K in keyof Events as K extends string ? MatchPatternAndGetRemainder<Split<K, '/'>, Split<Prefix, '/'>> extends infer Remainder ? Remainder extends string[] ? Join<Remainder, '/'> : never : never : never]: Events[K];
|
|
29
43
|
};
|
|
30
44
|
|
|
31
45
|
interface FastEventMeta {
|
|
@@ -58,9 +72,11 @@ type FastEventEmitMessage<Events extends Record<string, any> = Record<string, an
|
|
|
58
72
|
meta?: DeepPartial<FastEventMeta & M & Record<string, any>>;
|
|
59
73
|
};
|
|
60
74
|
}[Exclude<keyof Events, number | symbol>] & FastEventMessageExtends;
|
|
61
|
-
type
|
|
62
|
-
|
|
63
|
-
|
|
75
|
+
type FastMessagePayload<P = any> = {
|
|
76
|
+
type: P;
|
|
77
|
+
__IS_FAST_MESSAGE__: true;
|
|
78
|
+
};
|
|
79
|
+
type TypedFastEventListener<T extends string = string, P = any, M = any, C = any> = (this: C, message: TypedFastEventMessage<Record<T, P>, M>, args: FastEventListenerArgs<M>) => any | Promise<any>;
|
|
64
80
|
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>;
|
|
65
81
|
type FastEventListeners<Events extends Record<string, any> = Record<string, any>, M = any, C = any> = {
|
|
66
82
|
[K in keyof Events]: TypedFastEventListener<Exclude<K, number | symbol>, Events[K], M, C>;
|
|
@@ -133,6 +149,16 @@ type FastEventOptions<Meta = Record<string, any>, Context = never> = {
|
|
|
133
149
|
executor?: FastListenerExecutor;
|
|
134
150
|
onMessage?: TypedFastEventListener;
|
|
135
151
|
expandEmitResults?: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* 对接收到的消息进行转换,用于将消息转换成其他格式
|
|
154
|
+
*
|
|
155
|
+
* new FastEvent({
|
|
156
|
+
* transform:(message)=>{
|
|
157
|
+
* message.payload
|
|
158
|
+
* }
|
|
159
|
+
* })
|
|
160
|
+
*/
|
|
161
|
+
transform?: (message: FastEventMessage) => any;
|
|
136
162
|
};
|
|
137
163
|
interface FastEvents {
|
|
138
164
|
}
|
|
@@ -150,6 +176,9 @@ type FastEventListenOptions<Events extends Record<string, any> = Record<string,
|
|
|
150
176
|
*/
|
|
151
177
|
tag?: string;
|
|
152
178
|
};
|
|
179
|
+
declare enum FastEventListenerFlags {
|
|
180
|
+
Transformed = 1
|
|
181
|
+
}
|
|
153
182
|
type FastEventListenerArgs<M = Record<string, any>> = {
|
|
154
183
|
retain?: boolean;
|
|
155
184
|
meta?: DeepPartial<M> & Record<string, any>;
|
|
@@ -166,6 +195,17 @@ type FastEventListenerArgs<M = Record<string, any>> = {
|
|
|
166
195
|
* 当emit参数解析完成后的回调,用于修改emit参数
|
|
167
196
|
*/
|
|
168
197
|
parseArgs?: (message: TypedFastEventMessage, args: FastEventListenerArgs) => void;
|
|
198
|
+
/**
|
|
199
|
+
* 额外的标识
|
|
200
|
+
*
|
|
201
|
+
* - 1: transformed 当消息是经过transform转换后的消息时的标识
|
|
202
|
+
*
|
|
203
|
+
*/
|
|
204
|
+
flags?: FastEventListenerFlags;
|
|
205
|
+
/**
|
|
206
|
+
* 如果消息经过转换前的原主题
|
|
207
|
+
*/
|
|
208
|
+
rawEventType?: string;
|
|
169
209
|
};
|
|
170
210
|
type Merge<T extends object, U extends object> = {
|
|
171
211
|
[K in keyof T | keyof U]: K extends keyof U ? U[K] : K extends keyof T ? T[K] : never;
|
|
@@ -255,6 +295,52 @@ type RecordValues<R extends Record<string, any>> = R[keyof R];
|
|
|
255
295
|
type RecordPrefix<P extends string, R extends Record<string, any>> = {
|
|
256
296
|
[K in keyof R as K extends `${P}/${infer S}` ? S : never]: R[K];
|
|
257
297
|
};
|
|
298
|
+
/**
|
|
299
|
+
* 声明事件类型时,一般情况下,K=事件名称,V=事件Payload参数类型
|
|
300
|
+
*
|
|
301
|
+
* AssertFastMessage用于声明V是一个FastMessage类型,而不是Payload类型
|
|
302
|
+
*
|
|
303
|
+
* 一般配合transform参数使用
|
|
304
|
+
*
|
|
305
|
+
* 例如:
|
|
306
|
+
* type CustomEvents = {
|
|
307
|
+
click: { x: number; y: number };
|
|
308
|
+
}
|
|
309
|
+
const emitter = new FastEvent<CustomEvents>();
|
|
310
|
+
emitter.on('click', (message) => {
|
|
311
|
+
// typeof message.payload === { x: number; y: number }
|
|
312
|
+
})
|
|
313
|
+
const emitter = new FastEvent<CustomEvents>({
|
|
314
|
+
transform:(message)=>{
|
|
315
|
+
if(message.type === 'click'){
|
|
316
|
+
return message.payload
|
|
317
|
+
}else{
|
|
318
|
+
return message
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
emitter.on('click', (message) => {
|
|
323
|
+
// typeof message === { x: number; y: number }
|
|
324
|
+
}
|
|
325
|
+
*/
|
|
326
|
+
type AssertFastMessage<M> = {
|
|
327
|
+
type: M;
|
|
328
|
+
__IS_FAST_MESSAGE__: true;
|
|
329
|
+
};
|
|
330
|
+
type NotPayload<M> = AssertFastMessage<M>;
|
|
331
|
+
type PickPayload<M> = M extends FastMessagePayload ? M['type'] : M;
|
|
332
|
+
type AtPayloads<Events extends Record<string, any>> = {
|
|
333
|
+
[K in keyof Events]: PickPayload<Events[K]>;
|
|
334
|
+
};
|
|
335
|
+
type PickTransformedEvents<T extends Record<string, any>> = ExpandWildcard<{
|
|
336
|
+
[key in keyof T as T[key] extends FastMessagePayload ? key : never]: T[key];
|
|
337
|
+
}>;
|
|
338
|
+
type OmitTransformedEvents<T extends Record<string, any>> = {
|
|
339
|
+
[key in keyof T as T[key] extends FastMessagePayload ? never : key]: T[key];
|
|
340
|
+
};
|
|
341
|
+
type TransformedEvents<Events extends Record<string, any>> = {
|
|
342
|
+
[K in keyof Events]: NotPayload<Events[K]>;
|
|
343
|
+
};
|
|
258
344
|
|
|
259
345
|
type FastEventBusMessage<Events extends Record<string, any> = Record<string, any>, M = any> = FastEventEmitMessage<Events, M> & {
|
|
260
346
|
from?: string;
|
|
@@ -317,15 +403,17 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
317
403
|
private _getScopeType;
|
|
318
404
|
private _fixScopeType;
|
|
319
405
|
on<T extends Types = Types>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
320
|
-
on<T extends string
|
|
406
|
+
on<T extends Exclude<string, Types>>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
321
407
|
on(type: '**', options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
322
|
-
on<T extends
|
|
323
|
-
on<T extends
|
|
408
|
+
on<T extends keyof OmitTransformedEvents<Events>>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
409
|
+
on<T extends keyof PickTransformedEvents<Events>>(type: T, listener: (message: PickPayload<RecordValues<MatchEventType<Exclude<T, number | symbol>, Events>>>, args: FastEventListenerArgs<Meta>) => any | Promise<any>, options?: FastEventListenOptions<Events, Meta>): FastEventSubscriber;
|
|
410
|
+
on<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, Events>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
324
411
|
on(type: '**', listener: TypedFastEventAnyListener<Events, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
325
412
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
326
|
-
once<T extends string
|
|
327
|
-
once<T extends
|
|
328
|
-
once<T extends
|
|
413
|
+
once<T extends Exclude<string, Types>>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
414
|
+
once<T extends keyof OmitTransformedEvents<Events>>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
415
|
+
once<T extends keyof PickTransformedEvents<Events>>(type: T, listener: (message: PickPayload<RecordValues<MatchEventType<Exclude<T, number | symbol>, Events>>>, args: FastEventListenerArgs<Meta>) => any | Promise<any>, options?: FastEventListenOptions<Events, Meta>): FastEventSubscriber;
|
|
416
|
+
once<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, Events>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
329
417
|
onAny(options?: Pick<FastEventListenOptions, 'prepend'>): FastEventSubscriber;
|
|
330
418
|
onAny<P = any>(listener: TypedFastEventAnyListener<{
|
|
331
419
|
[K: string]: P;
|
|
@@ -339,19 +427,20 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
339
427
|
clear(): void;
|
|
340
428
|
emit(type: Types, directive: symbol): void;
|
|
341
429
|
emit(type: string, directive: symbol): void;
|
|
342
|
-
emit<R = any, T extends Types = Types>(type: T, payload?: Events[T]
|
|
343
|
-
emit<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : RecordValues<MatchEventType<T, Events
|
|
344
|
-
emit<R = any>(type:
|
|
345
|
-
emit<R = any
|
|
346
|
-
emit<R = any>(message: FastEventEmitMessage<Events, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
430
|
+
emit<R = any, T extends Types = Types>(type: T, payload?: PickPayload<Events[T]>, retain?: boolean): R[];
|
|
431
|
+
emit<R = any, T extends string = string>(type: T, payload?: PickPayload<T extends Types ? Events[T] : RecordValues<MatchEventType<T, Events>>>, retain?: boolean): R[];
|
|
432
|
+
emit<R = any, T extends string = string>(type: T, payload?: PickPayload<T extends Types ? Events[T] : RecordValues<MatchEventType<T, Events>>>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
433
|
+
emit<R = any>(message: FastEventEmitMessage<AtPayloads<Events>, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
347
434
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
348
|
-
[K in T]: K extends Types ? Events[K] : any
|
|
435
|
+
[K in T]: PickPayload<K extends Types ? Events[K] : any>;
|
|
349
436
|
}, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
350
|
-
emitAsync<R = any, T extends Types = Types>(type: T, payload?: Events[T]
|
|
351
|
-
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : any
|
|
352
|
-
emitAsync<R = any, T extends Types = Types>(type: T, payload?: Events[T]
|
|
353
|
-
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? Events[T] : any
|
|
354
|
-
emitAsync<R = any
|
|
437
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: PickPayload<Events[T]>, retain?: boolean): Promise<[R | Error][]>;
|
|
438
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: PickPayload<T extends Types ? Events[T] : any>, retain?: boolean): Promise<[R | Error][]>;
|
|
439
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: PickPayload<Events[T]>, options?: FastEventListenerArgs<FinalMeta>): Promise<[R | Error][]>;
|
|
440
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: PickPayload<T extends Types ? Events[T] : any>, options?: FastEventListenerArgs<FinalMeta>): Promise<[R | Error][]>;
|
|
441
|
+
emitAsync<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
442
|
+
[K in T]: PickPayload<K extends Types ? Events[K] : any>;
|
|
443
|
+
}, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): Promise<[R | Error][]>;
|
|
355
444
|
waitFor<T extends Types>(type: T, timeout?: number): Promise<TypedFastEventMessage<{
|
|
356
445
|
[key in T]: Events[T];
|
|
357
446
|
}, FinalMeta>>;
|
|
@@ -515,8 +604,9 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
515
604
|
on<T extends Types = Types>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
516
605
|
on<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
517
606
|
on(type: '**', options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
518
|
-
on<T extends
|
|
519
|
-
on<T extends
|
|
607
|
+
on<T extends keyof OmitTransformedEvents<AllEvents>>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, AllEvents[T], Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
608
|
+
on<T extends keyof PickTransformedEvents<AllEvents>>(type: T, listener: (message: PickPayload<RecordValues<MatchEventType<Exclude<T, number | symbol>, AllEvents>>>, args: FastEventListenerArgs<Meta>) => any | Promise<any>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
609
|
+
on<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, AllEvents>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
520
610
|
on(type: '**', listener: TypedFastEventAnyListener<Record<string, any>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
521
611
|
/**
|
|
522
612
|
* 注册一次性事件监听器
|
|
@@ -541,8 +631,9 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
541
631
|
*/
|
|
542
632
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
543
633
|
once<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
544
|
-
once<T extends
|
|
545
|
-
once<T extends
|
|
634
|
+
once<T extends keyof OmitTransformedEvents<AllEvents>>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, AllEvents[T], Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
635
|
+
once<T extends keyof PickTransformedEvents<AllEvents>>(type: T, listener: (message: PickPayload<RecordValues<MatchEventType<Exclude<T, number | symbol>, AllEvents>>>, args: FastEventListenerArgs<Meta>) => any | Promise<any>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
636
|
+
once<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<MatchEventType<T, AllEvents>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
546
637
|
/**
|
|
547
638
|
* 注册一个监听器,用于监听所有事件
|
|
548
639
|
* @param listener 事件监听器函数,可以接收任意类型的事件数据
|
|
@@ -628,6 +719,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
628
719
|
private _traverseToPath;
|
|
629
720
|
private _traverseListeners;
|
|
630
721
|
private _onListenerError;
|
|
722
|
+
private _setListenerFlags;
|
|
631
723
|
/**
|
|
632
724
|
* 执行单个监听器函数
|
|
633
725
|
* @param listener - 要执行的监听器函数或包装过的监听器对象
|
|
@@ -730,16 +822,16 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
730
822
|
*/
|
|
731
823
|
emit<T extends Types = Types>(type: T, directive: symbol): any[];
|
|
732
824
|
emit(type: string, directive: symbol): any[];
|
|
733
|
-
emit<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T]
|
|
734
|
-
emit<R = any, T extends string = string>(type: T, payload
|
|
825
|
+
emit<R = any, T extends Types = Types>(type: T, payload?: PickPayload<AllEvents[T]>, retain?: boolean): R[];
|
|
826
|
+
emit<R = any, T extends string = string>(type: T, payload: PickPayload<T extends Types ? AllEvents[T] : RecordValues<MatchEventType<T, AllEvents>>>, retain?: boolean): R[];
|
|
735
827
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
736
828
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
737
829
|
}, Meta>, retain?: boolean): R[];
|
|
738
830
|
emit<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, retain?: boolean): R[];
|
|
739
|
-
emit<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T]
|
|
740
|
-
emit<R = any, T extends string = string>(type: T, payload
|
|
831
|
+
emit<R = any, T extends Types = Types>(type: T, payload?: PickPayload<AllEvents[T]>, options?: FastEventListenerArgs<Meta>): R[];
|
|
832
|
+
emit<R = any, T extends string = string>(type: T, payload: PickPayload<T extends Types ? AllEvents[T] : RecordValues<MatchEventType<T, AllEvents>>>, options?: FastEventListenerArgs<Meta>): R[];
|
|
741
833
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
742
|
-
[K in T]: K extends Types ? AllEvents[K] : any
|
|
834
|
+
[K in T]: PickPayload<K extends Types ? AllEvents[K] : any>;
|
|
743
835
|
}, Meta>, options?: FastEventListenerArgs<Meta>): R[];
|
|
744
836
|
emit<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, options?: FastEventListenerArgs<Meta>): R[];
|
|
745
837
|
/**
|
|
@@ -778,16 +870,16 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
778
870
|
* });
|
|
779
871
|
* ```
|
|
780
872
|
*/
|
|
781
|
-
emitAsync<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T]
|
|
782
|
-
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : any
|
|
873
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: PickPayload<AllEvents[T]>, retain?: boolean): Promise<[R | Error][]>;
|
|
874
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: PickPayload<T extends Types ? AllEvents[T] : any>, retain?: boolean): Promise<[R | Error][]>;
|
|
783
875
|
emitAsync<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
784
|
-
[K in T]: K extends Types ? AllEvents[K] : any
|
|
876
|
+
[K in T]: PickPayload<K extends Types ? AllEvents[K] : any>;
|
|
785
877
|
}, Meta>, retain?: boolean): Promise<[R | Error][]>;
|
|
786
878
|
emitAsync<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, retain?: boolean): Promise<[R | Error][]>;
|
|
787
|
-
emitAsync<R = any, T extends string = string>(type: T, payload?: T extends Types ? AllEvents[T] : any
|
|
788
|
-
emitAsync<R = any, T extends Types = Types>(type: T, payload?: AllEvents[T]
|
|
879
|
+
emitAsync<R = any, T extends string = string>(type: T, payload?: PickPayload<T extends Types ? AllEvents[T] : any>, options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
880
|
+
emitAsync<R = any, T extends Types = Types>(type: T, payload?: PickPayload<AllEvents[T]>, options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
789
881
|
emitAsync<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
790
|
-
[K in T]: K extends Types ? AllEvents[K] : any
|
|
882
|
+
[K in T]: PickPayload<K extends Types ? AllEvents[K] : any>;
|
|
791
883
|
}, Meta>, options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
792
884
|
emitAsync<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, options?: FastEventListenerArgs<Meta>): Promise<[R | Error][]>;
|
|
793
885
|
/**
|
|
@@ -877,7 +969,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
877
969
|
|
|
878
970
|
type FastEventBusNodeOptions<Meta = Record<string, any>, Context = any> = FastEventOptions<Meta, Context> & {};
|
|
879
971
|
declare class FastEventBusNode<Events extends Record<string, any> = Record<string, any>, Meta extends Record<string, any> = Record<string, any>, Context = never> extends FastEvent<Events, Meta, Context> {
|
|
880
|
-
eventbus?: FastEventBus<any, any, any>;
|
|
972
|
+
eventbus?: FastEventBus<any, any, any, any, any>;
|
|
881
973
|
private _subscribers;
|
|
882
974
|
constructor(options?: DeepPartial<FastEventBusNodeOptions<Meta, Context>>);
|
|
883
975
|
/**
|
|
@@ -903,7 +995,7 @@ declare class FastEventBusNode<Events extends Record<string, any> = Record<strin
|
|
|
903
995
|
* 加入事件总线
|
|
904
996
|
* @param eventBus 要加入的事件总线
|
|
905
997
|
*/
|
|
906
|
-
connect(eventbus: FastEventBus<
|
|
998
|
+
connect<E extends Record<string, any> = Record<string, any>, M extends Record<string, any> = Record<string, any>, C = any>(eventbus: FastEventBus<E, M, C>): void;
|
|
907
999
|
disconnect(): void;
|
|
908
1000
|
/**
|
|
909
1001
|
*
|
|
@@ -1131,4 +1223,4 @@ declare function isClass(target: unknown): target is new (...args: any[]) => any
|
|
|
1131
1223
|
|
|
1132
1224
|
declare function isFastEvent(target: any): target is FastEvent;
|
|
1133
1225
|
|
|
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 };
|
|
1226
|
+
export { AbortError, type AssertFastMessage, type AtPayloads, BroadcastEvent, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type ExpandWildcard, 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, FastEventListenerFlags, 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 FastMessagePayload, type MatchEventPayload, type MatchEventType, type Merge, type MergeUnion, NamespaceDelimiter, NodeDataEvent, type NotPayload, type ObjectKeys, type OmitTransformedEvents, type OptionalItems, type Overloads, type OverrideOptions, type PickPayload, type PickTransformedEvents, QueueOverflowError, type RecordPrefix, type RecordValues, type RequiredItems, type ScopeEvents, TimeoutError, type TransformedEvents, 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 };
|