fastevent 2.3.2 → 2.3.3
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 +39 -21
- package/dist/eventbus/index.d.ts +39 -21
- 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/index.d.mts +39 -21
- package/dist/index.d.ts +39 -21
- 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/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -12,6 +12,17 @@ type ExpandWildcard<T extends Record<string, any>> = Expand$1<T & {
|
|
|
12
12
|
[K in WildcardKeys<T> as ReplaceWildcard<K>]: T[K];
|
|
13
13
|
}>;
|
|
14
14
|
|
|
15
|
+
type UnionToTuple<T> = UnionToTupleRec<T, []>;
|
|
16
|
+
type UnionToTupleRec<T, R extends any[]> = [T] extends [never] ? R : UnionToTupleRec<Exclude<T, LastOfUnion<T>>, [LastOfUnion<T>, ...R]>;
|
|
17
|
+
type LastOfUnion<T> = UnionToIntersection<T extends any ? (x: T) => 0 : never> extends (x: infer L) => 0 ? L : never;
|
|
18
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
19
|
+
type Keys<T extends Record<string, any>> = UnionToTuple<keyof T>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 保留对象中第一项
|
|
23
|
+
*/
|
|
24
|
+
type FirstObjectItem<T extends Record<string, any>> = Pick<T, Keys<T> extends any[] ? Keys<T>[0] : never>;
|
|
25
|
+
|
|
15
26
|
type MergeUnion<T> = (T extends any ? (x: T) => void : never) extends (x: infer U) => void ? {
|
|
16
27
|
[K in keyof U]: U[K];
|
|
17
28
|
} : never;
|
|
@@ -22,14 +33,25 @@ type MatchPattern<T extends string, Pattern extends string> = MatchPatternArray<
|
|
|
22
33
|
[K in Pattern]: any;
|
|
23
34
|
} : never;
|
|
24
35
|
type Fallback$1<T, F> = [T] extends [never] ? F : T extends undefined ? F : T;
|
|
25
|
-
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* 返回所有匹配事件的类型
|
|
39
|
+
*
|
|
40
|
+
* 支持通配符
|
|
41
|
+
*
|
|
42
|
+
* @param T 事件名称
|
|
43
|
+
* @param Events 事件类型
|
|
44
|
+
* @returns
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
type WildcardEvents<Events extends Record<string, any>, T extends string> = MergeUnion<Fallback$1<{
|
|
26
48
|
[K in keyof Events]: MatchPattern<T, K & string> extends never ? never : {
|
|
27
49
|
[P in K]: Events[K];
|
|
28
50
|
};
|
|
29
51
|
}[keyof Events] extends infer Result ? Result extends Record<string, any> ? Result : Record<string, any> : Record<string, any>, {
|
|
30
52
|
[K in T]: any;
|
|
31
53
|
}>>;
|
|
32
|
-
type
|
|
54
|
+
type ClosestWildcardEvents<Events extends Record<string, any>, T extends string> = FirstObjectItem<WildcardEvents<Events, T>>;
|
|
33
55
|
|
|
34
56
|
type Split<S extends string, Delimiter extends string> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split<Tail, Delimiter>] : [S];
|
|
35
57
|
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;
|
|
@@ -286,9 +308,6 @@ type Overloads<T> = Unique<T extends {
|
|
|
286
308
|
(...args: infer A1): infer R1;
|
|
287
309
|
} ? [(...args: A1) => R1] : [T]>;
|
|
288
310
|
type Dict<V = any> = Record<Exclude<string, number | symbol>, V>;
|
|
289
|
-
type Union<T> = T extends infer O ? {
|
|
290
|
-
[K in keyof O]: O[K];
|
|
291
|
-
} : never;
|
|
292
311
|
type RecordValues<R extends Record<string, any>> = R[keyof R];
|
|
293
312
|
type RecordPrefix<P extends string, R extends Record<string, any>> = {
|
|
294
313
|
[K in keyof R as K extends `${P}/${infer S}` ? S : never]: R[K];
|
|
@@ -369,7 +388,6 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
369
388
|
meta: FinalMeta;
|
|
370
389
|
context: Fallback<Context, typeof this>;
|
|
371
390
|
message: TypedFastEventMessageOptional<Events, FinalMeta>;
|
|
372
|
-
listeners: FastEventListeners<Events, FinalMeta>;
|
|
373
391
|
anyListener: TypedFastEventAnyListener<Events, FinalMeta, Fallback<Context, typeof this>>;
|
|
374
392
|
};
|
|
375
393
|
prefix: string;
|
|
@@ -401,14 +419,14 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
401
419
|
on<T extends Exclude<string, Types>>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
402
420
|
on(type: '**', options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
403
421
|
on<T extends keyof OmitTransformedEvents<Events>>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
404
|
-
on<T extends keyof PickTransformedEvents<Events>>(type: T, listener: (message: PickPayload<RecordValues<
|
|
405
|
-
on<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<
|
|
422
|
+
on<T extends keyof PickTransformedEvents<Events>>(type: T, listener: (message: PickPayload<RecordValues<ClosestWildcardEvents<Events, Exclude<T, number | symbol>>>>, args: FastEventListenerArgs<Meta>) => any | Promise<any>, options?: FastEventListenOptions<Events, Meta>): FastEventSubscriber;
|
|
423
|
+
on<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<ClosestWildcardEvents<Events, T>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
406
424
|
on(type: '**', listener: TypedFastEventAnyListener<Events, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
407
425
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
408
426
|
once<T extends Exclude<string, Types>>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
409
427
|
once<T extends keyof OmitTransformedEvents<Events>>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
410
|
-
once<T extends keyof PickTransformedEvents<Events>>(type: T, listener: (message: PickPayload<RecordValues<
|
|
411
|
-
once<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<
|
|
428
|
+
once<T extends keyof PickTransformedEvents<Events>>(type: T, listener: (message: PickPayload<RecordValues<WildcardEvents<Events, Exclude<T, number | symbol>>>>, args: FastEventListenerArgs<Meta>) => any | Promise<any>, options?: FastEventListenOptions<Events, Meta>): FastEventSubscriber;
|
|
429
|
+
once<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<WildcardEvents<Events, T>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
412
430
|
onAny(options?: Pick<FastEventListenOptions, 'prepend'>): FastEventSubscriber;
|
|
413
431
|
onAny<P = any>(listener: TypedFastEventAnyListener<{
|
|
414
432
|
[K: string]: P;
|
|
@@ -423,8 +441,8 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
423
441
|
emit(type: Types, directive: symbol): void;
|
|
424
442
|
emit(type: string, directive: symbol): void;
|
|
425
443
|
emit<R = any, T extends Types = Types>(type: T, payload?: PickPayload<Events[T]>, retain?: boolean): R[];
|
|
426
|
-
emit<R = any, T extends string = string>(type: T, payload?: PickPayload<T extends Types ? Events[T] : RecordValues<
|
|
427
|
-
emit<R = any, T extends string = string>(type: T, payload?: PickPayload<T extends Types ? Events[T] : RecordValues<
|
|
444
|
+
emit<R = any, T extends string = string>(type: T, payload?: PickPayload<T extends Types ? Events[T] : RecordValues<WildcardEvents<Events, T>>>, retain?: boolean): R[];
|
|
445
|
+
emit<R = any, T extends string = string>(type: T, payload?: PickPayload<T extends Types ? Events[T] : RecordValues<WildcardEvents<Events, T>>>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
428
446
|
emit<R = any>(message: FastEventEmitMessage<AtPayloads<Events>, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
429
447
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
430
448
|
[K in T]: PickPayload<K extends Types ? Events[K] : any>;
|
|
@@ -479,7 +497,7 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
479
497
|
* ```
|
|
480
498
|
*/
|
|
481
499
|
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>;
|
|
482
|
-
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<
|
|
500
|
+
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<Record<string, any>, any, any> = FastEventScope<Record<string, any>, any, any>>(prefix: P, scopeObj: ScopeInstance, options?: DeepPartial<FastEventScopeOptions<Partial<FinalMeta> & M, C>>): ScopeInstance & FastEventScope<ScopeEvents<Events, P> & E, FinalMeta & M, C>;
|
|
483
501
|
/**
|
|
484
502
|
* 当on/once/onAny未指定监听器时,此为默认监听器
|
|
485
503
|
* @param message
|
|
@@ -601,8 +619,8 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
601
619
|
on<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
602
620
|
on(type: '**', options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
603
621
|
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;
|
|
604
|
-
on<T extends keyof PickTransformedEvents<AllEvents>>(type: T, listener: (message: PickPayload<RecordValues<
|
|
605
|
-
on<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<
|
|
622
|
+
on<T extends keyof PickTransformedEvents<AllEvents>>(type: T, listener: (message: PickPayload<RecordValues<ClosestWildcardEvents<AllEvents, Exclude<T, number | symbol>>>>, args: FastEventListenerArgs<Meta>) => any | Promise<any>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
623
|
+
on<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<ClosestWildcardEvents<AllEvents, T>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
606
624
|
on(type: '**', listener: TypedFastEventAnyListener<Record<string, any>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
607
625
|
/**
|
|
608
626
|
* 注册一次性事件监听器
|
|
@@ -628,8 +646,8 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
628
646
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
629
647
|
once<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
630
648
|
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;
|
|
631
|
-
once<T extends keyof PickTransformedEvents<AllEvents>>(type: T, listener: (message: PickPayload<RecordValues<
|
|
632
|
-
once<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<
|
|
649
|
+
once<T extends keyof PickTransformedEvents<AllEvents>>(type: T, listener: (message: PickPayload<RecordValues<ClosestWildcardEvents<AllEvents, Exclude<T, number | symbol>>>>, args: FastEventListenerArgs<Meta>) => any | Promise<any>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
650
|
+
once<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<ClosestWildcardEvents<AllEvents, T>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
633
651
|
/**
|
|
634
652
|
* 注册一个监听器,用于监听所有事件
|
|
635
653
|
* @param listener 事件监听器函数,可以接收任意类型的事件数据
|
|
@@ -819,13 +837,13 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
819
837
|
emit<T extends Types = Types>(type: T, directive: symbol): any[];
|
|
820
838
|
emit(type: string, directive: symbol): any[];
|
|
821
839
|
emit<R = any, T extends Types = Types>(type: T, payload?: PickPayload<AllEvents[T]>, retain?: boolean): R[];
|
|
822
|
-
emit<R = any, T extends string = string>(type: T, payload: PickPayload<T extends Types ? AllEvents[T] : RecordValues<
|
|
840
|
+
emit<R = any, T extends string = string>(type: T, payload: PickPayload<T extends Types ? AllEvents[T] : RecordValues<WildcardEvents<AllEvents, T>>>, retain?: boolean): R[];
|
|
823
841
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
824
842
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
825
843
|
}, Meta>, retain?: boolean): R[];
|
|
826
844
|
emit<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, retain?: boolean): R[];
|
|
827
845
|
emit<R = any, T extends Types = Types>(type: T, payload?: PickPayload<AllEvents[T]>, options?: FastEventListenerArgs<Meta>): R[];
|
|
828
|
-
emit<R = any, T extends string = string>(type: T, payload: PickPayload<T extends Types ? AllEvents[T] : RecordValues<
|
|
846
|
+
emit<R = any, T extends string = string>(type: T, payload: PickPayload<T extends Types ? AllEvents[T] : RecordValues<WildcardEvents<AllEvents, T>>>, options?: FastEventListenerArgs<Meta>): R[];
|
|
829
847
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
830
848
|
[K in T]: PickPayload<K extends Types ? AllEvents[K] : any>;
|
|
831
849
|
}, Meta>, options?: FastEventListenerArgs<Meta>): R[];
|
|
@@ -960,7 +978,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
960
978
|
*/
|
|
961
979
|
scope<P extends string>(prefix: P, options?: DeepPartial<FastEventScopeOptions<Meta, Context>>): FastEventScope<ScopeEvents<AllEvents, P>, Meta, Context>;
|
|
962
980
|
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>;
|
|
963
|
-
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<
|
|
981
|
+
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<any, any, any>>(prefix: P, scopeObj: ScopeObject, options?: DeepPartial<FastEventScopeOptions<Meta & M, C>>): ScopeObject & FastEventScope<ScopeEvents<AllEvents, P> & E, Meta & M, C>;
|
|
964
982
|
}
|
|
965
983
|
|
|
966
984
|
declare const __FastEvent__: unique symbol;
|
|
@@ -1060,4 +1078,4 @@ declare function isClass(target: unknown): target is new (...args: any[]) => any
|
|
|
1060
1078
|
|
|
1061
1079
|
declare function isFastEvent(target: any): target is FastEvent;
|
|
1062
1080
|
|
|
1063
|
-
export { AbortError, type AssertFastMessage, type AtPayloads, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type ExpandWildcard, type Fallback, FastEvent, 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
|
|
1081
|
+
export { AbortError, type AssertFastMessage, type AtPayloads, CancelError, type ChangeFieldType, type ClosestWildcardEvents, type DeepPartial, type Dict, type Expand, type ExpandWildcard, type Fallback, FastEvent, 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 Keys, type Merge, type MergeUnion, 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 Unique, type WildcardEvents, __FastEventScope__, __FastEvent__, __expandable__, expandable, isClass, isExpandable, isFastEvent, isFastEventMessage, isFastEventScope, isFunction, isPathMatched, isString, isSubsctiber };
|
package/dist/index.d.ts
CHANGED
|
@@ -12,6 +12,17 @@ type ExpandWildcard<T extends Record<string, any>> = Expand$1<T & {
|
|
|
12
12
|
[K in WildcardKeys<T> as ReplaceWildcard<K>]: T[K];
|
|
13
13
|
}>;
|
|
14
14
|
|
|
15
|
+
type UnionToTuple<T> = UnionToTupleRec<T, []>;
|
|
16
|
+
type UnionToTupleRec<T, R extends any[]> = [T] extends [never] ? R : UnionToTupleRec<Exclude<T, LastOfUnion<T>>, [LastOfUnion<T>, ...R]>;
|
|
17
|
+
type LastOfUnion<T> = UnionToIntersection<T extends any ? (x: T) => 0 : never> extends (x: infer L) => 0 ? L : never;
|
|
18
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
19
|
+
type Keys<T extends Record<string, any>> = UnionToTuple<keyof T>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 保留对象中第一项
|
|
23
|
+
*/
|
|
24
|
+
type FirstObjectItem<T extends Record<string, any>> = Pick<T, Keys<T> extends any[] ? Keys<T>[0] : never>;
|
|
25
|
+
|
|
15
26
|
type MergeUnion<T> = (T extends any ? (x: T) => void : never) extends (x: infer U) => void ? {
|
|
16
27
|
[K in keyof U]: U[K];
|
|
17
28
|
} : never;
|
|
@@ -22,14 +33,25 @@ type MatchPattern<T extends string, Pattern extends string> = MatchPatternArray<
|
|
|
22
33
|
[K in Pattern]: any;
|
|
23
34
|
} : never;
|
|
24
35
|
type Fallback$1<T, F> = [T] extends [never] ? F : T extends undefined ? F : T;
|
|
25
|
-
|
|
36
|
+
/**
|
|
37
|
+
*
|
|
38
|
+
* 返回所有匹配事件的类型
|
|
39
|
+
*
|
|
40
|
+
* 支持通配符
|
|
41
|
+
*
|
|
42
|
+
* @param T 事件名称
|
|
43
|
+
* @param Events 事件类型
|
|
44
|
+
* @returns
|
|
45
|
+
*
|
|
46
|
+
*/
|
|
47
|
+
type WildcardEvents<Events extends Record<string, any>, T extends string> = MergeUnion<Fallback$1<{
|
|
26
48
|
[K in keyof Events]: MatchPattern<T, K & string> extends never ? never : {
|
|
27
49
|
[P in K]: Events[K];
|
|
28
50
|
};
|
|
29
51
|
}[keyof Events] extends infer Result ? Result extends Record<string, any> ? Result : Record<string, any> : Record<string, any>, {
|
|
30
52
|
[K in T]: any;
|
|
31
53
|
}>>;
|
|
32
|
-
type
|
|
54
|
+
type ClosestWildcardEvents<Events extends Record<string, any>, T extends string> = FirstObjectItem<WildcardEvents<Events, T>>;
|
|
33
55
|
|
|
34
56
|
type Split<S extends string, Delimiter extends string> = S extends `${infer Head}${Delimiter}${infer Tail}` ? [Head, ...Split<Tail, Delimiter>] : [S];
|
|
35
57
|
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;
|
|
@@ -286,9 +308,6 @@ type Overloads<T> = Unique<T extends {
|
|
|
286
308
|
(...args: infer A1): infer R1;
|
|
287
309
|
} ? [(...args: A1) => R1] : [T]>;
|
|
288
310
|
type Dict<V = any> = Record<Exclude<string, number | symbol>, V>;
|
|
289
|
-
type Union<T> = T extends infer O ? {
|
|
290
|
-
[K in keyof O]: O[K];
|
|
291
|
-
} : never;
|
|
292
311
|
type RecordValues<R extends Record<string, any>> = R[keyof R];
|
|
293
312
|
type RecordPrefix<P extends string, R extends Record<string, any>> = {
|
|
294
313
|
[K in keyof R as K extends `${P}/${infer S}` ? S : never]: R[K];
|
|
@@ -369,7 +388,6 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
369
388
|
meta: FinalMeta;
|
|
370
389
|
context: Fallback<Context, typeof this>;
|
|
371
390
|
message: TypedFastEventMessageOptional<Events, FinalMeta>;
|
|
372
|
-
listeners: FastEventListeners<Events, FinalMeta>;
|
|
373
391
|
anyListener: TypedFastEventAnyListener<Events, FinalMeta, Fallback<Context, typeof this>>;
|
|
374
392
|
};
|
|
375
393
|
prefix: string;
|
|
@@ -401,14 +419,14 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
401
419
|
on<T extends Exclude<string, Types>>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
402
420
|
on(type: '**', options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
403
421
|
on<T extends keyof OmitTransformedEvents<Events>>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
404
|
-
on<T extends keyof PickTransformedEvents<Events>>(type: T, listener: (message: PickPayload<RecordValues<
|
|
405
|
-
on<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<
|
|
422
|
+
on<T extends keyof PickTransformedEvents<Events>>(type: T, listener: (message: PickPayload<RecordValues<ClosestWildcardEvents<Events, Exclude<T, number | symbol>>>>, args: FastEventListenerArgs<Meta>) => any | Promise<any>, options?: FastEventListenOptions<Events, Meta>): FastEventSubscriber;
|
|
423
|
+
on<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<ClosestWildcardEvents<Events, T>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
406
424
|
on(type: '**', listener: TypedFastEventAnyListener<Events, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
407
425
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
408
426
|
once<T extends Exclude<string, Types>>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
|
|
409
427
|
once<T extends keyof OmitTransformedEvents<Events>>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
410
|
-
once<T extends keyof PickTransformedEvents<Events>>(type: T, listener: (message: PickPayload<RecordValues<
|
|
411
|
-
once<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<
|
|
428
|
+
once<T extends keyof PickTransformedEvents<Events>>(type: T, listener: (message: PickPayload<RecordValues<WildcardEvents<Events, Exclude<T, number | symbol>>>>, args: FastEventListenerArgs<Meta>) => any | Promise<any>, options?: FastEventListenOptions<Events, Meta>): FastEventSubscriber;
|
|
429
|
+
once<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<WildcardEvents<Events, T>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
|
|
412
430
|
onAny(options?: Pick<FastEventListenOptions, 'prepend'>): FastEventSubscriber;
|
|
413
431
|
onAny<P = any>(listener: TypedFastEventAnyListener<{
|
|
414
432
|
[K: string]: P;
|
|
@@ -423,8 +441,8 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
423
441
|
emit(type: Types, directive: symbol): void;
|
|
424
442
|
emit(type: string, directive: symbol): void;
|
|
425
443
|
emit<R = any, T extends Types = Types>(type: T, payload?: PickPayload<Events[T]>, retain?: boolean): R[];
|
|
426
|
-
emit<R = any, T extends string = string>(type: T, payload?: PickPayload<T extends Types ? Events[T] : RecordValues<
|
|
427
|
-
emit<R = any, T extends string = string>(type: T, payload?: PickPayload<T extends Types ? Events[T] : RecordValues<
|
|
444
|
+
emit<R = any, T extends string = string>(type: T, payload?: PickPayload<T extends Types ? Events[T] : RecordValues<WildcardEvents<Events, T>>>, retain?: boolean): R[];
|
|
445
|
+
emit<R = any, T extends string = string>(type: T, payload?: PickPayload<T extends Types ? Events[T] : RecordValues<WildcardEvents<Events, T>>>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
428
446
|
emit<R = any>(message: FastEventEmitMessage<AtPayloads<Events>, FinalMeta>, options?: FastEventListenerArgs<FinalMeta>): R[];
|
|
429
447
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
430
448
|
[K in T]: PickPayload<K extends Types ? Events[K] : any>;
|
|
@@ -479,7 +497,7 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
|
|
|
479
497
|
* ```
|
|
480
498
|
*/
|
|
481
499
|
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>;
|
|
482
|
-
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<
|
|
500
|
+
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<Record<string, any>, any, any> = FastEventScope<Record<string, any>, any, any>>(prefix: P, scopeObj: ScopeInstance, options?: DeepPartial<FastEventScopeOptions<Partial<FinalMeta> & M, C>>): ScopeInstance & FastEventScope<ScopeEvents<Events, P> & E, FinalMeta & M, C>;
|
|
483
501
|
/**
|
|
484
502
|
* 当on/once/onAny未指定监听器时,此为默认监听器
|
|
485
503
|
* @param message
|
|
@@ -601,8 +619,8 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
601
619
|
on<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
602
620
|
on(type: '**', options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
603
621
|
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;
|
|
604
|
-
on<T extends keyof PickTransformedEvents<AllEvents>>(type: T, listener: (message: PickPayload<RecordValues<
|
|
605
|
-
on<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<
|
|
622
|
+
on<T extends keyof PickTransformedEvents<AllEvents>>(type: T, listener: (message: PickPayload<RecordValues<ClosestWildcardEvents<AllEvents, Exclude<T, number | symbol>>>>, args: FastEventListenerArgs<Meta>) => any | Promise<any>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
623
|
+
on<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<ClosestWildcardEvents<AllEvents, T>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
606
624
|
on(type: '**', listener: TypedFastEventAnyListener<Record<string, any>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
607
625
|
/**
|
|
608
626
|
* 注册一次性事件监听器
|
|
@@ -628,8 +646,8 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
628
646
|
once<T extends Types = Types>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
629
647
|
once<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
630
648
|
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;
|
|
631
|
-
once<T extends keyof PickTransformedEvents<AllEvents>>(type: T, listener: (message: PickPayload<RecordValues<
|
|
632
|
-
once<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<
|
|
649
|
+
once<T extends keyof PickTransformedEvents<AllEvents>>(type: T, listener: (message: PickPayload<RecordValues<ClosestWildcardEvents<AllEvents, Exclude<T, number | symbol>>>>, args: FastEventListenerArgs<Meta>) => any | Promise<any>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
650
|
+
once<T extends Exclude<string, Types>>(type: T, listener: TypedFastEventAnyListener<ClosestWildcardEvents<AllEvents, T>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
|
|
633
651
|
/**
|
|
634
652
|
* 注册一个监听器,用于监听所有事件
|
|
635
653
|
* @param listener 事件监听器函数,可以接收任意类型的事件数据
|
|
@@ -819,13 +837,13 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
819
837
|
emit<T extends Types = Types>(type: T, directive: symbol): any[];
|
|
820
838
|
emit(type: string, directive: symbol): any[];
|
|
821
839
|
emit<R = any, T extends Types = Types>(type: T, payload?: PickPayload<AllEvents[T]>, retain?: boolean): R[];
|
|
822
|
-
emit<R = any, T extends string = string>(type: T, payload: PickPayload<T extends Types ? AllEvents[T] : RecordValues<
|
|
840
|
+
emit<R = any, T extends string = string>(type: T, payload: PickPayload<T extends Types ? AllEvents[T] : RecordValues<WildcardEvents<AllEvents, T>>>, retain?: boolean): R[];
|
|
823
841
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
824
842
|
[K in T]: K extends Types ? AllEvents[K] : any;
|
|
825
843
|
}, Meta>, retain?: boolean): R[];
|
|
826
844
|
emit<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, retain?: boolean): R[];
|
|
827
845
|
emit<R = any, T extends Types = Types>(type: T, payload?: PickPayload<AllEvents[T]>, options?: FastEventListenerArgs<Meta>): R[];
|
|
828
|
-
emit<R = any, T extends string = string>(type: T, payload: PickPayload<T extends Types ? AllEvents[T] : RecordValues<
|
|
846
|
+
emit<R = any, T extends string = string>(type: T, payload: PickPayload<T extends Types ? AllEvents[T] : RecordValues<WildcardEvents<AllEvents, T>>>, options?: FastEventListenerArgs<Meta>): R[];
|
|
829
847
|
emit<R = any, T extends string = string>(message: FastEventEmitMessage<{
|
|
830
848
|
[K in T]: PickPayload<K extends Types ? AllEvents[K] : any>;
|
|
831
849
|
}, Meta>, options?: FastEventListenerArgs<Meta>): R[];
|
|
@@ -960,7 +978,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
960
978
|
*/
|
|
961
979
|
scope<P extends string>(prefix: P, options?: DeepPartial<FastEventScopeOptions<Meta, Context>>): FastEventScope<ScopeEvents<AllEvents, P>, Meta, Context>;
|
|
962
980
|
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>;
|
|
963
|
-
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<
|
|
981
|
+
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<any, any, any>>(prefix: P, scopeObj: ScopeObject, options?: DeepPartial<FastEventScopeOptions<Meta & M, C>>): ScopeObject & FastEventScope<ScopeEvents<AllEvents, P> & E, Meta & M, C>;
|
|
964
982
|
}
|
|
965
983
|
|
|
966
984
|
declare const __FastEvent__: unique symbol;
|
|
@@ -1060,4 +1078,4 @@ declare function isClass(target: unknown): target is new (...args: any[]) => any
|
|
|
1060
1078
|
|
|
1061
1079
|
declare function isFastEvent(target: any): target is FastEvent;
|
|
1062
1080
|
|
|
1063
|
-
export { AbortError, type AssertFastMessage, type AtPayloads, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type ExpandWildcard, type Fallback, FastEvent, 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
|
|
1081
|
+
export { AbortError, type AssertFastMessage, type AtPayloads, CancelError, type ChangeFieldType, type ClosestWildcardEvents, type DeepPartial, type Dict, type Expand, type ExpandWildcard, type Fallback, FastEvent, 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 Keys, type Merge, type MergeUnion, 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 Unique, type WildcardEvents, __FastEventScope__, __FastEvent__, __expandable__, expandable, isClass, isExpandable, isFastEvent, isFastEventMessage, isFastEventScope, isFunction, isPathMatched, isString, isSubsctiber };
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var R=Object.defineProperty;var z=(i,t,e)=>t in i?R(i,t,{enumerable:true,configurable:true,writable:true,value:e}):i[t]=e;var f=(i,t)=>R(i,"name",{value:t,configurable:true});var h=(i,t,e)=>z(i,typeof t!="symbol"?t+"":t,e);var H=Symbol.for("__FastEvent__"),J=Symbol.for("__FastEventScope__"),S=class S extends Error{constructor(t){super(t);}};f(S,"FastEventError");var m=S,A=class A extends m{};f(A,"TimeoutError");var C=A,M=class M extends m{};f(M,"UnboundError");var x=M,w=class w extends m{};f(w,"AbortError");var d=w,F=class F extends m{};f(F,"CancelError");var y=F,j=class j extends m{};f(j,"QueueOverflowError");var W=j,b={clearRetain:Symbol.for("ClearRetain")};var _=function(i){return i[i.Transformed=1]="Transformed",i}({});function L(i,t,e,s){let n,r={},o={};return typeof i[0]=="object"?(Object.assign(o,i[0]),r=typeof i[1]=="boolean"?{retain:i[1]}:i[1]||{},n=i[0].meta):(o.type=i[0],o.payload=i[1],r=typeof i[2]=="boolean"?{retain:i[2]}:i[2]||{}),n=Object.assign({},t,e,r.meta,n),Object.keys(n).length===0&&(n=void 0),o.meta=n,r.executor===void 0&&(r.executor=s),[o,r]}f(L,"parseEmitArgs");function D(i){return i?typeof i=="object"&&"__FastEventScope__"in i:false}f(D,"isFastEventScope");function E(i,t,e){let s=i[0],n=D(i[1])?i[1]:void 0,r=(n?i[2]:i[1])||{};return r.meta=Object.assign({},t,r?.meta),r.context=r.context!==void 0?r.context:e,[s,n,r]}f(E,"parseScopeArgs");function g(i,t){return Object.defineProperty(i,"name",{value:t||"anonymous",configurable:true}),i}f(g,"renameFn");function u(i){return i&&typeof i=="function"}f(u,"isFunction");var T=class T{constructor(t){h(this,"__FastEventScope__",true);h(this,"_options",{});h(this,"types",{events:void 0,meta:void 0,context:void 0,message:void 0,listeners:void 0,anyListener:void 0});h(this,"prefix","");h(this,"emitter");this._options=Object.assign({},this._initOptions(t));}get context(){return this.options.context||this}get options(){return this._options}bind(t,e,s){this.emitter=t,this._options=Object.assign(this._options,{scope:e},s),e.length>0&&!e.endsWith(t.options.delimiter)&&(this.prefix=e+t.options.delimiter);}_initOptions(t){return t}_getScopeListener(t){let e=this.prefix;if(e.length===0)return t;t||(t=(this._options.onMessage||this.onMessage).bind(this));let s=this;return g(function(r,o){let p=o.rawEventType||r.type;if(p.startsWith(e)){let c=((o.flags||0)&_.Transformed)>0?r:Object.assign({},r,{type:p.substring(e.length)});return t.call(s.context,c,o)}},t.name)}_getScopeType(t){return t===void 0?void 0:this.prefix+t}_fixScopeType(t){return t.startsWith(this.prefix)?t.substring(this.prefix.length):t}on(){if(!this.emitter)throw new x;let t=[...arguments];return t[0]=this._getScopeType(t[0]),t[1]=this._getScopeListener(t[1]),this.emitter.on(...t)}once(){return this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",...arguments)}off(){let t=arguments;typeof t[0]=="string"&&(t[0]=this._getScopeType(t[0])),this.emitter.off(...t);}offAll(){this.emitter.offAll(this.prefix.substring(0,this.prefix.length-1));}clear(){this.emitter.clear(this.prefix.substring(0,this.prefix.length-1));}emit(){if(arguments.length===2&&typeof arguments[0]=="string"&&arguments[1]===b.clearRetain)return this.emitter.emit(this._getScopeType(arguments[0]));let[t,e]=L(arguments,this.emitter.options.meta,this.options.meta,this.options.executor);return this._transformMessage(t,e),t.type=this._getScopeType(t.type),this.emitter.emit(t,e)}_transformMessage(t,e){u(this._options.transform)&&(e.rawEventType=this._getScopeType(t.type),e.flags=(e.flags||0)|_.Transformed,t.payload=this._options.transform.call(this,t));}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(e=>e.status==="fulfilled"?e.value:e.reason)}async waitFor(){let t=arguments[0],e=arguments[1],s=await this.emitter.waitFor(this._getScopeType(t),e);return Object.assign({},s,{type:this._fixScopeType(s.type)})}scope(){let[t,e,s]=E(arguments,this.options.meta,this.options.context),n;return e?n=e:n=new T,n.bind(this.emitter,this.prefix+t,s),n}onMessage(t,e){}};f(T,"FastEventScope");var v=T;function O(i,t){if(i.length!==t.length&&i.length>0&&t[t.length-1]!=="**")return false;let e=[...t];t.length>0&&t[t.length-1]==="**"&&e.splice(t.length-1,1,...Array.from({length:i.length-t.length+1}).fill("*"));for(let s=0;s<i.length;s++)if(e[s]!=="*"&&e[s]!==i[s])return false;return true}f(O,"isPathMatched");function N(i,t){let e=[];for(;;){let s=i.findIndex(n=>t(n));if(s===-1){e.push(s);break}i.splice(s,1);}return e}f(N,"removeItem");var V=Symbol.for("__expandable__");function vt(i){return i[V]=true,i}f(vt,"expandable");function I(i){return i&&i[V]}f(I,"isExpandable");function B(i){for(let t=0;t<i.length;t++){let e=i[t];Array.isArray(e)&&I(e)&&(i.splice(t,1,...e),t+=e.length-1);}return i}f(B,"expandEmitResults");function X(i){return i&&typeof i=="object"&&"off"in i&&"listener"in i}f(X,"isSubsctiber");function $(i,t){return i.catch(e=>(t&&t(e),Promise.resolve(e)))}f($,"tryReturnError");var P=class P{constructor(t){h(this,"__FastEvent__",true);h(this,"listeners",{__listeners:[]});h(this,"_options");h(this,"_delimiter","/");h(this,"_context");h(this,"retainedMessages",new Map);h(this,"listenerCount",0);h(this,"types",{events:void 0,meta:void 0,context:void 0,message:void 0,listeners:void 0,anyListener:void 0});this._options=Object.assign({debug:false,id:Math.random().toString(36).substring(2),delimiter:"/",context:null,ignoreErrors:true,meta:void 0,expandEmitResults:true},this._initOptions(t)),this._delimiter=this._options.delimiter,this._context=this._options.context,this._enableDevTools();}get options(){return this._options}get context(){return this.options.context||this}get meta(){return this.options.meta}get id(){return this._options.id}_initOptions(t){return t}_addListener(t,e,s){let{count:n,prepend:r}=s,o=0;return [this._forEachNodes(t,a=>{let c=[e,n,0,s.tag,s.flags];r?(a.__listeners.splice(0,0,c),o=0):(a.__listeners.push(c),o=a.__listeners.length-1),this.listenerCount++;}),o]}_enableDevTools(){this.options.debug&&globalThis.__FLEXEVENT_DEVTOOLS__&&globalThis.__FLEXEVENT_DEVTOOLS__.add(this);}_forEachNodes(t,e){if(t.length===0)return;let s=this.listeners;for(let n=0;n<t.length;n++){let r=t[n];if(r in s||(s[r]={__listeners:[]}),n===t.length-1){let o=s[r];return e(o,s),o}else s=s[r];}}_removeListener(t,e,s){s&&N(t.__listeners,n=>{n=Array.isArray(n)?n[0]:n;let r=n===s;return r&&(this.listenerCount--,u(this._options.onRemoveListener)&&this._options.onRemoveListener(e.join(this._delimiter),s)),r});}_pipeListener(t,e){return e.forEach(s=>{t=g(s(t),t.name);}),t}on(){let t=arguments[0],e=u(arguments[1])?arguments[1]:(this._options.onMessage||this.onMessage).bind(this),s=Object.assign({count:0,flags:0,prepend:false},u(arguments[1])?arguments[2]:arguments[1]);if(t.length===0)throw new Error("event type cannot be empty");if(u(this._options.onAddListener)){let a=this._options.onAddListener(t,e,s);if(a===false)throw new y;if(X(a))return a}let n=t.split(this._delimiter);if(s.pipes&&s.pipes.length>0&&(e=this._pipeListener(e,s.pipes)),u(s.filter)||u(s.off)){let a=e;e=g(function(c,l){if(u(s.off)&&s.off.call(this,c,l)){p();return}if(u(s.filter)){if(s.filter.call(this,c,l))return a.call(this,c,l)}else return a.call(this,c,l)},e.name);}let[r,o]=this._addListener(n,e,s),p=f(()=>r&&this._removeListener(r,n,e),"off");return this._emitRetainMessage(t,r,o),{off:p,listener:e}}once(){return u(arguments[1])?this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1})):this.on(arguments[0],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",arguments[0],arguments[1])}onMessage(t,e){}off(){let t=arguments,e=u(t[0])?void 0:t[0],s=u(t[0])?t[0]:t[1],n=e?e.split(this._delimiter):[],r=e?e.includes("*"):false;if(e&&!r)this._traverseToPath(this.listeners,n,o=>{s?this._removeListener(o,n,s):e&&(o.__listeners=[]);});else {let o=r?[]:n;this._traverseListeners(this.listeners,o,(p,a)=>{(s!==void 0||r&&O(p,n))&&(s?this._removeListener(a,n,s):a.__listeners=[]);});}}offAll(t){if(t){let e=t.split(this._delimiter),s=0;this._traverseListeners(this.listeners,e,(n,r)=>{s+=r.__listeners.length,r.__listeners=[];}),this.listenerCount-=s,this._removeRetainedEvents(t);}else {let e=0;this._traverseListeners(this.listeners,[],(s,n)=>{e+=n.__listeners.length;}),this.listenerCount-=e,this.retainedMessages.clear(),this.listeners={__listeners:[]};}u(this._options.onClearListeners)&&this._options.onClearListeners.call(this);}_removeRetainedEvents(t){t||this.retainedMessages.clear(),t?.endsWith(this._delimiter)&&(t+=this._delimiter),this.retainedMessages.delete(t);for(let e of this.retainedMessages.keys())e.startsWith(t)&&this.retainedMessages.delete(e);}clear(t){this.offAll(t),this._removeRetainedEvents(t);}_emitRetainMessage(t,e,s){let n=[];if(t.includes("*")){let r=t.split(this._delimiter);this.retainedMessages.forEach((o,p)=>{let a=p.split(this._delimiter);O(a,r)&&n.push(o);});}else this.retainedMessages.has(t)&&n.push(this.retainedMessages.get(t));e&&n.forEach(r=>{this._executeListeners([e],r,{},o=>o[0]===e.__listeners[s][0]);});}_traverseToPath(t,e,s,n=0,r){if(n>=e.length){s(t);return}let o=e[n];if(r===true){this._traverseToPath(t,e,s,n+1,true);return}"*"in t&&this._traverseToPath(t["*"],e,s,n+1),"**"in t&&this._traverseToPath(t["**"],e,s,n+1,true),o in t&&this._traverseToPath(t[o],e,s,n+1);}_traverseListeners(t,e,s){let n=t;e&&e.length>0&&this._traverseToPath(t,e,o=>{n=o;});let r=f((o,p,a)=>{p(a,o);for(let[c,l]of Object.entries(o))c.startsWith("__")||l&&r(l,p,[...a,c]);},"traverseNodes");r(n,s,[]);}_onListenerError(t,e,s,n){if(n instanceof Error&&(n._emitter=`${t.name||"anonymous"}:${e.type}`),u(this._options.onListenerError))try{this._options.onListenerError.call(this,n,t,e,s);}catch{}if(this._options.ignoreErrors)return n;throw n}_setListenerFlags(t,e){return !t||t===0?e:t|e}_executeListener(t,e,s,n=false){try{if(s&&s.abortSignal&&s.abortSignal.aborted)return this._onListenerError(t,e,s,new d(t.name));let r=((s?.flags||0)&_.Transformed)>0,o=t.call(this.context,r?e.payload:e,s);return n&&o&&o instanceof Promise&&(o=$(o,p=>this._onListenerError(t,e,s,p))),o}catch(r){return this._onListenerError(t,e,s,r)}}_getListenerExecutor(t){if(!t)return;let e=t.executor||this._options.executor;if(u(e))return e}_executeListeners(t,e,s,n){if(!t||t.length===0)return [];let r=t.reduce((p,a)=>p.concat(a.__listeners.filter(c=>u(n)?n(c,a):true).map((c,l)=>[c,l,a.__listeners])),[]);u(this._options.transform)&&(s||(s={}),s.rawEventType=e.type,e.payload=this._options.transform.call(this,e),s.flags=this._setListenerFlags(s.flags,_.Transformed)),this._decListenerExecCount(r);let o=this._getListenerExecutor(s);if(o){let p=o(r.map(a=>a[0]),e,s,this._executeListener.bind(this));return Array.isArray(p)?p:[p]}else return r.map(p=>this._executeListener(p[0][0],e,s,true))}_decListenerExecCount(t){for(let e=t.length-1;e>=0;e--){let s=t[e][0];s[2]++,s[1]>0&&s[1]<=s[2]&&t[e][2].splice(e,1);}}getListeners(t){let e=[],s=t.split(this._delimiter);return this._traverseToPath(this.listeners,s,n=>{e.push(n);}),e[0].__listeners}emit(){if(arguments.length===2&&typeof arguments[0]=="string"&&arguments[1]===b.clearRetain)return this.retainedMessages.delete(arguments[0]),[];let[t,e]=L(arguments,this.options.meta);u(e.parseArgs)&&e.parseArgs(t,e);let s=t.type.split(this._delimiter);e.retain&&this.retainedMessages.set(t.type,t);let n=[],r=[];if(this._traverseToPath(this.listeners,s,o=>{r.push(o);}),u(this._options.onBeforeExecuteListener)){let o=this._options.onBeforeExecuteListener.call(this,t,e);if(Array.isArray(o))return o;if(o===false)throw new d(t.type)}return u(this._options.transform)&&(t.payload=this._options.transform.call(this,t),e.rawEventType=t.type,e.flags=(e.flags||0)|_.Transformed),n.push(...this._executeListeners(r,t,e)),u(this._options.onAfterExecuteListener)&&this._options.onAfterExecuteListener.call(this,t,n,r),this._options.expandEmitResults&&B(n),n}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(e=>e.status==="fulfilled"?e.value:e.reason)}waitFor(){let t=arguments[0],e=arguments[1];return new Promise((s,n)=>{let r,o,p=f(a=>{clearTimeout(r),o&&o.off(),s(a);},"listener");e&&e>0&&(r=setTimeout(()=>{o&&o.off(),n(new Error("wait for event<"+t+"> is timeout"));},e)),o=this.on(t,p);})}scope(){let[t,e,s]=E(arguments,this.options.meta,this.options.context),n;return e?n=e:n=new v,n.bind(this,t,s),n}};f(P,"FastEvent");var q=P;function Jt(i){return i?typeof i=="object"&&"type"in i:false}f(Jt,"isFastEventMessage");function Zt(i){return i&&typeof i=="string"}f(Zt,"isString");function Qt(i){return typeof i=="function"&&(i.toString().startsWith("class ")||i.prototype?.constructor===i)}f(Qt,"isClass");function se(i){return i?typeof i=="object"&&"__FastEvent__"in i:false}f(se,"isFastEvent");exports.AbortError=d;exports.CancelError=y;exports.FastEvent=q;exports.FastEventDirectives=b;exports.FastEventError=m;exports.FastEventListenerFlags=_;exports.FastEventScope=v;exports.QueueOverflowError=W;exports.TimeoutError=C;exports.UnboundError=x;exports.__FastEventScope__=J;exports.__FastEvent__=H;exports.__expandable__=V;exports.expandable=vt;exports.isClass=Qt;exports.isExpandable=I;exports.isFastEvent=se;exports.isFastEventMessage=Jt;exports.isFastEventScope=D;exports.isFunction=u;exports.isPathMatched=O;exports.isString=Zt;exports.isSubsctiber=X;//# sourceMappingURL=index.js.map
|
|
1
|
+
'use strict';var R=Object.defineProperty;var z=(i,t,e)=>t in i?R(i,t,{enumerable:true,configurable:true,writable:true,value:e}):i[t]=e;var f=(i,t)=>R(i,"name",{value:t,configurable:true});var h=(i,t,e)=>z(i,typeof t!="symbol"?t+"":t,e);var H=Symbol.for("__FastEvent__"),J=Symbol.for("__FastEventScope__"),S=class S extends Error{constructor(t){super(t);}};f(S,"FastEventError");var m=S,A=class A extends m{};f(A,"TimeoutError");var C=A,M=class M extends m{};f(M,"UnboundError");var x=M,w=class w extends m{};f(w,"AbortError");var d=w,F=class F extends m{};f(F,"CancelError");var y=F,j=class j extends m{};f(j,"QueueOverflowError");var W=j,b={clearRetain:Symbol.for("ClearRetain")};var _=function(i){return i[i.Transformed=1]="Transformed",i}({});function L(i,t,e,s){let n,r={},o={};return typeof i[0]=="object"?(Object.assign(o,i[0]),r=typeof i[1]=="boolean"?{retain:i[1]}:i[1]||{},n=i[0].meta):(o.type=i[0],o.payload=i[1],r=typeof i[2]=="boolean"?{retain:i[2]}:i[2]||{}),n=Object.assign({},t,e,r.meta,n),Object.keys(n).length===0&&(n=void 0),o.meta=n,r.executor===void 0&&(r.executor=s),[o,r]}f(L,"parseEmitArgs");function D(i){return i?typeof i=="object"&&"__FastEventScope__"in i:false}f(D,"isFastEventScope");function E(i,t,e){let s=i[0],n=D(i[1])?i[1]:void 0,r=(n?i[2]:i[1])||{};return r.meta=Object.assign({},t,r?.meta),r.context=r.context!==void 0?r.context:e,[s,n,r]}f(E,"parseScopeArgs");function g(i,t){return Object.defineProperty(i,"name",{value:t||"anonymous",configurable:true}),i}f(g,"renameFn");function u(i){return i&&typeof i=="function"}f(u,"isFunction");var T=class T{constructor(t){h(this,"__FastEventScope__",true);h(this,"_options",{});h(this,"types",{events:void 0,meta:void 0,context:void 0,message:void 0,anyListener:void 0});h(this,"prefix","");h(this,"emitter");this._options=Object.assign({},this._initOptions(t));}get context(){return this.options.context||this}get options(){return this._options}bind(t,e,s){this.emitter=t,this._options=Object.assign(this._options,{scope:e},s),e.length>0&&!e.endsWith(t.options.delimiter)&&(this.prefix=e+t.options.delimiter);}_initOptions(t){return t}_getScopeListener(t){let e=this.prefix;if(e.length===0)return t;t||(t=(this._options.onMessage||this.onMessage).bind(this));let s=this;return g(function(r,o){let p=o.rawEventType||r.type;if(p.startsWith(e)){let c=((o.flags||0)&_.Transformed)>0?r:Object.assign({},r,{type:p.substring(e.length)});return t.call(s.context,c,o)}},t.name)}_getScopeType(t){return t===void 0?void 0:this.prefix+t}_fixScopeType(t){return t.startsWith(this.prefix)?t.substring(this.prefix.length):t}on(){if(!this.emitter)throw new x;let t=[...arguments];return t[0]=this._getScopeType(t[0]),t[1]=this._getScopeListener(t[1]),this.emitter.on(...t)}once(){return this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",...arguments)}off(){let t=arguments;typeof t[0]=="string"&&(t[0]=this._getScopeType(t[0])),this.emitter.off(...t);}offAll(){this.emitter.offAll(this.prefix.substring(0,this.prefix.length-1));}clear(){this.emitter.clear(this.prefix.substring(0,this.prefix.length-1));}emit(){if(arguments.length===2&&typeof arguments[0]=="string"&&arguments[1]===b.clearRetain)return this.emitter.emit(this._getScopeType(arguments[0]));let[t,e]=L(arguments,this.emitter.options.meta,this.options.meta,this.options.executor);return this._transformMessage(t,e),t.type=this._getScopeType(t.type),this.emitter.emit(t,e)}_transformMessage(t,e){u(this._options.transform)&&(e.rawEventType=this._getScopeType(t.type),e.flags=(e.flags||0)|_.Transformed,t.payload=this._options.transform.call(this,t));}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(e=>e.status==="fulfilled"?e.value:e.reason)}async waitFor(){let t=arguments[0],e=arguments[1],s=await this.emitter.waitFor(this._getScopeType(t),e);return Object.assign({},s,{type:this._fixScopeType(s.type)})}scope(){let[t,e,s]=E(arguments,this.options.meta,this.options.context),n;return e?n=e:n=new T,n.bind(this.emitter,this.prefix+t,s),n}onMessage(t,e){}};f(T,"FastEventScope");var v=T;function O(i,t){if(i.length!==t.length&&i.length>0&&t[t.length-1]!=="**")return false;let e=[...t];t.length>0&&t[t.length-1]==="**"&&e.splice(t.length-1,1,...Array.from({length:i.length-t.length+1}).fill("*"));for(let s=0;s<i.length;s++)if(e[s]!=="*"&&e[s]!==i[s])return false;return true}f(O,"isPathMatched");function N(i,t){let e=[];for(;;){let s=i.findIndex(n=>t(n));if(s===-1){e.push(s);break}i.splice(s,1);}return e}f(N,"removeItem");var V=Symbol.for("__expandable__");function Tt(i){return i[V]=true,i}f(Tt,"expandable");function I(i){return i&&i[V]}f(I,"isExpandable");function B(i){for(let t=0;t<i.length;t++){let e=i[t];Array.isArray(e)&&I(e)&&(i.splice(t,1,...e),t+=e.length-1);}return i}f(B,"expandEmitResults");function X(i){return i&&typeof i=="object"&&"off"in i&&"listener"in i}f(X,"isSubsctiber");function $(i,t){return i.catch(e=>(t&&t(e),Promise.resolve(e)))}f($,"tryReturnError");var P=class P{constructor(t){h(this,"__FastEvent__",true);h(this,"listeners",{__listeners:[]});h(this,"_options");h(this,"_delimiter","/");h(this,"_context");h(this,"retainedMessages",new Map);h(this,"listenerCount",0);h(this,"types",{events:void 0,meta:void 0,context:void 0,message:void 0,listeners:void 0,anyListener:void 0});this._options=Object.assign({debug:false,id:Math.random().toString(36).substring(2),delimiter:"/",context:null,ignoreErrors:true,meta:void 0,expandEmitResults:true},this._initOptions(t)),this._delimiter=this._options.delimiter,this._context=this._options.context,this._enableDevTools();}get options(){return this._options}get context(){return this.options.context||this}get meta(){return this.options.meta}get id(){return this._options.id}_initOptions(t){return t}_addListener(t,e,s){let{count:n,prepend:r}=s,o=0;return [this._forEachNodes(t,a=>{let c=[e,n,0,s.tag,s.flags];r?(a.__listeners.splice(0,0,c),o=0):(a.__listeners.push(c),o=a.__listeners.length-1),this.listenerCount++;}),o]}_enableDevTools(){this.options.debug&&globalThis.__FLEXEVENT_DEVTOOLS__&&globalThis.__FLEXEVENT_DEVTOOLS__.add(this);}_forEachNodes(t,e){if(t.length===0)return;let s=this.listeners;for(let n=0;n<t.length;n++){let r=t[n];if(r in s||(s[r]={__listeners:[]}),n===t.length-1){let o=s[r];return e(o,s),o}else s=s[r];}}_removeListener(t,e,s){s&&N(t.__listeners,n=>{n=Array.isArray(n)?n[0]:n;let r=n===s;return r&&(this.listenerCount--,u(this._options.onRemoveListener)&&this._options.onRemoveListener(e.join(this._delimiter),s)),r});}_pipeListener(t,e){return e.forEach(s=>{t=g(s(t),t.name);}),t}on(){let t=arguments[0],e=u(arguments[1])?arguments[1]:(this._options.onMessage||this.onMessage).bind(this),s=Object.assign({count:0,flags:0,prepend:false},u(arguments[1])?arguments[2]:arguments[1]);if(t.length===0)throw new Error("event type cannot be empty");if(u(this._options.onAddListener)){let a=this._options.onAddListener(t,e,s);if(a===false)throw new y;if(X(a))return a}let n=t.split(this._delimiter);if(s.pipes&&s.pipes.length>0&&(e=this._pipeListener(e,s.pipes)),u(s.filter)||u(s.off)){let a=e;e=g(function(c,l){if(u(s.off)&&s.off.call(this,c,l)){p();return}if(u(s.filter)){if(s.filter.call(this,c,l))return a.call(this,c,l)}else return a.call(this,c,l)},e.name);}let[r,o]=this._addListener(n,e,s),p=f(()=>r&&this._removeListener(r,n,e),"off");return this._emitRetainMessage(t,r,o),{off:p,listener:e}}once(){return u(arguments[1])?this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1})):this.on(arguments[0],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",arguments[0],arguments[1])}onMessage(t,e){}off(){let t=arguments,e=u(t[0])?void 0:t[0],s=u(t[0])?t[0]:t[1],n=e?e.split(this._delimiter):[],r=e?e.includes("*"):false;if(e&&!r)this._traverseToPath(this.listeners,n,o=>{s?this._removeListener(o,n,s):e&&(o.__listeners=[]);});else {let o=r?[]:n;this._traverseListeners(this.listeners,o,(p,a)=>{(s!==void 0||r&&O(p,n))&&(s?this._removeListener(a,n,s):a.__listeners=[]);});}}offAll(t){if(t){let e=t.split(this._delimiter),s=0;this._traverseListeners(this.listeners,e,(n,r)=>{s+=r.__listeners.length,r.__listeners=[];}),this.listenerCount-=s,this._removeRetainedEvents(t);}else {let e=0;this._traverseListeners(this.listeners,[],(s,n)=>{e+=n.__listeners.length;}),this.listenerCount-=e,this.retainedMessages.clear(),this.listeners={__listeners:[]};}u(this._options.onClearListeners)&&this._options.onClearListeners.call(this);}_removeRetainedEvents(t){t||this.retainedMessages.clear(),t?.endsWith(this._delimiter)&&(t+=this._delimiter),this.retainedMessages.delete(t);for(let e of this.retainedMessages.keys())e.startsWith(t)&&this.retainedMessages.delete(e);}clear(t){this.offAll(t),this._removeRetainedEvents(t);}_emitRetainMessage(t,e,s){let n=[];if(t.includes("*")){let r=t.split(this._delimiter);this.retainedMessages.forEach((o,p)=>{let a=p.split(this._delimiter);O(a,r)&&n.push(o);});}else this.retainedMessages.has(t)&&n.push(this.retainedMessages.get(t));e&&n.forEach(r=>{this._executeListeners([e],r,{},o=>o[0]===e.__listeners[s][0]);});}_traverseToPath(t,e,s,n=0,r){if(n>=e.length){s(t);return}let o=e[n];if(r===true){this._traverseToPath(t,e,s,n+1,true);return}"*"in t&&this._traverseToPath(t["*"],e,s,n+1),"**"in t&&this._traverseToPath(t["**"],e,s,n+1,true),o in t&&this._traverseToPath(t[o],e,s,n+1);}_traverseListeners(t,e,s){let n=t;e&&e.length>0&&this._traverseToPath(t,e,o=>{n=o;});let r=f((o,p,a)=>{p(a,o);for(let[c,l]of Object.entries(o))c.startsWith("__")||l&&r(l,p,[...a,c]);},"traverseNodes");r(n,s,[]);}_onListenerError(t,e,s,n){if(n instanceof Error&&(n._emitter=`${t.name||"anonymous"}:${e.type}`),u(this._options.onListenerError))try{this._options.onListenerError.call(this,n,t,e,s);}catch{}if(this._options.ignoreErrors)return n;throw n}_setListenerFlags(t,e){return !t||t===0?e:t|e}_executeListener(t,e,s,n=false){try{if(s&&s.abortSignal&&s.abortSignal.aborted)return this._onListenerError(t,e,s,new d(t.name));let r=((s?.flags||0)&_.Transformed)>0,o=t.call(this.context,r?e.payload:e,s);return n&&o&&o instanceof Promise&&(o=$(o,p=>this._onListenerError(t,e,s,p))),o}catch(r){return this._onListenerError(t,e,s,r)}}_getListenerExecutor(t){if(!t)return;let e=t.executor||this._options.executor;if(u(e))return e}_executeListeners(t,e,s,n){if(!t||t.length===0)return [];let r=t.reduce((p,a)=>p.concat(a.__listeners.filter(c=>u(n)?n(c,a):true).map((c,l)=>[c,l,a.__listeners])),[]);u(this._options.transform)&&(s||(s={}),s.rawEventType=e.type,e.payload=this._options.transform.call(this,e),s.flags=this._setListenerFlags(s.flags,_.Transformed)),this._decListenerExecCount(r);let o=this._getListenerExecutor(s);if(o){let p=o(r.map(a=>a[0]),e,s,this._executeListener.bind(this));return Array.isArray(p)?p:[p]}else return r.map(p=>this._executeListener(p[0][0],e,s,true))}_decListenerExecCount(t){for(let e=t.length-1;e>=0;e--){let s=t[e][0];s[2]++,s[1]>0&&s[1]<=s[2]&&t[e][2].splice(e,1);}}getListeners(t){let e=[],s=t.split(this._delimiter);return this._traverseToPath(this.listeners,s,n=>{e.push(n);}),e[0].__listeners}emit(){if(arguments.length===2&&typeof arguments[0]=="string"&&arguments[1]===b.clearRetain)return this.retainedMessages.delete(arguments[0]),[];let[t,e]=L(arguments,this.options.meta);u(e.parseArgs)&&e.parseArgs(t,e);let s=t.type.split(this._delimiter);e.retain&&this.retainedMessages.set(t.type,t);let n=[],r=[];if(this._traverseToPath(this.listeners,s,o=>{r.push(o);}),u(this._options.onBeforeExecuteListener)){let o=this._options.onBeforeExecuteListener.call(this,t,e);if(Array.isArray(o))return o;if(o===false)throw new d(t.type)}return u(this._options.transform)&&(t.payload=this._options.transform.call(this,t),e.rawEventType=t.type,e.flags=(e.flags||0)|_.Transformed),n.push(...this._executeListeners(r,t,e)),u(this._options.onAfterExecuteListener)&&this._options.onAfterExecuteListener.call(this,t,n,r),this._options.expandEmitResults&&B(n),n}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(e=>e.status==="fulfilled"?e.value:e.reason)}waitFor(){let t=arguments[0],e=arguments[1];return new Promise((s,n)=>{let r,o,p=f(a=>{clearTimeout(r),o&&o.off(),s(a);},"listener");e&&e>0&&(r=setTimeout(()=>{o&&o.off(),n(new Error("wait for event<"+t+"> is timeout"));},e)),o=this.on(t,p);})}scope(){let[t,e,s]=E(arguments,this.options.meta,this.options.context),n;return e?n=e:n=new v,n.bind(this,t,s),n}};f(P,"FastEvent");var q=P;function Kt(i){return i?typeof i=="object"&&"type"in i:false}f(Kt,"isFastEventMessage");function kt(i){return i&&typeof i=="string"}f(kt,"isString");function te(i){return typeof i=="function"&&(i.toString().startsWith("class ")||i.prototype?.constructor===i)}f(te,"isClass");function ie(i){return i?typeof i=="object"&&"__FastEvent__"in i:false}f(ie,"isFastEvent");exports.AbortError=d;exports.CancelError=y;exports.FastEvent=q;exports.FastEventDirectives=b;exports.FastEventError=m;exports.FastEventListenerFlags=_;exports.FastEventScope=v;exports.QueueOverflowError=W;exports.TimeoutError=C;exports.UnboundError=x;exports.__FastEventScope__=J;exports.__FastEvent__=H;exports.__expandable__=V;exports.expandable=Tt;exports.isClass=te;exports.isExpandable=I;exports.isFastEvent=ie;exports.isFastEventMessage=Kt;exports.isFastEventScope=D;exports.isFunction=u;exports.isPathMatched=O;exports.isString=kt;exports.isSubsctiber=X;//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|