fastevent 2.1.4 → 2.2.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/index.d.ts CHANGED
@@ -1,43 +1,52 @@
1
- type FastListenerPipe = (listener: FastEventListener) => FastEventListener;
1
+ type FastListenerPipe = (listener: TypedFastEventListener) => TypedFastEventListener;
2
2
 
3
3
  interface FastEventMeta {
4
4
  }
5
5
  interface FastEventMessageExtends {
6
6
  }
7
- type FastEventMessage = {
8
- type: string;
9
- payload: any;
10
- meta?: Record<string, any>;
11
- };
7
+ type FastEventMessage<P = any, M extends Record<string, any> = Record<string, any>, T extends string = string> = {
8
+ type: T;
9
+ payload: P;
10
+ meta?: M & Partial<FastEventMeta>;
11
+ } & FastEventMessageExtends;
12
12
  type TypedFastEventMessage<Events extends Record<string, any> = Record<string, any>, M = any> = ({
13
13
  [K in keyof Events]: {
14
14
  type: Exclude<K, number | symbol>;
15
15
  payload: Events[K];
16
16
  meta: FastEventMeta & M & Record<string, any>;
17
17
  };
18
- }[Exclude<keyof Events, number | symbol>]) & DeepPartial<FastEventMessageExtends>;
18
+ }[Exclude<keyof Events, number | symbol>]) & FastEventMessageExtends;
19
19
  type TypedFastEventMessageOptional<Events extends Record<string, any> = Record<string, any>, M = any> = ({
20
20
  [K in keyof Events]: {
21
21
  type: Exclude<K, number | symbol>;
22
22
  payload: Events[K];
23
23
  meta?: DeepPartial<FastEventMeta & M & Record<string, any>>;
24
24
  };
25
- }[Exclude<keyof Events, number | symbol>]) & DeepPartial<FastEventMessageExtends>;
25
+ }[Exclude<keyof Events, number | symbol>]) & FastEventMessageExtends;
26
26
  type FastEventEmitMessage<Events extends Record<string, any> = Record<string, any>, M = any> = ({
27
27
  [K in keyof Events]: {
28
28
  type: Exclude<K, number | symbol>;
29
29
  payload?: Events[K];
30
30
  meta?: DeepPartial<FastEventMeta & M & Record<string, any>>;
31
31
  };
32
- }[Exclude<keyof Events, number | symbol>]) & DeepPartial<FastEventMessageExtends>;
33
- type FastEventListener<T extends string = string, P = any, M = any, C = any> = (this: C, message: TypedFastEventMessage<{
32
+ }[Exclude<keyof Events, number | symbol>]) & FastEventMessageExtends;
33
+ type TypedFastEventListener<T extends string = string, P = any, M = any, C = any> = (this: C, message: TypedFastEventMessage<{
34
34
  [K in T]: P;
35
35
  }, M>, args: FastEventListenerArgs<M>) => any | Promise<any>;
36
- type FastEventAnyListener<Events extends Record<string, any> = Record<string, any>, Meta = never, Context = any> = (this: Context, message: TypedFastEventMessage<Events, Meta>, args: FastEventListenerArgs<Meta>) => any | Promise<any>;
36
+ 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>;
37
+ type FastEventListeners<Events extends Record<string, any> = Record<string, any>, M = any, C = any> = ({
38
+ [K in keyof Events]: TypedFastEventListener<Exclude<K, number | symbol>, Events[K], M, C>;
39
+ });
40
+ type FastEventListener<P = any, M extends Record<string, any> = Record<string, any>, T extends string = string> = (message: FastEventMessage<P, M, T>, args: FastEventListenerArgs<M>) => any | Promise<any>;
37
41
  /**
38
- * [监听器函数引用,需要执行多少次,实际执行的次数(用于负载均衡时记录)]
42
+ * [
43
+ * 监听器函数引用,
44
+ * 需要执行多少次, =0代表不限
45
+ * 实际执行的次数(用于负载均衡时记录)
46
+ * 标签 用于调试一般可以标识监听器类型或任意信息
47
+ * ]
39
48
  */
40
- type FastListenerMeta = [FastEventListener<any, any>, number, number];
49
+ type FastListenerMeta = [TypedFastEventListener<any, any>, number, number, string?];
41
50
  type FastListenerNode = {
42
51
  __listeners: FastListenerMeta[];
43
52
  } & {
@@ -73,7 +82,7 @@ type FastEventSubscriber = {
73
82
  * scope.off(subscriber.listener) // 生效
74
83
  *
75
84
  */
76
- listener: FastEventListener<any, any, any>;
85
+ listener: TypedFastEventListener<any, any, any>;
77
86
  };
78
87
  type FastListeners = FastListenerNode;
79
88
  type FastEventOptions<Meta = Record<string, any>, Context = never> = {
@@ -83,17 +92,17 @@ type FastEventOptions<Meta = Record<string, any>, Context = never> = {
83
92
  context: Context;
84
93
  ignoreErrors: boolean;
85
94
  meta: Meta;
86
- onAddListener?: (type: string, listener: FastEventListener, options: FastEventListenOptions<Record<string, any>, Meta>) => boolean | FastEventSubscriber | void;
87
- onRemoveListener?: (type: string, listener: FastEventListener) => void;
95
+ onAddListener?: (type: string, listener: TypedFastEventListener, options: FastEventListenOptions<Record<string, any>, Meta>) => boolean | FastEventSubscriber | void;
96
+ onRemoveListener?: (type: string, listener: TypedFastEventListener) => void;
88
97
  onClearListeners?: () => void;
89
- onListenerError?: ((error: Error, listener: FastEventListener, message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta> | undefined) => void);
98
+ onListenerError?: ((error: Error, listener: TypedFastEventListener, message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta> | undefined) => void);
90
99
  onBeforeExecuteListener?: (message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta>) => boolean | void | any[];
91
100
  onAfterExecuteListener?: (message: TypedFastEventMessage<any, Meta>, returns: any[], listeners: FastListenerNode[]) => void;
92
101
  /**
93
102
  * 全局执行器
94
103
  */
95
104
  executor?: FastListenerExecutor;
96
- onMessage?: FastEventListener;
105
+ onMessage?: TypedFastEventListener;
97
106
  expandEmitResults?: boolean;
98
107
  };
99
108
  interface FastEvents {
@@ -108,6 +117,15 @@ type FastEventListenOptions<Events extends Record<string, any> = Record<string,
108
117
  filter?: (message: TypedFastEventMessage<Events, Meta>, args: FastEventListenerArgs<Meta>) => boolean;
109
118
  off?: (message: TypedFastEventMessage<Events, Meta>, args: FastEventListenerArgs<Meta>) => boolean;
110
119
  pipes?: FastListenerPipe[];
120
+ /**
121
+ * 为监听器添加一个tag,在监听器注册表中记录,用于调试使用
122
+ *
123
+ * emitter.on(type,listener,{tag:"x"})
124
+ *
125
+ * emitter.getListeners(tag)
126
+ *
127
+ */
128
+ tag?: string;
111
129
  };
112
130
  type FastEventListenerArgs<M = Record<string, any>> = {
113
131
  retain?: boolean;
@@ -256,17 +274,17 @@ type Overloads<T> = Unique<T extends {
256
274
  ]>;
257
275
  type Dict<V = any> = Record<Exclude<string, number | symbol>, V>;
258
276
 
259
- type FastListenerExecutor = (listeners: FastListenerMeta[], message: TypedFastEventMessage, args: FastEventListenerArgs, execute: (listener: FastEventListener, message: TypedFastEventMessage, args: FastEventListenerArgs, catchErrors?: boolean) => Promise<any> | any) => Promise<any[]> | any[];
277
+ type FastListenerExecutor = (listeners: FastListenerMeta[], message: TypedFastEventMessage, args: FastEventListenerArgs, execute: (listener: TypedFastEventListener, message: TypedFastEventMessage, args: FastEventListenerArgs, catchErrors?: boolean) => Promise<any> | any) => Promise<any[]> | any[];
260
278
 
261
279
  type FastEventScopeOptions<Meta = Record<string, any>, Context = never> = {
262
280
  meta: FastEventScopeMeta & FastEventMeta & Meta;
263
281
  context: Context;
264
282
  executor?: FastListenerExecutor;
265
- onMessage?: FastEventListener;
283
+ onMessage?: TypedFastEventListener;
266
284
  };
267
- type FastEventScopeMeta = {
285
+ interface FastEventScopeMeta {
268
286
  scope: string;
269
- };
287
+ }
270
288
  declare class FastEventScope<Events extends Record<string, any> = Record<string, any>, Meta extends Record<string, any> = Record<string, any>, Context = never, Types extends keyof Events = keyof Events, FinalMeta extends Record<string, any> = FastEventMeta & FastEventScopeMeta & Meta> {
271
289
  __FastEventScope__: boolean;
272
290
  private _options;
@@ -275,6 +293,8 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
275
293
  meta: FinalMeta;
276
294
  context: Fallback<Context, typeof this>;
277
295
  message: TypedFastEventMessageOptional<Events, FinalMeta>;
296
+ listeners: FastEventListeners<Events, FinalMeta>;
297
+ anyListener: TypedFastEventAnyListener<Events, FinalMeta, Fallback<Context, typeof this>>;
278
298
  };
279
299
  prefix: string;
280
300
  emitter: FastEvent<Events>;
@@ -304,20 +324,20 @@ declare class FastEventScope<Events extends Record<string, any> = Record<string,
304
324
  on<T extends Types = Types>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
305
325
  on<T extends string>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
306
326
  on(type: '**', options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
307
- on<T extends Types = Types>(type: T, listener: FastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
308
- on<T extends string>(type: T, listener: FastEventListener<string, any, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
309
- on(type: '**', listener: FastEventAnyListener<Events, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
327
+ on<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
328
+ on<T extends string>(type: T, listener: TypedFastEventListener<string, any, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
329
+ on(type: '**', listener: TypedFastEventAnyListener<Events, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
310
330
  once<T extends Types = Types>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
311
331
  once<T extends string>(type: T, options?: FastEventListenOptions<Events, FinalMeta>): FastEventSubscriber;
312
- once<T extends Types = Types>(type: T, listener: FastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
313
- once<T extends string>(type: T, listener: FastEventListener<string, any, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
332
+ once<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, Events[T], FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
333
+ once<T extends string>(type: T, listener: TypedFastEventListener<string, any, FinalMeta, Fallback<Context, typeof this>>, options?: FastEventListenOptions): FastEventSubscriber;
314
334
  onAny(options?: Pick<FastEventListenOptions, 'prepend'>): FastEventSubscriber;
315
- onAny<P = any>(listener: FastEventAnyListener<{
335
+ onAny<P = any>(listener: TypedFastEventAnyListener<{
316
336
  [K: string]: P;
317
337
  }, FinalMeta, Fallback<Context, typeof this>>, options?: Pick<FastEventListenOptions, 'prepend'>): FastEventSubscriber;
318
- off(listener: FastEventListener<any, any, any>): void;
319
- off(type: string, listener: FastEventListener<any, any, any>): void;
320
- off(type: Types, listener: FastEventListener<any, any, any>): void;
338
+ off(listener: TypedFastEventListener<any, any, any>): void;
339
+ off(type: string, listener: TypedFastEventListener<any, any, any>): void;
340
+ off(type: Types, listener: TypedFastEventListener<any, any, any>): void;
321
341
  off(type: string): void;
322
342
  off(type: Types): void;
323
343
  offAll(): void;
@@ -409,6 +429,8 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
409
429
  meta: Expand<FastEventMeta & Meta & Record<string, any>>;
410
430
  context: Expand<Fallback<Context, typeof this>>;
411
431
  message: TypedFastEventMessageOptional<AllEvents, Expand<FastEventMeta & Meta & Record<string, any>>>;
432
+ listeners: FastEventListeners<AllEvents, Expand<FastEventMeta & Meta & Record<string, any>>>;
433
+ anyListener: TypedFastEventAnyListener<AllEvents, Expand<FastEventMeta & Meta & Record<string, any>>, Expand<Fallback<Context, typeof this>>>;
412
434
  };
413
435
  /**
414
436
  * 创建FastEvent实例
@@ -494,9 +516,9 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
494
516
  on<T extends Types = Types>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
495
517
  on<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
496
518
  on(type: '**', options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
497
- on<T extends Types = Types>(type: T, listener: FastEventListener<Exclude<T, number | symbol>, AllEvents[T], Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
498
- on<T extends string>(type: T, listener: FastEventAnyListener<AllEvents, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
499
- on(type: '**', listener: FastEventAnyListener<Record<string, any>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
519
+ on<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, AllEvents[T], Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
520
+ on<T extends string>(type: T, listener: TypedFastEventAnyListener<AllEvents, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
521
+ on(type: '**', listener: TypedFastEventAnyListener<Record<string, any>, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
500
522
  /**
501
523
  * 注册一次性事件监听器
502
524
  * @param type - 事件类型,支持与on方法相同的格式:
@@ -520,8 +542,8 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
520
542
  */
521
543
  once<T extends Types = Types>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
522
544
  once<T extends string>(type: T, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
523
- once<T extends Types = Types>(type: T, listener: FastEventListener<Exclude<T, number | symbol>, AllEvents[T], Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
524
- once<T extends string>(type: T, listener: FastEventAnyListener<AllEvents, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
545
+ once<T extends Types = Types>(type: T, listener: TypedFastEventListener<Exclude<T, number | symbol>, AllEvents[T], Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
546
+ once<T extends string>(type: T, listener: TypedFastEventAnyListener<AllEvents, Meta, Fallback<Context, typeof this>>, options?: FastEventListenOptions<AllEvents, Meta>): FastEventSubscriber;
525
547
  /**
526
548
  * 注册一个监听器,用于监听所有事件
527
549
  * @param listener 事件监听器函数,可以接收任意类型的事件数据
@@ -537,7 +559,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
537
559
  * ```listener: FastEventAnyListener<AllEvents, Meta, Fallback<Context, typeof this>>): FastEventSubscriber
538
560
  */
539
561
  onAny(options?: Omit<FastEventListenOptions<AllEvents, Meta>, 'count'>): FastEventSubscriber;
540
- onAny<P = any>(listener: FastEventAnyListener<Record<string, P>, Meta, Fallback<Context, typeof this>>, options?: Omit<FastEventListenOptions<AllEvents, Meta>, 'count'>): FastEventSubscriber;
562
+ onAny<P = any>(listener: TypedFastEventAnyListener<Record<string, P>, Meta, Fallback<Context, typeof this>>, options?: Omit<FastEventListenOptions<AllEvents, Meta>, 'count'>): FastEventSubscriber;
541
563
  /**
542
564
  *
543
565
  * 当调用on/once/onAny时如果没有指定监听器,则调用此方法
@@ -546,9 +568,9 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
546
568
  *
547
569
  */
548
570
  onMessage(message: TypedFastEventMessage<AllEvents, Meta>, args: FastEventListenerArgs<Meta>): void;
549
- off(listener: FastEventListener<any, any, any>): void;
550
- off(type: string, listener: FastEventListener<any, any, any>): void;
551
- off(type: Types, listener: FastEventListener<any, any, any>): void;
571
+ off(listener: TypedFastEventListener<any, any, any>): void;
572
+ off(type: string, listener: TypedFastEventListener<any, any, any>): void;
573
+ off(type: Types, listener: TypedFastEventListener<any, any, any>): void;
552
574
  off(type: string): void;
553
575
  off(type: Types): void;
554
576
  /**
@@ -715,6 +737,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
715
737
  [K in T]: K extends Types ? AllEvents[K] : any;
716
738
  }, Meta>, options?: FastEventListenerArgs<Meta>): R[];
717
739
  emit<R = any>(message: FastEventEmitMessage<AllEvents, Meta>, options?: FastEventListenerArgs<Meta>): R[];
740
+ getListeners(type: keyof AllEvents): FastListenerMeta[];
718
741
  /**
719
742
  * 异步触发事件
720
743
  * @param type - 事件类型,可以是字符串或预定义的事件类型
@@ -860,4 +883,4 @@ declare const FastEventDirectives: {
860
883
  clearRetain: symbol;
861
884
  };
862
885
 
863
- export { AbortError, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type Fallback, FastEvent, type FastEventAnyListener, FastEventDirectives, type FastEventEmitMessage, FastEventError, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListenerMeta, type FastListenerNode, type FastListeners, type Merge, type ObjectKeys, type OptionalItems, type Overloads, type OverrideOptions, type PickScopeEvents, QueueOverflowError, type RequiredItems, type ScopeEvents, TimeoutError, type TypedFastEventMessage, type TypedFastEventMessageOptional, UnboundError, type Unique, __FastEventScope__, __FastEvent__ };
886
+ export { AbortError, CancelError, type ChangeFieldType, type DeepPartial, type Dict, type Expand, type Fallback, FastEvent, FastEventDirectives, type FastEventEmitMessage, FastEventError, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, type FastEventListeners, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListenerMeta, type FastListenerNode, type FastListeners, type Merge, type ObjectKeys, type OptionalItems, type Overloads, type OverrideOptions, type PickScopeEvents, QueueOverflowError, type RequiredItems, type ScopeEvents, TimeoutError, type TypedFastEventAnyListener, type TypedFastEventListener, type TypedFastEventMessage, type TypedFastEventMessageOptional, UnboundError, type Unique, __FastEventScope__, __FastEvent__ };
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- 'use strict';var R=Object.defineProperty;var $=(r,e,t)=>e in r?R(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t;var a=(r,e)=>R(r,"name",{value:e,configurable:true});var f=(r,e,t)=>$(r,typeof e!="symbol"?e+"":e,t);var G=Symbol.for("__FastEvent__"),H=Symbol.for("__FastEventScope__"),S=class S extends Error{constructor(e){super(e);}};a(S,"FastEventError");var m=S,A=class A extends m{};a(A,"TimeoutError");var F=A,M=class M extends m{};a(M,"UnboundError");var d=M,T=class T extends m{};a(T,"AbortError");var _=T,O=class O extends m{};a(O,"CancelError");var x=O,j=class j extends m{};a(j,"QueueOverflowError");var C=j,y={clearRetain:Symbol.for("ClearRetain")};function b(r,e,t,s){let i,n={},o={};return typeof r[0]=="object"?(Object.assign(o,r[0]),n=typeof r[1]=="boolean"?{retain:r[1]}:r[1]||{},i=r[0].meta):(o.type=r[0],o.payload=r[1],n=typeof r[2]=="boolean"?{retain:r[2]}:r[2]||{}),i=Object.assign({},e,t,n.meta,i),Object.keys(i).length===0&&(i=void 0),o.meta=i,n.executor===void 0&&(n.executor=s),[o,n]}a(b,"parseEmitArgs");function D(r){return r?typeof r=="object"&&"__FastEventScope__"in r:false}a(D,"isFastEventScope");function L(r,e,t){let s=r[0],i=D(r[1])?r[1]:void 0,n=(i?r[2]:r[1])||{};return n.meta=Object.assign({},e,n?.meta),n.context=n.context!==void 0?n.context:t,[s,i,n]}a(L,"parseScopeArgs");function g(r,e){return Object.defineProperty(r,"name",{value:e||"anonymous",configurable:true}),r}a(g,"renameFn");var v=class v{constructor(e){f(this,"__FastEventScope__",true);f(this,"_options",{});f(this,"types",{events:void 0,meta:void 0,context:void 0,message:void 0});f(this,"prefix","");f(this,"emitter");this._options=Object.assign({},this._initOptions(e));}get context(){return this.options.context||this}get options(){return this._options}bind(e,t,s){this.emitter=e,this._options=Object.assign(this._options,{scope:t},s),t.length>0&&!t.endsWith(e.options.delimiter)&&(this.prefix=t+e.options.delimiter);}_initOptions(e){return e}_getScopeListener(e){let t=this.prefix;if(t.length===0)return e;e||(e=(this._options.onMessage||this.onMessage).bind(this));let s=this;return g(function(n,o){if(n.type.startsWith(t))return e.call(s.context,Object.assign({},n,{type:n.type.substring(t.length)}),o)},e.name)}_getScopeType(e){return e===void 0?void 0:this.prefix+e}_fixScopeType(e){return e.startsWith(this.prefix)?e.substring(this.prefix.length):e}on(){if(!this.emitter)throw new d;let e=[...arguments];return e[0]=this._getScopeType(e[0]),e[1]=this._getScopeListener(e[1]),this.emitter.on(...e)}once(){return this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",...arguments)}off(){let e=arguments;typeof e[0]=="string"&&(e[0]=this._getScopeType(e[0])),this.emitter.off(...e);}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]===y.clearRetain)return this.emitter.emit(this._getScopeType(arguments[0]));let[e,t]=b(arguments,this.emitter.options.meta,this.options.meta,this.options.executor);return e.type=this._getScopeType(e.type),this.emitter.emit(e,t)}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}async waitFor(){let e=arguments[0],t=arguments[1],s=await this.emitter.waitFor(this._getScopeType(e),t);return Object.assign({},s,{type:this._fixScopeType(s.type)})}scope(){let[e,t,s]=L(arguments,this.options.meta,this.options.context),i;return t?i=t:i=new v,i.bind(this.emitter,this.prefix+e,s),i}onMessage(e,t){}};a(v,"FastEventScope");var E=v;function w(r,e){if(r.length!==e.length&&r.length>0&&e[e.length-1]!=="**")return false;let t=[...e];e.length>0&&e[e.length-1]==="**"&&t.splice(e.length-1,1,...Array.from({length:r.length-e.length+1}).fill("*"));for(let s=0;s<r.length;s++)if(t[s]!=="*"&&t[s]!==r[s])return false;return true}a(w,"isPathMatched");function W(r,e){let t=[];for(;;){let s=r.findIndex(i=>e(i));if(s===-1){t.push(s);break}r.splice(s,1);}return t}a(W,"removeItem");function h(r){return r&&typeof r=="function"}a(h,"isFunction");var q=Symbol.for("__expandable__");function N(r){return r&&r[q]}a(N,"isExpandable");function V(r){for(let e=0;e<r.length;e++){let t=r[e];Array.isArray(t)&&N(t)&&(r.splice(e,1,...t),e+=t.length-1);}return r}a(V,"expandEmitResults");function I(r){return r&&typeof r=="object"&&"off"in r&&"listener"in r}a(I,"isSubsctiber");function B(r,e){return r.catch(t=>(e&&e(t),Promise.resolve(t)))}a(B,"tryReturnError");var P=class P{constructor(e){f(this,"__FastEvent__",true);f(this,"listeners",{__listeners:[]});f(this,"_options");f(this,"_delimiter","/");f(this,"_context");f(this,"retainedMessages",new Map);f(this,"listenerCount",0);f(this,"types",{events:void 0,meta:void 0,context:void 0,message: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(e)),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(e){return e}_addListener(e,t,s){let{count:i,prepend:n}=s,o=0;return [this._forEachNodes(e,c=>{let l=[t,i,0];n?(c.__listeners.splice(0,0,l),o=0):(c.__listeners.push(l),o=c.__listeners.length-1),this.listenerCount++;}),o]}_enableDevTools(){this.options.debug&&globalThis.__FLEXEVENT_DEVTOOLS__&&globalThis.__FLEXEVENT_DEVTOOLS__.add(this);}_forEachNodes(e,t){if(e.length===0)return;let s=this.listeners;for(let i=0;i<e.length;i++){let n=e[i];if(n in s||(s[n]={__listeners:[]}),i===e.length-1){let o=s[n];return t(o,s),o}else s=s[n];}}_removeListener(e,t,s){s&&W(e.__listeners,i=>{i=Array.isArray(i)?i[0]:i;let n=i===s;return n&&(this.listenerCount--,h(this._options.onRemoveListener)&&this._options.onRemoveListener(t.join(this._delimiter),s)),n});}_pipeListener(e,t){return t.forEach(s=>{e=g(s(e),e.name);}),e}on(){let e=arguments[0],t=h(arguments[1])?arguments[1]:(this._options.onMessage||this.onMessage).bind(this),s=Object.assign({count:0,prepend:false},h(arguments[1])?arguments[2]:arguments[1]);if(e.length===0)throw new Error("event type cannot be empty");if(h(this._options.onAddListener)){let c=this._options.onAddListener(e,t,s);if(c===false)throw new x;if(I(c))return c}let i=e.split(this._delimiter);if(s.pipes&&s.pipes.length>0&&(t=this._pipeListener(t,s.pipes)),h(s.filter)||h(s.off)){let c=t;t=g(function(l,p){if(h(s.off)&&s.off.call(this,l,p)){u();return}if(h(s.filter)){if(s.filter.call(this,l,p))return c.call(this,l,p)}else return c.call(this,l,p)},t.name);}let[n,o]=this._addListener(i,t,s),u=a(()=>n&&this._removeListener(n,i,t),"off");return this._emitRetainMessage(e,n,o),{off:u,listener:t}}once(){return h(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(e,t){}off(){let e=arguments,t=h(e[0])?void 0:e[0],s=h(e[0])?e[0]:e[1],i=t?t.split(this._delimiter):[],n=t?t.includes("*"):false;if(t&&!n)this._traverseToPath(this.listeners,i,o=>{s?this._removeListener(o,i,s):t&&(o.__listeners=[]);});else {let o=n?[]:i;this._traverseListeners(this.listeners,o,(u,c)=>{(s!==void 0||n&&w(u,i))&&(s?this._removeListener(c,i,s):c.__listeners=[]);});}}offAll(e){if(e){let t=e.split(this._delimiter),s=0;this._traverseListeners(this.listeners,t,(i,n)=>{s+=n.__listeners.length,n.__listeners=[];}),this.listenerCount-=s,this._removeRetainedEvents(e);}else {let t=0;this._traverseListeners(this.listeners,[],(s,i)=>{t+=i.__listeners.length;}),this.listenerCount-=t,this.retainedMessages.clear(),this.listeners={__listeners:[]};}h(this._options.onClearListeners)&&this._options.onClearListeners.call(this);}_removeRetainedEvents(e){e||this.retainedMessages.clear(),e?.endsWith(this._delimiter)&&(e+=this._delimiter),this.retainedMessages.delete(e);for(let t of this.retainedMessages.keys())t.startsWith(e)&&this.retainedMessages.delete(t);}clear(e){this.offAll(e),this._removeRetainedEvents(e);}_emitRetainMessage(e,t,s){let i=[];if(e.includes("*")){let n=e.split(this._delimiter);this.retainedMessages.forEach((o,u)=>{let c=u.split(this._delimiter);w(c,n)&&i.push(o);});}else this.retainedMessages.has(e)&&i.push(this.retainedMessages.get(e));t&&i.forEach(n=>{this._executeListeners([t],n,{},o=>o[0]===t.__listeners[s][0]);});}_traverseToPath(e,t,s,i=0,n){if(i>=t.length){s(e);return}let o=t[i];if(n===true){this._traverseToPath(e,t,s,i+1,true);return}"*"in e&&this._traverseToPath(e["*"],t,s,i+1),"**"in e&&this._traverseToPath(e["**"],t,s,i+1,true),o in e&&this._traverseToPath(e[o],t,s,i+1);}_traverseListeners(e,t,s){let i=e;t&&t.length>0&&this._traverseToPath(e,t,o=>{i=o;});let n=a((o,u,c)=>{u(c,o);for(let[l,p]of Object.entries(o))l.startsWith("__")||p&&n(p,u,[...c,l]);},"traverseNodes");n(i,s,[]);}_onListenerError(e,t,s,i){if(i instanceof Error&&(i._emitter=`${e.name||"anonymous"}:${t.type}`),h(this._options.onListenerError))try{this._options.onListenerError.call(this,i,e,t,s);}catch{}if(this._options.ignoreErrors)return i;throw i}_executeListener(e,t,s,i=false){try{if(s&&s.abortSignal&&s.abortSignal.aborted)return this._onListenerError(e,t,s,new _(e.name));let n=e.call(this.context,t,s);return i&&n&&n instanceof Promise&&(n=B(n,o=>this._onListenerError(e,t,s,o))),n}catch(n){return this._onListenerError(e,t,s,n)}}_getListenerExecutor(e){if(!e)return;let t=e.executor||this._options.executor;if(h(t))return t}_executeListeners(e,t,s,i){if(!e||e.length===0)return [];let n=e.reduce((o,u)=>o.concat(u.__listeners.filter(c=>h(i)?i(c,u):true).map((c,l)=>[c,l,u.__listeners])),[]);try{let o=this._getListenerExecutor(s);if(o){let u=o(n.map(c=>c[0]),t,s,this._executeListener.bind(this));return Array.isArray(u)?u:[u]}else return n.map(u=>this._executeListener(u[0][0],t,s,!0))}finally{for(let o=n.length-1;o>=0;o--){let u=n[o][0];u[2]++,u[1]>0&&u[1]<=u[2]&&n[o][2].splice(o,1);}}}emit(){if(arguments.length===2&&typeof arguments[0]=="string"&&arguments[1]===y.clearRetain)return this.retainedMessages.delete(arguments[0]),[];let[e,t]=b(arguments,this.options.meta);h(t.parseArgs)&&t.parseArgs(e,t);let s=e.type.split(this._delimiter);t.retain&&this.retainedMessages.set(e.type,e);let i=[],n=[];if(this._traverseToPath(this.listeners,s,o=>{n.push(o);}),h(this._options.onBeforeExecuteListener)){let o=this._options.onBeforeExecuteListener.call(this,e,t);if(Array.isArray(o))return o;if(o===false)throw new _(e.type)}return i.push(...this._executeListeners(n,e,t)),h(this._options.onAfterExecuteListener)&&this._options.onAfterExecuteListener.call(this,e,i,n),this._options.expandEmitResults&&V(i),i}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}waitFor(){let e=arguments[0],t=arguments[1];return new Promise((s,i)=>{let n,o,u=a(c=>{clearTimeout(n),o.off(),s(c);},"listener");t&&t>0&&(n=setTimeout(()=>{o&&o.off(),i(new Error("wait for event<"+e+"> is timeout"));},t)),o=this.on(e,u);})}scope(){let[e,t,s]=L(arguments,this.options.meta,this.options.context),i;return t?i=t:i=new E,i.bind(this,e,s),i}};a(P,"FastEvent");var X=P;exports.AbortError=_;exports.CancelError=x;exports.FastEvent=X;exports.FastEventDirectives=y;exports.FastEventError=m;exports.FastEventScope=E;exports.QueueOverflowError=C;exports.TimeoutError=F;exports.UnboundError=d;exports.__FastEventScope__=H;exports.__FastEvent__=G;//# sourceMappingURL=index.js.map
1
+ 'use strict';var R=Object.defineProperty;var $=(r,e,t)=>e in r?R(r,e,{enumerable:true,configurable:true,writable:true,value:t}):r[e]=t;var a=(r,e)=>R(r,"name",{value:e,configurable:true});var f=(r,e,t)=>$(r,typeof e!="symbol"?e+"":e,t);var G=Symbol.for("__FastEvent__"),H=Symbol.for("__FastEventScope__"),S=class S extends Error{constructor(e){super(e);}};a(S,"FastEventError");var m=S,A=class A extends m{};a(A,"TimeoutError");var F=A,T=class T extends m{};a(T,"UnboundError");var d=T,M=class M extends m{};a(M,"AbortError");var _=M,O=class O extends m{};a(O,"CancelError");var x=O,j=class j extends m{};a(j,"QueueOverflowError");var C=j,y={clearRetain:Symbol.for("ClearRetain")};function b(r,e,t,s){let i,n={},o={};return typeof r[0]=="object"?(Object.assign(o,r[0]),n=typeof r[1]=="boolean"?{retain:r[1]}:r[1]||{},i=r[0].meta):(o.type=r[0],o.payload=r[1],n=typeof r[2]=="boolean"?{retain:r[2]}:r[2]||{}),i=Object.assign({},e,t,n.meta,i),Object.keys(i).length===0&&(i=void 0),o.meta=i,n.executor===void 0&&(n.executor=s),[o,n]}a(b,"parseEmitArgs");function D(r){return r?typeof r=="object"&&"__FastEventScope__"in r:false}a(D,"isFastEventScope");function L(r,e,t){let s=r[0],i=D(r[1])?r[1]:void 0,n=(i?r[2]:r[1])||{};return n.meta=Object.assign({},e,n?.meta),n.context=n.context!==void 0?n.context:t,[s,i,n]}a(L,"parseScopeArgs");function g(r,e){return Object.defineProperty(r,"name",{value:e||"anonymous",configurable:true}),r}a(g,"renameFn");var v=class v{constructor(e){f(this,"__FastEventScope__",true);f(this,"_options",{});f(this,"types",{events:void 0,meta:void 0,context:void 0,message:void 0,listeners:void 0,anyListener:void 0});f(this,"prefix","");f(this,"emitter");this._options=Object.assign({},this._initOptions(e));}get context(){return this.options.context||this}get options(){return this._options}bind(e,t,s){this.emitter=e,this._options=Object.assign(this._options,{scope:t},s),t.length>0&&!t.endsWith(e.options.delimiter)&&(this.prefix=t+e.options.delimiter);}_initOptions(e){return e}_getScopeListener(e){let t=this.prefix;if(t.length===0)return e;e||(e=(this._options.onMessage||this.onMessage).bind(this));let s=this;return g(function(n,o){if(n.type.startsWith(t))return e.call(s.context,Object.assign({},n,{type:n.type.substring(t.length)}),o)},e.name)}_getScopeType(e){return e===void 0?void 0:this.prefix+e}_fixScopeType(e){return e.startsWith(this.prefix)?e.substring(this.prefix.length):e}on(){if(!this.emitter)throw new d;let e=[...arguments];return e[0]=this._getScopeType(e[0]),e[1]=this._getScopeListener(e[1]),this.emitter.on(...e)}once(){return this.on(arguments[0],arguments[1],Object.assign({},arguments[2],{count:1}))}onAny(){return this.on("**",...arguments)}off(){let e=arguments;typeof e[0]=="string"&&(e[0]=this._getScopeType(e[0])),this.emitter.off(...e);}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]===y.clearRetain)return this.emitter.emit(this._getScopeType(arguments[0]));let[e,t]=b(arguments,this.emitter.options.meta,this.options.meta,this.options.executor);return e.type=this._getScopeType(e.type),this.emitter.emit(e,t)}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}async waitFor(){let e=arguments[0],t=arguments[1],s=await this.emitter.waitFor(this._getScopeType(e),t);return Object.assign({},s,{type:this._fixScopeType(s.type)})}scope(){let[e,t,s]=L(arguments,this.options.meta,this.options.context),i;return t?i=t:i=new v,i.bind(this.emitter,this.prefix+e,s),i}onMessage(e,t){}};a(v,"FastEventScope");var E=v;function w(r,e){if(r.length!==e.length&&r.length>0&&e[e.length-1]!=="**")return false;let t=[...e];e.length>0&&e[e.length-1]==="**"&&t.splice(e.length-1,1,...Array.from({length:r.length-e.length+1}).fill("*"));for(let s=0;s<r.length;s++)if(t[s]!=="*"&&t[s]!==r[s])return false;return true}a(w,"isPathMatched");function W(r,e){let t=[];for(;;){let s=r.findIndex(i=>e(i));if(s===-1){t.push(s);break}r.splice(s,1);}return t}a(W,"removeItem");function c(r){return r&&typeof r=="function"}a(c,"isFunction");var q=Symbol.for("__expandable__");function N(r){return r&&r[q]}a(N,"isExpandable");function V(r){for(let e=0;e<r.length;e++){let t=r[e];Array.isArray(t)&&N(t)&&(r.splice(e,1,...t),e+=t.length-1);}return r}a(V,"expandEmitResults");function I(r){return r&&typeof r=="object"&&"off"in r&&"listener"in r}a(I,"isSubsctiber");function B(r,e){return r.catch(t=>(e&&e(t),Promise.resolve(t)))}a(B,"tryReturnError");var P=class P{constructor(e){f(this,"__FastEvent__",true);f(this,"listeners",{__listeners:[]});f(this,"_options");f(this,"_delimiter","/");f(this,"_context");f(this,"retainedMessages",new Map);f(this,"listenerCount",0);f(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(e)),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(e){return e}_addListener(e,t,s){let{count:i,prepend:n}=s,o=0;return [this._forEachNodes(e,h=>{let l=[t,i,0];s.tag&&l.push(s.tag),n?(h.__listeners.splice(0,0,l),o=0):(h.__listeners.push(l),o=h.__listeners.length-1),this.listenerCount++;}),o]}_enableDevTools(){this.options.debug&&globalThis.__FLEXEVENT_DEVTOOLS__&&globalThis.__FLEXEVENT_DEVTOOLS__.add(this);}_forEachNodes(e,t){if(e.length===0)return;let s=this.listeners;for(let i=0;i<e.length;i++){let n=e[i];if(n in s||(s[n]={__listeners:[]}),i===e.length-1){let o=s[n];return t(o,s),o}else s=s[n];}}_removeListener(e,t,s){s&&W(e.__listeners,i=>{i=Array.isArray(i)?i[0]:i;let n=i===s;return n&&(this.listenerCount--,c(this._options.onRemoveListener)&&this._options.onRemoveListener(t.join(this._delimiter),s)),n});}_pipeListener(e,t){return t.forEach(s=>{e=g(s(e),e.name);}),e}on(){let e=arguments[0],t=c(arguments[1])?arguments[1]:(this._options.onMessage||this.onMessage).bind(this),s=Object.assign({count:0,prepend:false},c(arguments[1])?arguments[2]:arguments[1]);if(e.length===0)throw new Error("event type cannot be empty");if(c(this._options.onAddListener)){let h=this._options.onAddListener(e,t,s);if(h===false)throw new x;if(I(h))return h}let i=e.split(this._delimiter);if(s.pipes&&s.pipes.length>0&&(t=this._pipeListener(t,s.pipes)),c(s.filter)||c(s.off)){let h=t;t=g(function(l,p){if(c(s.off)&&s.off.call(this,l,p)){u();return}if(c(s.filter)){if(s.filter.call(this,l,p))return h.call(this,l,p)}else return h.call(this,l,p)},t.name);}let[n,o]=this._addListener(i,t,s),u=a(()=>n&&this._removeListener(n,i,t),"off");return this._emitRetainMessage(e,n,o),{off:u,listener:t}}once(){return c(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(e,t){}off(){let e=arguments,t=c(e[0])?void 0:e[0],s=c(e[0])?e[0]:e[1],i=t?t.split(this._delimiter):[],n=t?t.includes("*"):false;if(t&&!n)this._traverseToPath(this.listeners,i,o=>{s?this._removeListener(o,i,s):t&&(o.__listeners=[]);});else {let o=n?[]:i;this._traverseListeners(this.listeners,o,(u,h)=>{(s!==void 0||n&&w(u,i))&&(s?this._removeListener(h,i,s):h.__listeners=[]);});}}offAll(e){if(e){let t=e.split(this._delimiter),s=0;this._traverseListeners(this.listeners,t,(i,n)=>{s+=n.__listeners.length,n.__listeners=[];}),this.listenerCount-=s,this._removeRetainedEvents(e);}else {let t=0;this._traverseListeners(this.listeners,[],(s,i)=>{t+=i.__listeners.length;}),this.listenerCount-=t,this.retainedMessages.clear(),this.listeners={__listeners:[]};}c(this._options.onClearListeners)&&this._options.onClearListeners.call(this);}_removeRetainedEvents(e){e||this.retainedMessages.clear(),e?.endsWith(this._delimiter)&&(e+=this._delimiter),this.retainedMessages.delete(e);for(let t of this.retainedMessages.keys())t.startsWith(e)&&this.retainedMessages.delete(t);}clear(e){this.offAll(e),this._removeRetainedEvents(e);}_emitRetainMessage(e,t,s){let i=[];if(e.includes("*")){let n=e.split(this._delimiter);this.retainedMessages.forEach((o,u)=>{let h=u.split(this._delimiter);w(h,n)&&i.push(o);});}else this.retainedMessages.has(e)&&i.push(this.retainedMessages.get(e));t&&i.forEach(n=>{this._executeListeners([t],n,{},o=>o[0]===t.__listeners[s][0]);});}_traverseToPath(e,t,s,i=0,n){if(i>=t.length){s(e);return}let o=t[i];if(n===true){this._traverseToPath(e,t,s,i+1,true);return}"*"in e&&this._traverseToPath(e["*"],t,s,i+1),"**"in e&&this._traverseToPath(e["**"],t,s,i+1,true),o in e&&this._traverseToPath(e[o],t,s,i+1);}_traverseListeners(e,t,s){let i=e;t&&t.length>0&&this._traverseToPath(e,t,o=>{i=o;});let n=a((o,u,h)=>{u(h,o);for(let[l,p]of Object.entries(o))l.startsWith("__")||p&&n(p,u,[...h,l]);},"traverseNodes");n(i,s,[]);}_onListenerError(e,t,s,i){if(i instanceof Error&&(i._emitter=`${e.name||"anonymous"}:${t.type}`),c(this._options.onListenerError))try{this._options.onListenerError.call(this,i,e,t,s);}catch{}if(this._options.ignoreErrors)return i;throw i}_executeListener(e,t,s,i=false){try{if(s&&s.abortSignal&&s.abortSignal.aborted)return this._onListenerError(e,t,s,new _(e.name));let n=e.call(this.context,t,s);return i&&n&&n instanceof Promise&&(n=B(n,o=>this._onListenerError(e,t,s,o))),n}catch(n){return this._onListenerError(e,t,s,n)}}_getListenerExecutor(e){if(!e)return;let t=e.executor||this._options.executor;if(c(t))return t}_executeListeners(e,t,s,i){if(!e||e.length===0)return [];let n=e.reduce((o,u)=>o.concat(u.__listeners.filter(h=>c(i)?i(h,u):true).map((h,l)=>[h,l,u.__listeners])),[]);try{let o=this._getListenerExecutor(s);if(o){let u=o(n.map(h=>h[0]),t,s,this._executeListener.bind(this));return Array.isArray(u)?u:[u]}else return n.map(u=>this._executeListener(u[0][0],t,s,!0))}finally{for(let o=n.length-1;o>=0;o--){let u=n[o][0];u[2]++,u[1]>0&&u[1]<=u[2]&&n[o][2].splice(o,1);}}}emit(){if(arguments.length===2&&typeof arguments[0]=="string"&&arguments[1]===y.clearRetain)return this.retainedMessages.delete(arguments[0]),[];let[e,t]=b(arguments,this.options.meta);c(t.parseArgs)&&t.parseArgs(e,t);let s=e.type.split(this._delimiter);t.retain&&this.retainedMessages.set(e.type,e);let i=[],n=[];if(this._traverseToPath(this.listeners,s,o=>{n.push(o);}),c(this._options.onBeforeExecuteListener)){let o=this._options.onBeforeExecuteListener.call(this,e,t);if(Array.isArray(o))return o;if(o===false)throw new _(e.type)}return i.push(...this._executeListeners(n,e,t)),c(this._options.onAfterExecuteListener)&&this._options.onAfterExecuteListener.call(this,e,i,n),this._options.expandEmitResults&&V(i),i}getListeners(e){let t=[],s=e.split(this._delimiter);return this._traverseToPath(this.listeners,s,i=>{t.push(i);}),t[0].__listeners}async emitAsync(){return (await Promise.allSettled(this.emit.apply(this,arguments))).map(t=>t.status==="fulfilled"?t.value:t.reason)}waitFor(){let e=arguments[0],t=arguments[1];return new Promise((s,i)=>{let n,o,u=a(h=>{clearTimeout(n),o.off(),s(h);},"listener");t&&t>0&&(n=setTimeout(()=>{o&&o.off(),i(new Error("wait for event<"+e+"> is timeout"));},t)),o=this.on(e,u);})}scope(){let[e,t,s]=L(arguments,this.options.meta,this.options.context),i;return t?i=t:i=new E,i.bind(this,e,s),i}};a(P,"FastEvent");var X=P;exports.AbortError=_;exports.CancelError=x;exports.FastEvent=X;exports.FastEventDirectives=y;exports.FastEventError=m;exports.FastEventScope=E;exports.QueueOverflowError=C;exports.TimeoutError=F;exports.UnboundError=d;exports.__FastEventScope__=H;exports.__FastEvent__=G;//# sourceMappingURL=index.js.map
2
2
  //# sourceMappingURL=index.js.map