fastevent 2.4.1 → 2.5.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/executors/index.d.mts +9 -7
- package/dist/executors/index.d.ts +9 -7
- package/dist/executors/index.js +1 -1
- package/dist/executors/index.js.map +1 -1
- package/dist/executors/index.mjs +1 -1
- package/dist/executors/index.mjs.map +1 -1
- package/dist/index.d.mts +61 -20
- package/dist/index.d.ts +61 -20
- package/dist/index.global.js +2 -0
- package/dist/index.global.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/pipes/index.d.mts +9 -7
- package/dist/pipes/index.d.ts +9 -7
- package/dist/viewer/fastevent.viewer.d.ts +165 -0
- package/dist/viewer/favicon.svg +1 -0
- package/dist/viewer/icons.svg +24 -0
- package/dist/viewer/index.js +1369 -0
- package/dist/viewer/index.js.map +1 -0
- package/dist/viewer/index.mjs +3383 -0
- package/dist/viewer/index.mjs.map +1 -0
- package/package.json +14 -11
- package/dist/devTools.js +0 -3
- package/dist/devTools.js.map +0 -1
- package/dist/devTools.mjs +0 -3
- package/dist/devTools.mjs.map +0 -1
|
@@ -88,11 +88,12 @@ type FastEventListenerArgs<M = Record<string, any>> = {
|
|
|
88
88
|
type TypedFastEventListener<T extends string = string, P = any, M = any, C = any> = (this: C, message: TypedFastEventMessage<Record<T, P>, M>, args: FastEventListenerArgs<M>) => any | Promise<any>;
|
|
89
89
|
/**
|
|
90
90
|
* [
|
|
91
|
-
* 监听器函数引用,
|
|
92
|
-
* 需要执行多少次, =0代表不限
|
|
93
|
-
* 实际执行的次数(用于负载均衡时记录)
|
|
94
|
-
* 标签 用于调试一般可以标识监听器类型或任意信息
|
|
95
|
-
*
|
|
91
|
+
* 0: 监听器函数引用,
|
|
92
|
+
* 1: 需要执行多少次, =0代表不限
|
|
93
|
+
* 2: 实际执行的次数(用于负载均衡时记录)
|
|
94
|
+
* 3: 标签 用于调试一般可以标识监听器类型或任意信息
|
|
95
|
+
* 4: 标识,
|
|
96
|
+
* 5: 监听器最后一次执行结果,仅仅在debug时启用,如果结果是对象则是一个WeakRef
|
|
96
97
|
* ]
|
|
97
98
|
*/
|
|
98
99
|
type FastEventListenerMeta = [
|
|
@@ -100,10 +101,11 @@ type FastEventListenerMeta = [
|
|
|
100
101
|
number,
|
|
101
102
|
number,
|
|
102
103
|
string,
|
|
103
|
-
number
|
|
104
|
+
number,
|
|
105
|
+
any?
|
|
104
106
|
];
|
|
105
107
|
|
|
106
|
-
type FastListenerExecutor = (listeners: FastEventListenerMeta[], message: TypedFastEventMessage, args: FastEventListenerArgs, execute: (listener:
|
|
108
|
+
type FastListenerExecutor = (listeners: FastEventListenerMeta[], message: TypedFastEventMessage, args: FastEventListenerArgs, execute: (this: FastEventListenerMeta, listener: FastEventListenerMeta, message: TypedFastEventMessage, args: FastEventListenerArgs, catchErrors?: boolean) => Promise<any> | any) => Promise<any[]> | any[];
|
|
107
109
|
type FastListenerExecutorBuilder<T extends Record<string, any>> = (options?: T) => FastListenerExecutor;
|
|
108
110
|
|
|
109
111
|
/**
|
|
@@ -88,11 +88,12 @@ type FastEventListenerArgs<M = Record<string, any>> = {
|
|
|
88
88
|
type TypedFastEventListener<T extends string = string, P = any, M = any, C = any> = (this: C, message: TypedFastEventMessage<Record<T, P>, M>, args: FastEventListenerArgs<M>) => any | Promise<any>;
|
|
89
89
|
/**
|
|
90
90
|
* [
|
|
91
|
-
* 监听器函数引用,
|
|
92
|
-
* 需要执行多少次, =0代表不限
|
|
93
|
-
* 实际执行的次数(用于负载均衡时记录)
|
|
94
|
-
* 标签 用于调试一般可以标识监听器类型或任意信息
|
|
95
|
-
*
|
|
91
|
+
* 0: 监听器函数引用,
|
|
92
|
+
* 1: 需要执行多少次, =0代表不限
|
|
93
|
+
* 2: 实际执行的次数(用于负载均衡时记录)
|
|
94
|
+
* 3: 标签 用于调试一般可以标识监听器类型或任意信息
|
|
95
|
+
* 4: 标识,
|
|
96
|
+
* 5: 监听器最后一次执行结果,仅仅在debug时启用,如果结果是对象则是一个WeakRef
|
|
96
97
|
* ]
|
|
97
98
|
*/
|
|
98
99
|
type FastEventListenerMeta = [
|
|
@@ -100,10 +101,11 @@ type FastEventListenerMeta = [
|
|
|
100
101
|
number,
|
|
101
102
|
number,
|
|
102
103
|
string,
|
|
103
|
-
number
|
|
104
|
+
number,
|
|
105
|
+
any?
|
|
104
106
|
];
|
|
105
107
|
|
|
106
|
-
type FastListenerExecutor = (listeners: FastEventListenerMeta[], message: TypedFastEventMessage, args: FastEventListenerArgs, execute: (listener:
|
|
108
|
+
type FastListenerExecutor = (listeners: FastEventListenerMeta[], message: TypedFastEventMessage, args: FastEventListenerArgs, execute: (this: FastEventListenerMeta, listener: FastEventListenerMeta, message: TypedFastEventMessage, args: FastEventListenerArgs, catchErrors?: boolean) => Promise<any> | any) => Promise<any[]> | any[];
|
|
107
109
|
type FastListenerExecutorBuilder<T extends Record<string, any>> = (options?: T) => FastListenerExecutor;
|
|
108
110
|
|
|
109
111
|
/**
|
package/dist/executors/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var v=Object.defineProperty;var o=(r,c)=>v(r,"name",{value:c,configurable:true});var S=o(()=>(r,c,t,a)=>(r.forEach(e=>e[2]--),r[0][2]++,[a.call(r[0],r[0],c,t)]),"first");var j=o(()=>(r,c,t,a)=>(r.forEach(e=>e[2]--),r[r.length-1][2]++,[a.call(r[r.length-1],r[r.length-1],c,t)]),"last");var M=o(()=>(r,c,t,a)=>{let e,n;return (!t||t&&!t.abortSignal)&&(n=new AbortController,t||(t={}),t.abortSignal=n.signal),[Promise.race(r.map(f=>(f[2]--,Promise.resolve(a.call(f,f,c,t)).then(m=>(e||(e=f,f[2]++),n?.abort(),m)))))]},"race");var A=o(()=>(r,c,t,a)=>{let e=Math.floor(Math.random()*r.length);return r.forEach(n=>n[2]--),r[e][2]++,[a.call(r[e],r[e],c,t)]},"random");var z=o(()=>(r,c,t,a)=>{let e,n=0;return r.forEach((u,f)=>{u[2]--,(e===void 0||e>u[2])&&(e=u[2],n=f);}),r[n][2]++,[a.call(r[n],r[n],c,t)]},"balance");function i(r){return r&&typeof r=="function"}o(i,"isFunction");function y(r){return r&&typeof r=="string"}o(y,"isString");var g=o(r=>{let{reverse:c,onNext:t,onReturns:a,onError:e}=Object.assign({reverse:false,onError:o(()=>{},"onError"),onNext:o(()=>true,"onNext"),onReturns:o((n,u)=>u,"onReturns")},r);return async(n,u,f,m)=>{let l,x,k=0;n.forEach(p=>p[2]--);for(let p=0;p<n.length;p++){let b=n[c?n.length-1-p:p],d=b;try{if(i(t)&&t(++k,x,u,f,l)===!1)break;x=await m.call(d,d,u,f,!1),i(a)?l=a(l,x):l=x,b[2]++;}catch(E){try{let h=y(e)?e:i(e)&&e(E,u,f);if(h==="skip")continue;if(h==="error"){l=E;break}else if(h==="abort")break}catch{}}}return l}},"series");var V=o(r=>g(Object.assign({},r,{onError:"abort",onNext:o((c,t,a)=>{a.payload=t;},"onNext")})),"waterfall");var Y=o(()=>(r,c,t,a)=>r.map((e,n)=>a.call(r[n],e,c,t,true)),"parallel");exports.balance=z;exports.first=S;exports.last=j;exports.parallel=Y;exports.race=M;exports.random=A;exports.series=g;exports.waterfall=V;//# sourceMappingURL=index.js.map
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/executors/first.ts","../../src/executors/last.ts","../../src/executors/race.ts","../../src/executors/random.ts","../../src/executors/balance.ts","../../src/utils/isFunction.ts","../../src/utils/isString.ts","../../src/executors/series.ts","../../src/executors/waterfall.ts","../../src/executors/parallel.ts"],"names":["first","__name","listeners","message","args","execute","forEach","listener","last","length","race","winner","abortController","abortSignal","AbortController","signal","Promise","map","resolve","then","result","abort","random","index","Math","floor","balance","count","i","undefined","isFunction","fn","isString","str","series","options","reverse","onNext","onReturns","onError","Object","assign","_","cur","results","stepResult","item","e","behavior","waterfall","previous","payload","parallel"],"mappings":"8FAWaA,IAAAA,CAAAA,CAAQC,CAAA,CAAA,IACV,CAACC,CAAAA,CAAWC,EAASC,CAAMC,CAAAA,CAAAA,IAC9BH,CAAUI,CAAAA,OAAAA,CAAQC,CAAYA,EAAAA,CAAAA,CAAS,CAAA,CAAE,EAAA,CAAA,CACzCL,CAAU,CAAA,CAAA,CAAG,CAAA,CAAA,CACN,EAAA,CAAA,CACHG,CAAQH,CAAAA,CAAAA,CAAU,CAAA,CAAA,CAAG,CAAA,CAAA,CAAIC,EAASC,CAAAA,CAAAA,CAAAA,CAAAA,CALzB,OCDd,EAAA,IAAMI,CAAOP,CAAAA,CAAAA,CAAA,IACT,CAACC,CAAWC,CAAAA,CAAAA,CAASC,CAAMC,CAAAA,CAAAA,IAC9BH,CAAUI,CAAAA,OAAAA,CAAQC,GAAYA,CAAS,CAAA,CAAA,CAAE,EAAA,CAAA,CACzCL,CAAUA,CAAAA,CAAAA,CAAUO,MAAS,CAAA,CAAA,CAAG,CAAA,CAAA,CACzB,EAAA,CAAA,CACHJ,CAAQH,CAAAA,CAAAA,CAAUA,EAAUO,MAAS,CAAA,CAAA,CAAG,CAAA,CAAA,CAAIN,CAAAA,CAAAA,CAASC,CAAAA,CAAAA,CAAAA,CAAAA,CAL7C,MCQb,EAAA,IAAMM,CAAOT,CAAAA,CAAAA,CAAA,IACT,CAACC,EAAWC,CAASC,CAAAA,CAAAA,CAAMC,CAAAA,GAAAA,CAC9B,IAAIM,CAAAA,CACAC,CACJ,CAAA,OAAA,CAAI,CAACR,CAAAA,EAASA,CAAQ,EAAA,CAACA,CAAKS,CAAAA,WAAAA,IACxBD,EAAkB,IAAIE,eAAAA,CACjBV,CAAMA,GAAAA,CAAAA,CAAO,EAAC,CAAA,CACnBA,CAAKS,CAAAA,WAAAA,CAAcD,CAAgBG,CAAAA,MAAAA,CAAAA,CAehC,CAb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IAAAA,EAAAA,CAAYhD,CAACkC,CAAAA,CAAAA,EACfD,CACHM,CAAAA,MAAAA,CAAOC,OAAO,EAAC,CAAGN,CAAS,CAAA,CAEvBI,OAAS,CAAA,OAAA,CAETF,MAAQpC,CAAAA,CAAAA,CAAA,CAACsB,CAAAA,CAAe2B,CAAe/C,CAAAA,CAAAA,GAAAA,CACnCA,CAAAA,CAAQgD,QAAUD,EACtB,CAAA,CAFQ,QAGZ,CAAA,CAAA,CAAA,CAAA,CATiB,WCflB,EAAA,IAAME,EAAWnD,CAAAA,CAAAA,CAAA,IACb,CAACC,CAAWC,CAAAA,CAAAA,CAASC,EAAMC,CACvBH,GAAAA,CAAAA,CAAUe,GAAIV,CAAAA,CAAAA,EAAYF,CAAQE,CAAAA,CAAAA,CAAS,CAAA,CAAA,CAAIJ,CAASC,CAAAA,CAAAA,CAAM,IAAA,CAAA,CAFrD,CAAA,UAAA","file":"index.js","sourcesContent":["import { FastListenerExecutor } from \"./types\"\n\n/**\n * 执行第一个监听器的执行器函数\n * \n * @param listeners - 监听器数组,每个元素是一个包含监听器函数的元组\n * @param message - 要传递给监听器的消息对象\n * @param args - 要传递给监听器的额外参数\n * @param execute - 执行监听器的函数\n * @returns 返回一个数组,包含第一个监听器的执行结果\n */\nexport const first = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n listeners.forEach(listener => listener[2]--)\n listeners[0][2]++\n return [\n execute(listeners[0][0], message, args)\n ]\n }\n}","import { FastListenerExecutor } from \"./types\"\n\n/**\n * 执行监听器列表中的最后一个监听器\n * @param listeners - 监听器数组\n * @param message - 事件消息\n * @param args - 事件参数\n * @param execute - 执行器函数\n * @returns 返回包含最后一个监听器执行结果的数组\n */\nexport const last = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n listeners.forEach(listener => listener[2]--)\n listeners[listeners.length - 1][2]++\n return [\n execute(listeners[listeners.length - 1][0], message, args)\n ]\n }\n}","import { FastEventListenerMeta } from \"../types/FastEventListeners\";\nimport { FastListenerExecutor } from \"./types\";\n\n/**\n * 竞态执行器 - 同时执行多个监听器,只返回最快完成的结果\n *\n * @param listeners - 监听器元数据列表\n * @param message - 要处理的消息\n * @param args - 执行参数\n * @param execute - 执行函数\n * @returns 包含最快完成监听器结果的数组\n *\n * @description\n * - 只有第一个完成的监听器结果会被返回\n * - 其他未完成的监听器会被中止\n * - 如果没有提供中止信号,会自动创建一个\n * - 胜出的监听器计数会被恢复\n */\nexport const race = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n let winner: FastEventListenerMeta | undefined;\n let abortController: AbortController | undefined;\n if (!args || (args && !args.abortSignal)) {\n abortController = new AbortController();\n if (!args) args = {};\n args.abortSignal = abortController.signal;\n }\n const result = Promise.race(\n listeners.map((listener) => {\n listener[2]--;\n return Promise.resolve(execute(listener[0], message, args)).then((result: any) => {\n if (!winner) {\n winner = listener;\n listener[2]++;\n }\n abortController?.abort();\n return result;\n });\n }),\n );\n return [result];\n };\n};\n","import { FastListenerExecutor } from \"./types\"\n\n/**\n * 随机执行器 - 从监听器列表中随机选择一个监听器执行\n * \n * @param listeners - 监听器列表,每个元素为 [监听器函数, 优先级, 执行次数] 的元组\n * @param message - 要处理的消息对象\n * @param args - 传递给监听器的额外参数\n * @param execute - 执行监听器的函数\n * @returns 返回包含执行结果的数组\n * \n * @remarks\n * - 随机选择一个监听器执行\n * - 所有监听器的执行次数计数减1\n * - 被选中执行的监听器执行次数加1\n */\nexport const random = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n const index = Math.floor(Math.random() * listeners.length)\n listeners.forEach(listener => listener[2]--)\n listeners[index][2]++\n return [\n execute(listeners[index][0], message, args)\n ]\n }\n}","import { FastListenerExecutor } from \"./types\"\n\n/**\n * 负载均衡执行器,用于在多个监听器中选择执行次数最少的进行调用\n * @param listeners 监听器列表\n * @param message 消息对象\n * @param args 参数列表\n * @param execute 执行函数\n * @returns 返回包含单个执行结果的数组\n * \n * 执行策略:\n * 1. 遍历所有监听器,找出执行次数最少的监听器\n * 2. 由于监听器执行后会自动+1,因此先对所有监听器执行次数-1,以抵消后续的+1\n * 3. 只执行选中的监听器,其他监听器不执行\n */\nexport const balance = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n // 找出listeners里面所有执行器的执行次数最少的项\n let count: number\n let index: number = 0\n listeners.forEach((listener, i) => {\n // 为什么所有监听器的执行次数均减1?\n // 因为监听器执行完毕后会自动+1,但是在balance执行器中,只有一个会监听器会执行,因此在此先减一用来抵消后续的+1\n listener[2]--\n if (count === undefined || count > listener[2]) {\n count = listener[2]\n index = i\n }\n })\n listeners[index][2]++\n return [execute(listeners[index][0], message, args)]\n }\n}","export function isFunction(fn: any): fn is Function {\n return fn && typeof (fn) == \"function\"\n}","export function isString(str: any): str is string {\n return str && typeof (str) === \"string\"\n}","import { TypedFastEventMessage } from \"../types/FastEventMessages\";\nimport { TypedFastEventListener } from \"../types/FastEventListeners\";\nimport { FastEventListenerArgs } from \"../types/FastEvents\";\nimport { isString } from \"../utils\";\nimport { isFunction } from \"../utils/isFunction\";\nimport { FastListenerExecutor } from \"./types\";\n\nexport type SeriesExecutorOptions = {\n reverse?: boolean; // 反向执行监听器\n /**\n * 控制监听器如何返回结果\n *\n * 提供一个reduce函数对所有监听器返回结果进行reduce操作\n * series({\n * onReturns: (result, cur)=>{\n * if(!result) result = []\n * return result.push(cur)\n * }\n * })\n */\n onReturns?: (results: any, cur: any) => any;\n // 当调用下一个监听器前执行,返回false或触发错误均不再执行后续的监听器\n // 可以在此修改message\n onNext?: (\n index: number,\n previous: any,\n message: TypedFastEventMessage,\n args: FastEventListenerArgs,\n results: any,\n ) => boolean;\n // 当执行监听器出错时的回调,返回false中止后续执行\n onError?:\n | \"skip\"\n | \"abort\"\n | \"error\"\n | ((\n e: any,\n message: TypedFastEventMessage,\n args: FastEventListenerArgs,\n ) => void | \"skip\" | \"abort\" | \"error\");\n};\n\nexport const series = (options?: SeriesExecutorOptions): FastListenerExecutor => {\n const { reverse, onNext, onReturns, onError } = Object.assign(\n {\n reverse: false,\n onError: () => {},\n onNext: () => true,\n onReturns: (_: any, cur: any) => cur,\n },\n options,\n ) as SeriesExecutorOptions;\n return async (listeners, message, args, execute) => {\n let results: any = undefined;\n let stepResult: any = undefined;\n let index: number = 0;\n // 全部执行次数-1\n listeners.forEach((listener) => listener[2]--);\n for (let i = 0; i < listeners.length; i++) {\n const item = listeners[reverse ? listeners.length - 1 - i : i];\n const listener = item[0] as TypedFastEventListener<any, any, any>;\n try {\n if (\n isFunction(onNext) &&\n onNext(++index, stepResult, message, args, results) === false\n ) {\n break;\n }\n stepResult = await execute(listener, message, args, false);\n if (isFunction(onReturns)) {\n results = onReturns(results, stepResult);\n } else {\n results = stepResult;\n }\n // 实际执行次数+1\n item[2]++;\n } catch (e: any) {\n try {\n const behavior = isString(onError)\n ? onError\n : isFunction(onError) && onError!(e, message, args);\n if (behavior === \"skip\") {\n continue;\n } else if (behavior === \"error\") {\n results = e;\n break;\n } else if (behavior === \"abort\") {\n break;\n }\n } catch {}\n }\n }\n return results;\n };\n};\n","import { TypedFastEventMessage } from \"../types/FastEventMessages\";\nimport { series, SeriesExecutorOptions } from \"./series\";\nimport { FastListenerExecutor } from \"./types\";\n\nexport type WaterfallExecutorOptions = Omit<\n SeriesExecutorOptions,\n \"onError\" | \"onReturns\" | \"onStep\"\n>;\n\n/**\n * 创建一个瀑布流执行器,用于按顺序执行监听器,并将前一个监听器的结果传递给下一个监听器\n * 如果出错就不再执行后续的监听器\n *\n * @param options - 执行器配置选项\n * @returns 返回一个 FastListener 执行器实例\n *\n * @remarks\n * - 当任一监听器执行出错时,会中断后续监听器的执行\n * - 每个监听器的执行结果会作为下一个监听器的 payload 参数\n */\nexport const waterfall = (options?: WaterfallExecutorOptions): FastListenerExecutor => {\n return series(\n Object.assign({}, options, {\n // 出错时不再执行后续的监听器\n onError: \"abort\",\n // 将结果作为payload传给下一个监听器\n onNext: (index: number, previous: any, message: TypedFastEventMessage) => {\n message.payload = previous;\n },\n }) as unknown as SeriesExecutorOptions,\n );\n};\n","import { FastListenerExecutor } from \"./types\"\n\n/**\n * \n */\nexport const parallel = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n return listeners.map(listener => execute(listener[0], message, args, true))\n }\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/executors/first.ts","../../src/executors/last.ts","../../src/executors/race.ts","../../src/executors/random.ts","../../src/executors/balance.ts","../../src/utils/isFunction.ts","../../src/utils/isString.ts","../../src/executors/series.ts","../../src/executors/waterfall.ts","../../src/executors/parallel.ts"],"names":["first","__name","listeners","message","args","execute","forEach","listener","call","last","length","race","winner","abortController","abortSignal","AbortController","signal","Promise","map","resolve","then","result","abort","random","index","Math","floor","balance","count","i","undefined","isFunction","fn","isString","str","series","options","reverse","onNext","onReturns","onError","Object","assign","_","cur","results","stepResult","item","e","behavior","waterfall","previous","payload","parallel"],"mappings":"8FAWaA,IAAAA,CAAAA,CAAQC,CAAA,CAAA,IACV,CAACC,CAAAA,CAAWC,CAASC,CAAAA,CAAAA,CAAMC,CAC9BH,IAAAA,CAAAA,CAAUI,OAASC,CAAAA,CAAAA,EAAaA,CAAS,CAAA,CAAA,GAAE,CAC3CL,CAAAA,CAAAA,CAAU,CAAA,CAAA,CAAG,CAAA,CAAA,EAAA,CACN,CAACG,CAAAA,CAAQG,IAAKN,CAAAA,CAAAA,CAAU,CAAA,CAAA,CAAIA,CAAU,CAAA,CAAA,EAAIC,CAASC,CAAAA,CAAAA,CAJ7C,CAAA,CAAA,CAAA,OAAA,ECDRK,IAAAA,CAAAA,CAAOR,CAAA,CAAA,IACT,CAACC,CAAAA,CAAWC,CAASC,CAAAA,CAAAA,CAAMC,CAC9BH,IAAAA,CAAAA,CAAUI,OAASC,CAAAA,CAAAA,EAAaA,CAAS,CAAA,CAAA,CAAE,EAAA,CAAA,CAC3CL,CAAUA,CAAAA,CAAAA,CAAUQ,MAAS,CAAA,CAAA,CAAG,CAAA,CAAA,CACzB,EAAA,CAA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B,CAAAA,CAAAA,GAC5BxB,CAAQG,CAAAA,IAAAA,CAAKN,CAAU2B,CAAAA,CAAAA,CAAItB,CAAAA,CAAAA,CAAUJ,CAASC,CAAAA,CAAAA,CAAM,IAAA,CAAA,CAHxC,CAAA,UAAA","file":"index.js","sourcesContent":["import { FastListenerExecutor } from \"./types\";\n\n/**\n * 执行第一个监听器的执行器函数\n *\n * @param listeners - 监听器数组,每个元素是一个包含监听器函数的元组\n * @param message - 要传递给监听器的消息对象\n * @param args - 要传递给监听器的额外参数\n * @param execute - 执行监听器的函数\n * @returns 返回一个数组,包含第一个监听器的执行结果\n */\nexport const first = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n listeners.forEach((listener) => listener[2]--);\n listeners[0][2]++;\n return [execute.call(listeners[0], listeners[0], message, args)];\n };\n};\n","import { FastListenerExecutor } from \"./types\";\n\n/**\n * 执行监听器列表中的最后一个监听器\n * @param listeners - 监听器数组\n * @param message - 事件消息\n * @param args - 事件参数\n * @param execute - 执行器函数\n * @returns 返回包含最后一个监听器执行结果的数组\n */\nexport const last = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n listeners.forEach((listener) => listener[2]--);\n listeners[listeners.length - 1][2]++;\n return [\n execute.call(\n listeners[listeners.length - 1],\n listeners[listeners.length - 1],\n message,\n args,\n ),\n ];\n };\n};\n","import { FastEventListenerMeta } from \"../types/FastEventListeners\";\nimport { FastListenerExecutor } from \"./types\";\n\n/**\n * 竞态执行器 - 同时执行多个监听器,只返回最快完成的结果\n *\n * @param listeners - 监听器元数据列表\n * @param message - 要处理的消息\n * @param args - 执行参数\n * @param execute - 执行函数\n * @returns 包含最快完成监听器结果的数组\n *\n * @description\n * - 只有第一个完成的监听器结果会被返回\n * - 其他未完成的监听器会被中止\n * - 如果没有提供中止信号,会自动创建一个\n * - 胜出的监听器计数会被恢复\n */\nexport const race = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n let winner: FastEventListenerMeta | undefined;\n let abortController: AbortController | undefined;\n if (!args || (args && !args.abortSignal)) {\n abortController = new AbortController();\n if (!args) args = {};\n args.abortSignal = abortController.signal;\n }\n const result = Promise.race(\n listeners.map((listener) => {\n listener[2]--;\n return Promise.resolve(execute.call(listener, listener, message, args)).then(\n (result: any) => {\n if (!winner) {\n winner = listener;\n listener[2]++;\n }\n abortController?.abort();\n return result;\n },\n );\n }),\n );\n return [result];\n };\n};\n","import { FastListenerExecutor } from \"./types\";\n\n/**\n * 随机执行器 - 从监听器列表中随机选择一个监听器执行\n *\n * @param listeners - 监听器列表,每个元素为 [监听器函数, 优先级, 执行次数] 的元组\n * @param message - 要处理的消息对象\n * @param args - 传递给监听器的额外参数\n * @param execute - 执行监听器的函数\n * @returns 返回包含执行结果的数组\n *\n * @remarks\n * - 随机选择一个监听器执行\n * - 所有监听器的执行次数计数减1\n * - 被选中执行的监听器执行次数加1\n */\nexport const random = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n const index = Math.floor(Math.random() * listeners.length);\n listeners.forEach((listener) => listener[2]--);\n listeners[index][2]++;\n return [execute.call(listeners[index], listeners[index], message, args)];\n };\n};\n","import { FastListenerExecutor } from \"./types\";\n\n/**\n * 负载均衡执行器,用于在多个监听器中选择执行次数最少的进行调用\n * @param listeners 监听器列表\n * @param message 消息对象\n * @param args 参数列表\n * @param execute 执行函数\n * @returns 返回包含单个执行结果的数组\n *\n * 执行策略:\n * 1. 遍历所有监听器,找出执行次数最少的监听器\n * 2. 由于监听器执行后会自动+1,因此先对所有监听器执行次数-1,以抵消后续的+1\n * 3. 只执行选中的监听器,其他监听器不执行\n */\nexport const balance = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n // 找出listeners里面所有执行器的执行次数最少的项\n let count: number;\n let index: number = 0;\n listeners.forEach((listener, i) => {\n // 为什么所有监听器的执行次数均减1?\n // 因为监听器执行完毕后会自动+1,但是在balance执行器中,只有一个会监听器会执行,因此在此先减一用来抵消后续的+1\n listener[2]--;\n if (count === undefined || count > listener[2]) {\n count = listener[2];\n index = i;\n }\n });\n listeners[index][2]++;\n return [execute.call(listeners[index], listeners[index], message, args)];\n };\n};\n","export function isFunction(fn: any): fn is Function {\n return fn && typeof (fn) == \"function\"\n}","export function isString(str: any): str is string {\n return str && typeof (str) === \"string\"\n}","import { TypedFastEventMessage } from \"../types/FastEventMessages\";\nimport { FastEventListenerMeta, TypedFastEventListener } from \"../types/FastEventListeners\";\nimport { FastEventListenerArgs } from \"../types/FastEvents\";\nimport { isString } from \"../utils\";\nimport { isFunction } from \"../utils/isFunction\";\nimport { FastListenerExecutor } from \"./types\";\n\nexport type SeriesExecutorOptions = {\n reverse?: boolean; // 反向执行监听器\n /**\n * 控制监听器如何返回结果\n *\n * 提供一个reduce函数对所有监听器返回结果进行reduce操作\n * series({\n * onReturns: (result, cur)=>{\n * if(!result) result = []\n * return result.push(cur)\n * }\n * })\n */\n onReturns?: (results: any, cur: any) => any;\n // 当调用下一个监听器前执行,返回false或触发错误均不再执行后续的监听器\n // 可以在此修改message\n onNext?: (\n index: number,\n previous: any,\n message: TypedFastEventMessage,\n args: FastEventListenerArgs,\n results: any,\n ) => boolean;\n // 当执行监听器出错时的回调,返回false中止后续执行\n onError?:\n | \"skip\"\n | \"abort\"\n | \"error\"\n | ((\n e: any,\n message: TypedFastEventMessage,\n args: FastEventListenerArgs,\n ) => void | \"skip\" | \"abort\" | \"error\");\n};\n\nexport const series = (options?: SeriesExecutorOptions): FastListenerExecutor => {\n const { reverse, onNext, onReturns, onError } = Object.assign(\n {\n reverse: false,\n onError: () => {},\n onNext: () => true,\n onReturns: (_: any, cur: any) => cur,\n },\n options,\n ) as SeriesExecutorOptions;\n return async (listeners, message, args, execute) => {\n let results: any = undefined;\n let stepResult: any = undefined;\n let index: number = 0;\n // 全部执行次数-1\n listeners.forEach((listener) => listener[2]--);\n for (let i = 0; i < listeners.length; i++) {\n const item = listeners[reverse ? listeners.length - 1 - i : i];\n const listener = item as unknown as FastEventListenerMeta;\n try {\n if (\n isFunction(onNext) &&\n onNext(++index, stepResult, message, args, results) === false\n ) {\n break;\n }\n stepResult = await execute.call(listener, listener, message, args, false);\n if (isFunction(onReturns)) {\n results = onReturns(results, stepResult);\n } else {\n results = stepResult;\n }\n // 实际执行次数+1\n item[2]++;\n } catch (e: any) {\n try {\n const behavior = isString(onError)\n ? onError\n : isFunction(onError) && onError!(e, message, args);\n if (behavior === \"skip\") {\n continue;\n } else if (behavior === \"error\") {\n results = e;\n break;\n } else if (behavior === \"abort\") {\n break;\n }\n } catch {}\n }\n }\n return results;\n };\n};\n","import { TypedFastEventMessage } from \"../types/FastEventMessages\";\nimport { series, SeriesExecutorOptions } from \"./series\";\nimport { FastListenerExecutor } from \"./types\";\n\nexport type WaterfallExecutorOptions = Omit<\n SeriesExecutorOptions,\n \"onError\" | \"onReturns\" | \"onStep\"\n>;\n\n/**\n * 创建一个瀑布流执行器,用于按顺序执行监听器,并将前一个监听器的结果传递给下一个监听器\n * 如果出错就不再执行后续的监听器\n *\n * @param options - 执行器配置选项\n * @returns 返回一个 FastListener 执行器实例\n *\n * @remarks\n * - 当任一监听器执行出错时,会中断后续监听器的执行\n * - 每个监听器的执行结果会作为下一个监听器的 payload 参数\n */\nexport const waterfall = (options?: WaterfallExecutorOptions): FastListenerExecutor => {\n return series(\n Object.assign({}, options, {\n // 出错时不再执行后续的监听器\n onError: \"abort\",\n // 将结果作为payload传给下一个监听器\n onNext: (index: number, previous: any, message: TypedFastEventMessage) => {\n message.payload = previous;\n },\n }) as unknown as SeriesExecutorOptions,\n );\n};\n","import { FastListenerExecutor } from \"./types\";\n\n/**\n *\n */\nexport const parallel = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n return listeners.map((listener, i) =>\n execute.call(listeners[i], listener, message, args, true),\n );\n };\n};\n"]}
|
package/dist/executors/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var
|
|
1
|
+
var v=Object.defineProperty;var o=(r,c)=>v(r,"name",{value:c,configurable:true});var S=o(()=>(r,c,t,a)=>(r.forEach(e=>e[2]--),r[0][2]++,[a.call(r[0],r[0],c,t)]),"first");var j=o(()=>(r,c,t,a)=>(r.forEach(e=>e[2]--),r[r.length-1][2]++,[a.call(r[r.length-1],r[r.length-1],c,t)]),"last");var M=o(()=>(r,c,t,a)=>{let e,n;return (!t||t&&!t.abortSignal)&&(n=new AbortController,t||(t={}),t.abortSignal=n.signal),[Promise.race(r.map(f=>(f[2]--,Promise.resolve(a.call(f,f,c,t)).then(m=>(e||(e=f,f[2]++),n?.abort(),m)))))]},"race");var A=o(()=>(r,c,t,a)=>{let e=Math.floor(Math.random()*r.length);return r.forEach(n=>n[2]--),r[e][2]++,[a.call(r[e],r[e],c,t)]},"random");var z=o(()=>(r,c,t,a)=>{let e,n=0;return r.forEach((u,f)=>{u[2]--,(e===void 0||e>u[2])&&(e=u[2],n=f);}),r[n][2]++,[a.call(r[n],r[n],c,t)]},"balance");function i(r){return r&&typeof r=="function"}o(i,"isFunction");function y(r){return r&&typeof r=="string"}o(y,"isString");var g=o(r=>{let{reverse:c,onNext:t,onReturns:a,onError:e}=Object.assign({reverse:false,onError:o(()=>{},"onError"),onNext:o(()=>true,"onNext"),onReturns:o((n,u)=>u,"onReturns")},r);return async(n,u,f,m)=>{let l,x,k=0;n.forEach(p=>p[2]--);for(let p=0;p<n.length;p++){let b=n[c?n.length-1-p:p],d=b;try{if(i(t)&&t(++k,x,u,f,l)===!1)break;x=await m.call(d,d,u,f,!1),i(a)?l=a(l,x):l=x,b[2]++;}catch(E){try{let h=y(e)?e:i(e)&&e(E,u,f);if(h==="skip")continue;if(h==="error"){l=E;break}else if(h==="abort")break}catch{}}}return l}},"series");var V=o(r=>g(Object.assign({},r,{onError:"abort",onNext:o((c,t,a)=>{a.payload=t;},"onNext")})),"waterfall");var Y=o(()=>(r,c,t,a)=>r.map((e,n)=>a.call(r[n],e,c,t,true)),"parallel");export{z as balance,S as first,j as last,Y as parallel,M as race,A as random,g as series,V as waterfall};//# sourceMappingURL=index.mjs.map
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/executors/first.ts","../../src/executors/last.ts","../../src/executors/race.ts","../../src/executors/random.ts","../../src/executors/balance.ts","../../src/utils/isFunction.ts","../../src/utils/isString.ts","../../src/executors/series.ts","../../src/executors/waterfall.ts","../../src/executors/parallel.ts"],"names":["first","__name","listeners","message","args","execute","forEach","listener","last","length","race","winner","abortController","abortSignal","AbortController","signal","Promise","map","resolve","then","result","abort","random","index","Math","floor","balance","count","i","undefined","isFunction","fn","isString","str","series","options","reverse","onNext","onReturns","onError","Object","assign","_","cur","results","stepResult","item","e","behavior","waterfall","previous","payload","parallel"],"mappings":"iFAWaA,IAAAA,CAAAA,CAAQC,CAAA,CAAA,IACV,CAACC,CAAAA,CAAWC,EAASC,CAAMC,CAAAA,CAAAA,IAC9BH,CAAUI,CAAAA,OAAAA,CAAQC,CAAYA,EAAAA,CAAAA,CAAS,CAAA,CAAE,EAAA,CAAA,CACzCL,CAAU,CAAA,CAAA,CAAG,CAAA,CAAA,CACN,EAAA,CAAA,CACHG,CAAQH,CAAAA,CAAAA,CAAU,CAAA,CAAA,CAAG,CAAA,CAAA,CAAIC,EAASC,CAAAA,CAAAA,CAAAA,CAAAA,CALzB,OCDd,EAAA,IAAMI,CAAOP,CAAAA,CAAAA,CAAA,IACT,CAACC,CAAWC,CAAAA,CAAAA,CAASC,CAAMC,CAAAA,CAAAA,IAC9BH,CAAUI,CAAAA,OAAAA,CAAQC,GAAYA,CAAS,CAAA,CAAA,CAAE,EAAA,CAAA,CACzCL,CAAUA,CAAAA,CAAAA,CAAUO,MAAS,CAAA,CAAA,CAAG,CAAA,CAAA,CACzB,EAAA,CAAA,CACHJ,CAAQH,CAAAA,CAAAA,CAAUA,EAAUO,MAAS,CAAA,CAAA,CAAG,CAAA,CAAA,CAAIN,CAAAA,CAAAA,CAASC,CAAAA,CAAAA,CAAAA,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,CAAAA,CAAAA,CAASO,CAAAA,CAAAA,CACpBA,CACAT,CAAAA,CAAAA,CAAWS,CAAAA,CAAAA,EAAYA,CAASQ,CAAAA,CAAAA,CAAG5C,CAASC,CAAAA,CAAAA,CAClD,CAAA,GAAI4C,IAAa,MACb,CAAA,SACG,GAAIA,CAAAA,GAAa,OAAS,CAAA,CAC7BJ,CAAUG,CAAAA,CAAAA,CACV,KACJ,CAAA,KAAA,GAAWC,CAAa,GAAA,OAAA,CACpB,KAER,CAAA,KAAQ,EACZ,CACJ,CACA,OAAOJ,CACX,CACJ,CApDsB,CAAA,QAAA,ECtBTK,IAAAA,EAAAA,CAAYhD,CAACkC,CAAAA,CAAAA,EACfD,CACHM,CAAAA,MAAAA,CAAOC,OAAO,EAAC,CAAGN,CAAS,CAAA,CAEvBI,OAAS,CAAA,OAAA,CAETF,MAAQpC,CAAAA,CAAAA,CAAA,CAACsB,CAAAA,CAAe2B,CAAe/C,CAAAA,CAAAA,GAAAA,CACnCA,CAAAA,CAAQgD,QAAUD,EACtB,CAAA,CAFQ,QAGZ,CAAA,CAAA,CAAA,CAAA,CATiB,WCflB,EAAA,IAAME,EAAWnD,CAAAA,CAAAA,CAAA,IACb,CAACC,CAAWC,CAAAA,CAAAA,CAASC,EAAMC,CACvBH,GAAAA,CAAAA,CAAUe,GAAIV,CAAAA,CAAAA,EAAYF,CAAQE,CAAAA,CAAAA,CAAS,CAAA,CAAA,CAAIJ,CAASC,CAAAA,CAAAA,CAAM,IAAA,CAAA,CAFrD,CAAA,UAAA","file":"index.mjs","sourcesContent":["import { FastListenerExecutor } from \"./types\"\n\n/**\n * 执行第一个监听器的执行器函数\n * \n * @param listeners - 监听器数组,每个元素是一个包含监听器函数的元组\n * @param message - 要传递给监听器的消息对象\n * @param args - 要传递给监听器的额外参数\n * @param execute - 执行监听器的函数\n * @returns 返回一个数组,包含第一个监听器的执行结果\n */\nexport const first = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n listeners.forEach(listener => listener[2]--)\n listeners[0][2]++\n return [\n execute(listeners[0][0], message, args)\n ]\n }\n}","import { FastListenerExecutor } from \"./types\"\n\n/**\n * 执行监听器列表中的最后一个监听器\n * @param listeners - 监听器数组\n * @param message - 事件消息\n * @param args - 事件参数\n * @param execute - 执行器函数\n * @returns 返回包含最后一个监听器执行结果的数组\n */\nexport const last = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n listeners.forEach(listener => listener[2]--)\n listeners[listeners.length - 1][2]++\n return [\n execute(listeners[listeners.length - 1][0], message, args)\n ]\n }\n}","import { FastEventListenerMeta } from \"../types/FastEventListeners\";\nimport { FastListenerExecutor } from \"./types\";\n\n/**\n * 竞态执行器 - 同时执行多个监听器,只返回最快完成的结果\n *\n * @param listeners - 监听器元数据列表\n * @param message - 要处理的消息\n * @param args - 执行参数\n * @param execute - 执行函数\n * @returns 包含最快完成监听器结果的数组\n *\n * @description\n * - 只有第一个完成的监听器结果会被返回\n * - 其他未完成的监听器会被中止\n * - 如果没有提供中止信号,会自动创建一个\n * - 胜出的监听器计数会被恢复\n */\nexport const race = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n let winner: FastEventListenerMeta | undefined;\n let abortController: AbortController | undefined;\n if (!args || (args && !args.abortSignal)) {\n abortController = new AbortController();\n if (!args) args = {};\n args.abortSignal = abortController.signal;\n }\n const result = Promise.race(\n listeners.map((listener) => {\n listener[2]--;\n return Promise.resolve(execute(listener[0], message, args)).then((result: any) => {\n if (!winner) {\n winner = listener;\n listener[2]++;\n }\n abortController?.abort();\n return result;\n });\n }),\n );\n return [result];\n };\n};\n","import { FastListenerExecutor } from \"./types\"\n\n/**\n * 随机执行器 - 从监听器列表中随机选择一个监听器执行\n * \n * @param listeners - 监听器列表,每个元素为 [监听器函数, 优先级, 执行次数] 的元组\n * @param message - 要处理的消息对象\n * @param args - 传递给监听器的额外参数\n * @param execute - 执行监听器的函数\n * @returns 返回包含执行结果的数组\n * \n * @remarks\n * - 随机选择一个监听器执行\n * - 所有监听器的执行次数计数减1\n * - 被选中执行的监听器执行次数加1\n */\nexport const random = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n const index = Math.floor(Math.random() * listeners.length)\n listeners.forEach(listener => listener[2]--)\n listeners[index][2]++\n return [\n execute(listeners[index][0], message, args)\n ]\n }\n}","import { FastListenerExecutor } from \"./types\"\n\n/**\n * 负载均衡执行器,用于在多个监听器中选择执行次数最少的进行调用\n * @param listeners 监听器列表\n * @param message 消息对象\n * @param args 参数列表\n * @param execute 执行函数\n * @returns 返回包含单个执行结果的数组\n * \n * 执行策略:\n * 1. 遍历所有监听器,找出执行次数最少的监听器\n * 2. 由于监听器执行后会自动+1,因此先对所有监听器执行次数-1,以抵消后续的+1\n * 3. 只执行选中的监听器,其他监听器不执行\n */\nexport const balance = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n // 找出listeners里面所有执行器的执行次数最少的项\n let count: number\n let index: number = 0\n listeners.forEach((listener, i) => {\n // 为什么所有监听器的执行次数均减1?\n // 因为监听器执行完毕后会自动+1,但是在balance执行器中,只有一个会监听器会执行,因此在此先减一用来抵消后续的+1\n listener[2]--\n if (count === undefined || count > listener[2]) {\n count = listener[2]\n index = i\n }\n })\n listeners[index][2]++\n return [execute(listeners[index][0], message, args)]\n }\n}","export function isFunction(fn: any): fn is Function {\n return fn && typeof (fn) == \"function\"\n}","export function isString(str: any): str is string {\n return str && typeof (str) === \"string\"\n}","import { TypedFastEventMessage } from \"../types/FastEventMessages\";\nimport { TypedFastEventListener } from \"../types/FastEventListeners\";\nimport { FastEventListenerArgs } from \"../types/FastEvents\";\nimport { isString } from \"../utils\";\nimport { isFunction } from \"../utils/isFunction\";\nimport { FastListenerExecutor } from \"./types\";\n\nexport type SeriesExecutorOptions = {\n reverse?: boolean; // 反向执行监听器\n /**\n * 控制监听器如何返回结果\n *\n * 提供一个reduce函数对所有监听器返回结果进行reduce操作\n * series({\n * onReturns: (result, cur)=>{\n * if(!result) result = []\n * return result.push(cur)\n * }\n * })\n */\n onReturns?: (results: any, cur: any) => any;\n // 当调用下一个监听器前执行,返回false或触发错误均不再执行后续的监听器\n // 可以在此修改message\n onNext?: (\n index: number,\n previous: any,\n message: TypedFastEventMessage,\n args: FastEventListenerArgs,\n results: any,\n ) => boolean;\n // 当执行监听器出错时的回调,返回false中止后续执行\n onError?:\n | \"skip\"\n | \"abort\"\n | \"error\"\n | ((\n e: any,\n message: TypedFastEventMessage,\n args: FastEventListenerArgs,\n ) => void | \"skip\" | \"abort\" | \"error\");\n};\n\nexport const series = (options?: SeriesExecutorOptions): FastListenerExecutor => {\n const { reverse, onNext, onReturns, onError } = Object.assign(\n {\n reverse: false,\n onError: () => {},\n onNext: () => true,\n onReturns: (_: any, cur: any) => cur,\n },\n options,\n ) as SeriesExecutorOptions;\n return async (listeners, message, args, execute) => {\n let results: any = undefined;\n let stepResult: any = undefined;\n let index: number = 0;\n // 全部执行次数-1\n listeners.forEach((listener) => listener[2]--);\n for (let i = 0; i < listeners.length; i++) {\n const item = listeners[reverse ? listeners.length - 1 - i : i];\n const listener = item[0] as TypedFastEventListener<any, any, any>;\n try {\n if (\n isFunction(onNext) &&\n onNext(++index, stepResult, message, args, results) === false\n ) {\n break;\n }\n stepResult = await execute(listener, message, args, false);\n if (isFunction(onReturns)) {\n results = onReturns(results, stepResult);\n } else {\n results = stepResult;\n }\n // 实际执行次数+1\n item[2]++;\n } catch (e: any) {\n try {\n const behavior = isString(onError)\n ? onError\n : isFunction(onError) && onError!(e, message, args);\n if (behavior === \"skip\") {\n continue;\n } else if (behavior === \"error\") {\n results = e;\n break;\n } else if (behavior === \"abort\") {\n break;\n }\n } catch {}\n }\n }\n return results;\n };\n};\n","import { TypedFastEventMessage } from \"../types/FastEventMessages\";\nimport { series, SeriesExecutorOptions } from \"./series\";\nimport { FastListenerExecutor } from \"./types\";\n\nexport type WaterfallExecutorOptions = Omit<\n SeriesExecutorOptions,\n \"onError\" | \"onReturns\" | \"onStep\"\n>;\n\n/**\n * 创建一个瀑布流执行器,用于按顺序执行监听器,并将前一个监听器的结果传递给下一个监听器\n * 如果出错就不再执行后续的监听器\n *\n * @param options - 执行器配置选项\n * @returns 返回一个 FastListener 执行器实例\n *\n * @remarks\n * - 当任一监听器执行出错时,会中断后续监听器的执行\n * - 每个监听器的执行结果会作为下一个监听器的 payload 参数\n */\nexport const waterfall = (options?: WaterfallExecutorOptions): FastListenerExecutor => {\n return series(\n Object.assign({}, options, {\n // 出错时不再执行后续的监听器\n onError: \"abort\",\n // 将结果作为payload传给下一个监听器\n onNext: (index: number, previous: any, message: TypedFastEventMessage) => {\n message.payload = previous;\n },\n }) as unknown as SeriesExecutorOptions,\n );\n};\n","import { FastListenerExecutor } from \"./types\"\n\n/**\n * \n */\nexport const parallel = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n return listeners.map(listener => execute(listener[0], message, args, true))\n }\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/executors/first.ts","../../src/executors/last.ts","../../src/executors/race.ts","../../src/executors/random.ts","../../src/executors/balance.ts","../../src/utils/isFunction.ts","../../src/utils/isString.ts","../../src/executors/series.ts","../../src/executors/waterfall.ts","../../src/executors/parallel.ts"],"names":["first","__name","listeners","message","args","execute","forEach","listener","call","last","length","race","winner","abortController","abortSignal","AbortController","signal","Promise","map","resolve","then","result","abort","random","index","Math","floor","balance","count","i","undefined","isFunction","fn","isString","str","series","options","reverse","onNext","onReturns","onError","Object","assign","_","cur","results","stepResult","item","e","behavior","waterfall","previous","payload","parallel"],"mappings":"iFAWaA,IAAAA,CAAAA,CAAQC,CAAA,CAAA,IACV,CAACC,CAAAA,CAAWC,CAASC,CAAAA,CAAAA,CAAMC,CAC9BH,IAAAA,CAAAA,CAAUI,OAASC,CAAAA,CAAAA,EAAaA,CAAS,CAAA,CAAA,GAAE,CAC3CL,CAAAA,CAAAA,CAAU,CAAA,CAAA,CAAG,CAAA,CAAA,EAAA,CACN,CAACG,CAAAA,CAAQG,IAAKN,CAAAA,C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A,EAAIN,CAAAA,CAAAA,CAAS,CAEvBI,OAAAA,CAAS,OAETF,CAAAA,MAAAA,CAAQrC,CAAA,CAAA,CAACuB,CAAe2B,CAAAA,CAAAA,CAAehD,CAAAA,GAAAA,CACnCA,CAAQiD,CAAAA,OAAAA,CAAUD,EACtB,CAAA,CAFQ,SAGZ,CAAA,CAAA,CATiB,CAAA,WAAA,ECfZE,IAAAA,CAAAA,CAAWpD,CAAA,CAAA,IACb,CAACC,CAAAA,CAAWC,CAASC,CAAAA,CAAAA,CAAMC,CACvBH,GAAAA,CAAAA,CAAUgB,GAAI,CAAA,CAACX,CAAUsB,CAAAA,CAAAA,GAC5BxB,CAAQG,CAAAA,IAAAA,CAAKN,CAAU2B,CAAAA,CAAAA,CAAItB,CAAAA,CAAAA,CAAUJ,CAASC,CAAAA,CAAAA,CAAM,IAAA,CAAA,CAHxC,CAAA,UAAA","file":"index.mjs","sourcesContent":["import { FastListenerExecutor } from \"./types\";\n\n/**\n * 执行第一个监听器的执行器函数\n *\n * @param listeners - 监听器数组,每个元素是一个包含监听器函数的元组\n * @param message - 要传递给监听器的消息对象\n * @param args - 要传递给监听器的额外参数\n * @param execute - 执行监听器的函数\n * @returns 返回一个数组,包含第一个监听器的执行结果\n */\nexport const first = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n listeners.forEach((listener) => listener[2]--);\n listeners[0][2]++;\n return [execute.call(listeners[0], listeners[0], message, args)];\n };\n};\n","import { FastListenerExecutor } from \"./types\";\n\n/**\n * 执行监听器列表中的最后一个监听器\n * @param listeners - 监听器数组\n * @param message - 事件消息\n * @param args - 事件参数\n * @param execute - 执行器函数\n * @returns 返回包含最后一个监听器执行结果的数组\n */\nexport const last = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n listeners.forEach((listener) => listener[2]--);\n listeners[listeners.length - 1][2]++;\n return [\n execute.call(\n listeners[listeners.length - 1],\n listeners[listeners.length - 1],\n message,\n args,\n ),\n ];\n };\n};\n","import { FastEventListenerMeta } from \"../types/FastEventListeners\";\nimport { FastListenerExecutor } from \"./types\";\n\n/**\n * 竞态执行器 - 同时执行多个监听器,只返回最快完成的结果\n *\n * @param listeners - 监听器元数据列表\n * @param message - 要处理的消息\n * @param args - 执行参数\n * @param execute - 执行函数\n * @returns 包含最快完成监听器结果的数组\n *\n * @description\n * - 只有第一个完成的监听器结果会被返回\n * - 其他未完成的监听器会被中止\n * - 如果没有提供中止信号,会自动创建一个\n * - 胜出的监听器计数会被恢复\n */\nexport const race = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n let winner: FastEventListenerMeta | undefined;\n let abortController: AbortController | undefined;\n if (!args || (args && !args.abortSignal)) {\n abortController = new AbortController();\n if (!args) args = {};\n args.abortSignal = abortController.signal;\n }\n const result = Promise.race(\n listeners.map((listener) => {\n listener[2]--;\n return Promise.resolve(execute.call(listener, listener, message, args)).then(\n (result: any) => {\n if (!winner) {\n winner = listener;\n listener[2]++;\n }\n abortController?.abort();\n return result;\n },\n );\n }),\n );\n return [result];\n };\n};\n","import { FastListenerExecutor } from \"./types\";\n\n/**\n * 随机执行器 - 从监听器列表中随机选择一个监听器执行\n *\n * @param listeners - 监听器列表,每个元素为 [监听器函数, 优先级, 执行次数] 的元组\n * @param message - 要处理的消息对象\n * @param args - 传递给监听器的额外参数\n * @param execute - 执行监听器的函数\n * @returns 返回包含执行结果的数组\n *\n * @remarks\n * - 随机选择一个监听器执行\n * - 所有监听器的执行次数计数减1\n * - 被选中执行的监听器执行次数加1\n */\nexport const random = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n const index = Math.floor(Math.random() * listeners.length);\n listeners.forEach((listener) => listener[2]--);\n listeners[index][2]++;\n return [execute.call(listeners[index], listeners[index], message, args)];\n };\n};\n","import { FastListenerExecutor } from \"./types\";\n\n/**\n * 负载均衡执行器,用于在多个监听器中选择执行次数最少的进行调用\n * @param listeners 监听器列表\n * @param message 消息对象\n * @param args 参数列表\n * @param execute 执行函数\n * @returns 返回包含单个执行结果的数组\n *\n * 执行策略:\n * 1. 遍历所有监听器,找出执行次数最少的监听器\n * 2. 由于监听器执行后会自动+1,因此先对所有监听器执行次数-1,以抵消后续的+1\n * 3. 只执行选中的监听器,其他监听器不执行\n */\nexport const balance = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n // 找出listeners里面所有执行器的执行次数最少的项\n let count: number;\n let index: number = 0;\n listeners.forEach((listener, i) => {\n // 为什么所有监听器的执行次数均减1?\n // 因为监听器执行完毕后会自动+1,但是在balance执行器中,只有一个会监听器会执行,因此在此先减一用来抵消后续的+1\n listener[2]--;\n if (count === undefined || count > listener[2]) {\n count = listener[2];\n index = i;\n }\n });\n listeners[index][2]++;\n return [execute.call(listeners[index], listeners[index], message, args)];\n };\n};\n","export function isFunction(fn: any): fn is Function {\n return fn && typeof (fn) == \"function\"\n}","export function isString(str: any): str is string {\n return str && typeof (str) === \"string\"\n}","import { TypedFastEventMessage } from \"../types/FastEventMessages\";\nimport { FastEventListenerMeta, TypedFastEventListener } from \"../types/FastEventListeners\";\nimport { FastEventListenerArgs } from \"../types/FastEvents\";\nimport { isString } from \"../utils\";\nimport { isFunction } from \"../utils/isFunction\";\nimport { FastListenerExecutor } from \"./types\";\n\nexport type SeriesExecutorOptions = {\n reverse?: boolean; // 反向执行监听器\n /**\n * 控制监听器如何返回结果\n *\n * 提供一个reduce函数对所有监听器返回结果进行reduce操作\n * series({\n * onReturns: (result, cur)=>{\n * if(!result) result = []\n * return result.push(cur)\n * }\n * })\n */\n onReturns?: (results: any, cur: any) => any;\n // 当调用下一个监听器前执行,返回false或触发错误均不再执行后续的监听器\n // 可以在此修改message\n onNext?: (\n index: number,\n previous: any,\n message: TypedFastEventMessage,\n args: FastEventListenerArgs,\n results: any,\n ) => boolean;\n // 当执行监听器出错时的回调,返回false中止后续执行\n onError?:\n | \"skip\"\n | \"abort\"\n | \"error\"\n | ((\n e: any,\n message: TypedFastEventMessage,\n args: FastEventListenerArgs,\n ) => void | \"skip\" | \"abort\" | \"error\");\n};\n\nexport const series = (options?: SeriesExecutorOptions): FastListenerExecutor => {\n const { reverse, onNext, onReturns, onError } = Object.assign(\n {\n reverse: false,\n onError: () => {},\n onNext: () => true,\n onReturns: (_: any, cur: any) => cur,\n },\n options,\n ) as SeriesExecutorOptions;\n return async (listeners, message, args, execute) => {\n let results: any = undefined;\n let stepResult: any = undefined;\n let index: number = 0;\n // 全部执行次数-1\n listeners.forEach((listener) => listener[2]--);\n for (let i = 0; i < listeners.length; i++) {\n const item = listeners[reverse ? listeners.length - 1 - i : i];\n const listener = item as unknown as FastEventListenerMeta;\n try {\n if (\n isFunction(onNext) &&\n onNext(++index, stepResult, message, args, results) === false\n ) {\n break;\n }\n stepResult = await execute.call(listener, listener, message, args, false);\n if (isFunction(onReturns)) {\n results = onReturns(results, stepResult);\n } else {\n results = stepResult;\n }\n // 实际执行次数+1\n item[2]++;\n } catch (e: any) {\n try {\n const behavior = isString(onError)\n ? onError\n : isFunction(onError) && onError!(e, message, args);\n if (behavior === \"skip\") {\n continue;\n } else if (behavior === \"error\") {\n results = e;\n break;\n } else if (behavior === \"abort\") {\n break;\n }\n } catch {}\n }\n }\n return results;\n };\n};\n","import { TypedFastEventMessage } from \"../types/FastEventMessages\";\nimport { series, SeriesExecutorOptions } from \"./series\";\nimport { FastListenerExecutor } from \"./types\";\n\nexport type WaterfallExecutorOptions = Omit<\n SeriesExecutorOptions,\n \"onError\" | \"onReturns\" | \"onStep\"\n>;\n\n/**\n * 创建一个瀑布流执行器,用于按顺序执行监听器,并将前一个监听器的结果传递给下一个监听器\n * 如果出错就不再执行后续的监听器\n *\n * @param options - 执行器配置选项\n * @returns 返回一个 FastListener 执行器实例\n *\n * @remarks\n * - 当任一监听器执行出错时,会中断后续监听器的执行\n * - 每个监听器的执行结果会作为下一个监听器的 payload 参数\n */\nexport const waterfall = (options?: WaterfallExecutorOptions): FastListenerExecutor => {\n return series(\n Object.assign({}, options, {\n // 出错时不再执行后续的监听器\n onError: \"abort\",\n // 将结果作为payload传给下一个监听器\n onNext: (index: number, previous: any, message: TypedFastEventMessage) => {\n message.payload = previous;\n },\n }) as unknown as SeriesExecutorOptions,\n );\n};\n","import { FastListenerExecutor } from \"./types\";\n\n/**\n *\n */\nexport const parallel = (): FastListenerExecutor => {\n return (listeners, message, args, execute) => {\n return listeners.map((listener, i) =>\n execute.call(listeners[i], listener, message, args, true),\n );\n };\n};\n"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -998,7 +998,7 @@ type FastEventSubscriber = {
|
|
|
998
998
|
_close?: () => void;
|
|
999
999
|
};
|
|
1000
1000
|
|
|
1001
|
-
type FastListenerExecutor = (listeners: FastEventListenerMeta[], message: TypedFastEventMessage, args: FastEventListenerArgs, execute: (listener:
|
|
1001
|
+
type FastListenerExecutor = (listeners: FastEventListenerMeta[], message: TypedFastEventMessage, args: FastEventListenerArgs, execute: (this: FastEventListenerMeta, listener: FastEventListenerMeta, message: TypedFastEventMessage, args: FastEventListenerArgs, catchErrors?: boolean) => Promise<any> | any) => Promise<any[]> | any[];
|
|
1002
1002
|
|
|
1003
1003
|
type FastListenerPipe = (listener: TypedFastEventListener) => TypedFastEventListener;
|
|
1004
1004
|
|
|
@@ -1111,13 +1111,15 @@ declare function createAsyncEventIterator<T = any>(eventEmitter: FastEvent<any>
|
|
|
1111
1111
|
|
|
1112
1112
|
type FastEventOptions<Meta = Record<string, any>, Context = never> = {
|
|
1113
1113
|
id: string;
|
|
1114
|
+
title: string;
|
|
1114
1115
|
debug: boolean;
|
|
1115
1116
|
delimiter: string;
|
|
1116
1117
|
context: Context;
|
|
1117
1118
|
ignoreErrors: boolean;
|
|
1118
1119
|
meta: Meta;
|
|
1119
|
-
|
|
1120
|
-
|
|
1120
|
+
onAddBeforeListener?: (type: string, listener: TypedFastEventListener, options: FastEventListenOptions<Record<string, any>, Meta>) => boolean | FastEventSubscriber | void;
|
|
1121
|
+
onAddAfterListener?: (type: string, node: FastEventListenerNode) => void;
|
|
1122
|
+
onRemoveListener?: (type: string, listener: TypedFastEventListener, node: FastEventListenerNode) => void;
|
|
1121
1123
|
onClearListeners?: () => void;
|
|
1122
1124
|
onListenerError?: (error: Error, listener: TypedFastEventListener, message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta> | undefined) => void;
|
|
1123
1125
|
onBeforeExecuteListener?: (message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta>) => boolean | void | any[];
|
|
@@ -1211,11 +1213,12 @@ type FastEventListener<T extends string = string, P = any, M extends Record<stri
|
|
|
1211
1213
|
type FastEventCommonListener<Message = FastEventMessage, Meta extends Record<string, any> = Record<string, any>, Context = any> = (this: Context, message: Message, args: FastEventListenerArgs<Meta>) => any | Promise<any>;
|
|
1212
1214
|
/**
|
|
1213
1215
|
* [
|
|
1214
|
-
* 监听器函数引用,
|
|
1215
|
-
* 需要执行多少次, =0代表不限
|
|
1216
|
-
* 实际执行的次数(用于负载均衡时记录)
|
|
1217
|
-
* 标签 用于调试一般可以标识监听器类型或任意信息
|
|
1218
|
-
*
|
|
1216
|
+
* 0: 监听器函数引用,
|
|
1217
|
+
* 1: 需要执行多少次, =0代表不限
|
|
1218
|
+
* 2: 实际执行的次数(用于负载均衡时记录)
|
|
1219
|
+
* 3: 标签 用于调试一般可以标识监听器类型或任意信息
|
|
1220
|
+
* 4: 标识,
|
|
1221
|
+
* 5: 监听器最后一次执行结果,仅仅在debug时启用,如果结果是对象则是一个WeakRef
|
|
1219
1222
|
* ]
|
|
1220
1223
|
*/
|
|
1221
1224
|
type FastEventListenerMeta = [
|
|
@@ -1223,7 +1226,8 @@ type FastEventListenerMeta = [
|
|
|
1223
1226
|
number,
|
|
1224
1227
|
number,
|
|
1225
1228
|
string,
|
|
1226
|
-
number
|
|
1229
|
+
number,
|
|
1230
|
+
any?
|
|
1227
1231
|
];
|
|
1228
1232
|
type FastEventListenerNode = {
|
|
1229
1233
|
__listeners: FastEventListenerMeta[];
|
|
@@ -1286,6 +1290,23 @@ type UnTransformedEvents<Events extends Record<string, any>> = {
|
|
|
1286
1290
|
[K in keyof Events]: Events[K] extends FastMessagePayload<infer P> ? P : Events[K];
|
|
1287
1291
|
};
|
|
1288
1292
|
|
|
1293
|
+
type AddBeforeListenerHook = (type: string, listener: TypedFastEventListener, options: FastEventListenOptions<Record<string, any>, any>) => boolean | FastEventSubscriber | void;
|
|
1294
|
+
type AddAfterListenerHook = (type: string, node: FastEventListenerNode) => void;
|
|
1295
|
+
type RemoveListenerHook = (type: string, listener: TypedFastEventListener, node: FastEventListenerNode) => void;
|
|
1296
|
+
type ClearListenersHook = () => void;
|
|
1297
|
+
type ListenerErrorHook = (error: Error, listener: TypedFastEventListener, message: TypedFastEventMessage<any, any>, args: FastEventListenerArgs<any> | undefined) => void;
|
|
1298
|
+
type BeforeExecuteListenerHook = (message: TypedFastEventMessage<any, any>, args: FastEventListenerArgs<any>) => boolean | void | any[];
|
|
1299
|
+
type AfterExecuteListenerHook = (message: TypedFastEventMessage<any, any>, returns: any[], listeners: FastEventListenerNode[]) => void;
|
|
1300
|
+
type FastEventHooks = {
|
|
1301
|
+
AddBeforeListener: AddBeforeListenerHook[];
|
|
1302
|
+
AddAfterListener: AddAfterListenerHook[];
|
|
1303
|
+
RemoveListener: RemoveListenerHook[];
|
|
1304
|
+
ClearListeners: ClearListenersHook[];
|
|
1305
|
+
ListenerError: ListenerErrorHook[];
|
|
1306
|
+
BeforeExecuteListener: BeforeExecuteListenerHook[];
|
|
1307
|
+
AfterExecuteListener: AfterExecuteListenerHook[];
|
|
1308
|
+
};
|
|
1309
|
+
|
|
1289
1310
|
/**
|
|
1290
1311
|
* 返回最匹配的事件元组
|
|
1291
1312
|
*
|
|
@@ -1473,6 +1494,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
1473
1494
|
private _delimiter;
|
|
1474
1495
|
/** 事件监听器执行时的上下文对象 */
|
|
1475
1496
|
private _context;
|
|
1497
|
+
private _hooks?;
|
|
1476
1498
|
/** 保留的事件消息映射,Key是事件名称,Value是保留的事件消息 */
|
|
1477
1499
|
retainedMessages: Map<string, any>;
|
|
1478
1500
|
/** 当前注册的监听器总数 */
|
|
@@ -1505,6 +1527,26 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
1505
1527
|
get meta(): Meta;
|
|
1506
1528
|
/** 获取事件发射器的唯一标识符 */
|
|
1507
1529
|
get id(): string;
|
|
1530
|
+
/** 获取事件发射器的唯一标识符 */
|
|
1531
|
+
get title(): string;
|
|
1532
|
+
get hooks(): FastEventHooks;
|
|
1533
|
+
private _execAfterExecuteListener;
|
|
1534
|
+
/**
|
|
1535
|
+
* 执行Hook
|
|
1536
|
+
*
|
|
1537
|
+
* AfterExecuteListener为什么需要特别处理?
|
|
1538
|
+
*
|
|
1539
|
+
* 因为AfterExecuteListener是在监听器执行完成后调用
|
|
1540
|
+
* 并且将监听器的结果传入,但是监听器有可能返回Promise
|
|
1541
|
+
* 因为需要等等Promise resolve,再调用AfterExecuteListener
|
|
1542
|
+
*
|
|
1543
|
+
*
|
|
1544
|
+
* @param hookName
|
|
1545
|
+
* @param args
|
|
1546
|
+
* @param onlyAsyncHook 只运行异步HOOK
|
|
1547
|
+
* @returns
|
|
1548
|
+
*/
|
|
1549
|
+
private _executeHooks;
|
|
1508
1550
|
/**
|
|
1509
1551
|
* 初始化选项
|
|
1510
1552
|
*
|
|
@@ -1525,7 +1567,6 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
1525
1567
|
* @private
|
|
1526
1568
|
*/
|
|
1527
1569
|
private _addListener;
|
|
1528
|
-
private _enableDevTools;
|
|
1529
1570
|
/**
|
|
1530
1571
|
*
|
|
1531
1572
|
* 根据parts路径遍历监听器树,并在最后的节点上执行回调函数
|
|
@@ -1543,14 +1584,6 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
1543
1584
|
* @description 遍历节点的监听器列表,移除所有匹配的监听器。支持移除普通函数和数组形式的监听器
|
|
1544
1585
|
*/
|
|
1545
1586
|
private _removeListener;
|
|
1546
|
-
/**
|
|
1547
|
-
* 调用onAddListener HOOK
|
|
1548
|
-
* @param type
|
|
1549
|
-
* @param listener
|
|
1550
|
-
* @param options
|
|
1551
|
-
* @returns
|
|
1552
|
-
*/
|
|
1553
|
-
private _onAddListener;
|
|
1554
1587
|
/**
|
|
1555
1588
|
* 注册事件监听器
|
|
1556
1589
|
* @param type - 事件类型,支持以下格式:
|
|
@@ -1683,7 +1716,6 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
1683
1716
|
private _traverseToPath;
|
|
1684
1717
|
private _traverseListeners;
|
|
1685
1718
|
private _onListenerError;
|
|
1686
|
-
private _setListenerFlags;
|
|
1687
1719
|
/**
|
|
1688
1720
|
* 执行单个监听器函数
|
|
1689
1721
|
* @param listener - 要执行的监听器函数或包装过的监听器对象
|
|
@@ -2028,4 +2060,13 @@ declare function isClass(target: unknown): target is new (...args: any[]) => any
|
|
|
2028
2060
|
|
|
2029
2061
|
declare function isFastEvent(target: any): target is FastEvent;
|
|
2030
2062
|
|
|
2031
|
-
|
|
2063
|
+
/**
|
|
2064
|
+
* 判断是否为可异步迭代对象(AsyncIterable)
|
|
2065
|
+
* 即具有 Symbol.asyncIterator 方法的对象
|
|
2066
|
+
*
|
|
2067
|
+
* @param value - 要检查的值
|
|
2068
|
+
* @returns 如果是可异步迭代对象返回 true
|
|
2069
|
+
*/
|
|
2070
|
+
declare function isAsyncIterable<T = any>(value: unknown): value is AsyncIterable<T>;
|
|
2071
|
+
|
|
2072
|
+
export { AbortError, type Add, type AddAfterListenerHook, type AddBeforeListenerHook, type AfterExecuteListenerHook, type AllowCall, type ApplyWildcardEvents, type AssertFastMessage, type AssertRecord, type AssertString, type AtPayloads, type BeforeExecuteListenerHook, CancelError, type ChangeFieldType, type Class, type ClearListenersHook, type ClosestMatch, type ContainsWildcard, type Decrement, type DeepPartial, type Dict, type Equal, type Expand, type ExpandRecord, type ExpandWildcard, type ExtendWildcardEvents, type Fallback, FastEvent, type FastEventCommonListener, type FastEventCommonMessage, type FastEventEmitMessage, FastEventError, type FastEventHooks, FastEventIterator, type FastEventIteratorOptions, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, FastEventListenerFlags, type FastEventListenerMeta, type FastEventListenerNode, type FastEventListeners, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListeners, type FastMessagePayload, type FastQueueOverflows, type FirstObjectItem, type FirstOfUnion, type GetClosestEventName, type GetClosestEventNameTuple, type GetClosestEventPayload, type GetClosestEventTuple, type GetClosestEvents, type GetFixedPartCount, type GetMatchedEventNames, type GetPartCount, type GetPartCountAcc, type GetPayload, type GetWildcardCount, type GetWildcardEventList, type IFastEventScope, type IfNever, type IndexOfMax, type IndexOfMin, type IsAllTransformed, type IsAny, type IsAnyRecord, type IsFullWildcard, type IsMatchEventName, type IsMultiWildcard, type IsNever, type IsSemiWildcard, type IsTransformedEvent, type IsWildcardPart, type Join, type KeyOf, type Keys, type ListenerErrorHook, type Max, type Merge, type MergeStrings, type MergeUnion, type Min, type MutableMessage, type MutableRecord, type NormalEvents, type NotEqual, type NotPayload, type ObjectKeys, type OmitTransformedEvents, type OptionalKeys, type Overloads, type OverrideOptions, type PayloadValues, type PickEqualRecord, type PickInlcudeDelimiterRecord, type PickNotEqualRecord, type PickNotInlcudeDelimiterRecord, type PickPayload, type PickTransformedEvents, type PrefixNumber, type ProcessSegments, QueueOverflowError, type RemoveEmptyObject, type RemoveListenerHook, type ReplaceWildcard, type RequiredItems, type RequiredKeys, type ScopeEvents, type Slice, type Split, type SplitPath, type StrictEqual, TimeoutError, type ToFixedCounts, type ToKeyPrioritys, type ToWildcardMessage, type TransformedEvents, type Tuple, type TypedFastEventAnyListener, type TypedFastEventListener, type TypedFastEventMessage, type TypedFastEventMessageOptional, type UnTransformedEvents, UnboundError, type Union, type UnionToIntersection, type Unique, type ValueOf, type WildcardEvents, type WildcardKeyToObject, type WildcardKeys, type WildcardStyle, __FastEventScope__, __FastEvent__, __expandable__, createAsyncEventIterator, expandable, isAsyncIterable, isClass, type isEmpty, isExpandable, isFastEvent, isFastEventMessage, isFastEventScope, isFunction, isPathMatched, isString, isSubsctiber };
|
package/dist/index.d.ts
CHANGED
|
@@ -998,7 +998,7 @@ type FastEventSubscriber = {
|
|
|
998
998
|
_close?: () => void;
|
|
999
999
|
};
|
|
1000
1000
|
|
|
1001
|
-
type FastListenerExecutor = (listeners: FastEventListenerMeta[], message: TypedFastEventMessage, args: FastEventListenerArgs, execute: (listener:
|
|
1001
|
+
type FastListenerExecutor = (listeners: FastEventListenerMeta[], message: TypedFastEventMessage, args: FastEventListenerArgs, execute: (this: FastEventListenerMeta, listener: FastEventListenerMeta, message: TypedFastEventMessage, args: FastEventListenerArgs, catchErrors?: boolean) => Promise<any> | any) => Promise<any[]> | any[];
|
|
1002
1002
|
|
|
1003
1003
|
type FastListenerPipe = (listener: TypedFastEventListener) => TypedFastEventListener;
|
|
1004
1004
|
|
|
@@ -1111,13 +1111,15 @@ declare function createAsyncEventIterator<T = any>(eventEmitter: FastEvent<any>
|
|
|
1111
1111
|
|
|
1112
1112
|
type FastEventOptions<Meta = Record<string, any>, Context = never> = {
|
|
1113
1113
|
id: string;
|
|
1114
|
+
title: string;
|
|
1114
1115
|
debug: boolean;
|
|
1115
1116
|
delimiter: string;
|
|
1116
1117
|
context: Context;
|
|
1117
1118
|
ignoreErrors: boolean;
|
|
1118
1119
|
meta: Meta;
|
|
1119
|
-
|
|
1120
|
-
|
|
1120
|
+
onAddBeforeListener?: (type: string, listener: TypedFastEventListener, options: FastEventListenOptions<Record<string, any>, Meta>) => boolean | FastEventSubscriber | void;
|
|
1121
|
+
onAddAfterListener?: (type: string, node: FastEventListenerNode) => void;
|
|
1122
|
+
onRemoveListener?: (type: string, listener: TypedFastEventListener, node: FastEventListenerNode) => void;
|
|
1121
1123
|
onClearListeners?: () => void;
|
|
1122
1124
|
onListenerError?: (error: Error, listener: TypedFastEventListener, message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta> | undefined) => void;
|
|
1123
1125
|
onBeforeExecuteListener?: (message: TypedFastEventMessage<any, Meta>, args: FastEventListenerArgs<Meta>) => boolean | void | any[];
|
|
@@ -1211,11 +1213,12 @@ type FastEventListener<T extends string = string, P = any, M extends Record<stri
|
|
|
1211
1213
|
type FastEventCommonListener<Message = FastEventMessage, Meta extends Record<string, any> = Record<string, any>, Context = any> = (this: Context, message: Message, args: FastEventListenerArgs<Meta>) => any | Promise<any>;
|
|
1212
1214
|
/**
|
|
1213
1215
|
* [
|
|
1214
|
-
* 监听器函数引用,
|
|
1215
|
-
* 需要执行多少次, =0代表不限
|
|
1216
|
-
* 实际执行的次数(用于负载均衡时记录)
|
|
1217
|
-
* 标签 用于调试一般可以标识监听器类型或任意信息
|
|
1218
|
-
*
|
|
1216
|
+
* 0: 监听器函数引用,
|
|
1217
|
+
* 1: 需要执行多少次, =0代表不限
|
|
1218
|
+
* 2: 实际执行的次数(用于负载均衡时记录)
|
|
1219
|
+
* 3: 标签 用于调试一般可以标识监听器类型或任意信息
|
|
1220
|
+
* 4: 标识,
|
|
1221
|
+
* 5: 监听器最后一次执行结果,仅仅在debug时启用,如果结果是对象则是一个WeakRef
|
|
1219
1222
|
* ]
|
|
1220
1223
|
*/
|
|
1221
1224
|
type FastEventListenerMeta = [
|
|
@@ -1223,7 +1226,8 @@ type FastEventListenerMeta = [
|
|
|
1223
1226
|
number,
|
|
1224
1227
|
number,
|
|
1225
1228
|
string,
|
|
1226
|
-
number
|
|
1229
|
+
number,
|
|
1230
|
+
any?
|
|
1227
1231
|
];
|
|
1228
1232
|
type FastEventListenerNode = {
|
|
1229
1233
|
__listeners: FastEventListenerMeta[];
|
|
@@ -1286,6 +1290,23 @@ type UnTransformedEvents<Events extends Record<string, any>> = {
|
|
|
1286
1290
|
[K in keyof Events]: Events[K] extends FastMessagePayload<infer P> ? P : Events[K];
|
|
1287
1291
|
};
|
|
1288
1292
|
|
|
1293
|
+
type AddBeforeListenerHook = (type: string, listener: TypedFastEventListener, options: FastEventListenOptions<Record<string, any>, any>) => boolean | FastEventSubscriber | void;
|
|
1294
|
+
type AddAfterListenerHook = (type: string, node: FastEventListenerNode) => void;
|
|
1295
|
+
type RemoveListenerHook = (type: string, listener: TypedFastEventListener, node: FastEventListenerNode) => void;
|
|
1296
|
+
type ClearListenersHook = () => void;
|
|
1297
|
+
type ListenerErrorHook = (error: Error, listener: TypedFastEventListener, message: TypedFastEventMessage<any, any>, args: FastEventListenerArgs<any> | undefined) => void;
|
|
1298
|
+
type BeforeExecuteListenerHook = (message: TypedFastEventMessage<any, any>, args: FastEventListenerArgs<any>) => boolean | void | any[];
|
|
1299
|
+
type AfterExecuteListenerHook = (message: TypedFastEventMessage<any, any>, returns: any[], listeners: FastEventListenerNode[]) => void;
|
|
1300
|
+
type FastEventHooks = {
|
|
1301
|
+
AddBeforeListener: AddBeforeListenerHook[];
|
|
1302
|
+
AddAfterListener: AddAfterListenerHook[];
|
|
1303
|
+
RemoveListener: RemoveListenerHook[];
|
|
1304
|
+
ClearListeners: ClearListenersHook[];
|
|
1305
|
+
ListenerError: ListenerErrorHook[];
|
|
1306
|
+
BeforeExecuteListener: BeforeExecuteListenerHook[];
|
|
1307
|
+
AfterExecuteListener: AfterExecuteListenerHook[];
|
|
1308
|
+
};
|
|
1309
|
+
|
|
1289
1310
|
/**
|
|
1290
1311
|
* 返回最匹配的事件元组
|
|
1291
1312
|
*
|
|
@@ -1473,6 +1494,7 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
1473
1494
|
private _delimiter;
|
|
1474
1495
|
/** 事件监听器执行时的上下文对象 */
|
|
1475
1496
|
private _context;
|
|
1497
|
+
private _hooks?;
|
|
1476
1498
|
/** 保留的事件消息映射,Key是事件名称,Value是保留的事件消息 */
|
|
1477
1499
|
retainedMessages: Map<string, any>;
|
|
1478
1500
|
/** 当前注册的监听器总数 */
|
|
@@ -1505,6 +1527,26 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
1505
1527
|
get meta(): Meta;
|
|
1506
1528
|
/** 获取事件发射器的唯一标识符 */
|
|
1507
1529
|
get id(): string;
|
|
1530
|
+
/** 获取事件发射器的唯一标识符 */
|
|
1531
|
+
get title(): string;
|
|
1532
|
+
get hooks(): FastEventHooks;
|
|
1533
|
+
private _execAfterExecuteListener;
|
|
1534
|
+
/**
|
|
1535
|
+
* 执行Hook
|
|
1536
|
+
*
|
|
1537
|
+
* AfterExecuteListener为什么需要特别处理?
|
|
1538
|
+
*
|
|
1539
|
+
* 因为AfterExecuteListener是在监听器执行完成后调用
|
|
1540
|
+
* 并且将监听器的结果传入,但是监听器有可能返回Promise
|
|
1541
|
+
* 因为需要等等Promise resolve,再调用AfterExecuteListener
|
|
1542
|
+
*
|
|
1543
|
+
*
|
|
1544
|
+
* @param hookName
|
|
1545
|
+
* @param args
|
|
1546
|
+
* @param onlyAsyncHook 只运行异步HOOK
|
|
1547
|
+
* @returns
|
|
1548
|
+
*/
|
|
1549
|
+
private _executeHooks;
|
|
1508
1550
|
/**
|
|
1509
1551
|
* 初始化选项
|
|
1510
1552
|
*
|
|
@@ -1525,7 +1567,6 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
1525
1567
|
* @private
|
|
1526
1568
|
*/
|
|
1527
1569
|
private _addListener;
|
|
1528
|
-
private _enableDevTools;
|
|
1529
1570
|
/**
|
|
1530
1571
|
*
|
|
1531
1572
|
* 根据parts路径遍历监听器树,并在最后的节点上执行回调函数
|
|
@@ -1543,14 +1584,6 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
1543
1584
|
* @description 遍历节点的监听器列表,移除所有匹配的监听器。支持移除普通函数和数组形式的监听器
|
|
1544
1585
|
*/
|
|
1545
1586
|
private _removeListener;
|
|
1546
|
-
/**
|
|
1547
|
-
* 调用onAddListener HOOK
|
|
1548
|
-
* @param type
|
|
1549
|
-
* @param listener
|
|
1550
|
-
* @param options
|
|
1551
|
-
* @returns
|
|
1552
|
-
*/
|
|
1553
|
-
private _onAddListener;
|
|
1554
1587
|
/**
|
|
1555
1588
|
* 注册事件监听器
|
|
1556
1589
|
* @param type - 事件类型,支持以下格式:
|
|
@@ -1683,7 +1716,6 @@ declare class FastEvent<Events extends Record<string, any> = Record<string, any>
|
|
|
1683
1716
|
private _traverseToPath;
|
|
1684
1717
|
private _traverseListeners;
|
|
1685
1718
|
private _onListenerError;
|
|
1686
|
-
private _setListenerFlags;
|
|
1687
1719
|
/**
|
|
1688
1720
|
* 执行单个监听器函数
|
|
1689
1721
|
* @param listener - 要执行的监听器函数或包装过的监听器对象
|
|
@@ -2028,4 +2060,13 @@ declare function isClass(target: unknown): target is new (...args: any[]) => any
|
|
|
2028
2060
|
|
|
2029
2061
|
declare function isFastEvent(target: any): target is FastEvent;
|
|
2030
2062
|
|
|
2031
|
-
|
|
2063
|
+
/**
|
|
2064
|
+
* 判断是否为可异步迭代对象(AsyncIterable)
|
|
2065
|
+
* 即具有 Symbol.asyncIterator 方法的对象
|
|
2066
|
+
*
|
|
2067
|
+
* @param value - 要检查的值
|
|
2068
|
+
* @returns 如果是可异步迭代对象返回 true
|
|
2069
|
+
*/
|
|
2070
|
+
declare function isAsyncIterable<T = any>(value: unknown): value is AsyncIterable<T>;
|
|
2071
|
+
|
|
2072
|
+
export { AbortError, type Add, type AddAfterListenerHook, type AddBeforeListenerHook, type AfterExecuteListenerHook, type AllowCall, type ApplyWildcardEvents, type AssertFastMessage, type AssertRecord, type AssertString, type AtPayloads, type BeforeExecuteListenerHook, CancelError, type ChangeFieldType, type Class, type ClearListenersHook, type ClosestMatch, type ContainsWildcard, type Decrement, type DeepPartial, type Dict, type Equal, type Expand, type ExpandRecord, type ExpandWildcard, type ExtendWildcardEvents, type Fallback, FastEvent, type FastEventCommonListener, type FastEventCommonMessage, type FastEventEmitMessage, FastEventError, type FastEventHooks, FastEventIterator, type FastEventIteratorOptions, type FastEventListenOptions, type FastEventListener, type FastEventListenerArgs, FastEventListenerFlags, type FastEventListenerMeta, type FastEventListenerNode, type FastEventListeners, type FastEventMessage, type FastEventMessageExtends, type FastEventMeta, type FastEventOptions, FastEventScope, type FastEventScopeMeta, type FastEventScopeOptions, type FastEventSubscriber, type FastEvents, type FastListeners, type FastMessagePayload, type FastQueueOverflows, type FirstObjectItem, type FirstOfUnion, type GetClosestEventName, type GetClosestEventNameTuple, type GetClosestEventPayload, type GetClosestEventTuple, type GetClosestEvents, type GetFixedPartCount, type GetMatchedEventNames, type GetPartCount, type GetPartCountAcc, type GetPayload, type GetWildcardCount, type GetWildcardEventList, type IFastEventScope, type IfNever, type IndexOfMax, type IndexOfMin, type IsAllTransformed, type IsAny, type IsAnyRecord, type IsFullWildcard, type IsMatchEventName, type IsMultiWildcard, type IsNever, type IsSemiWildcard, type IsTransformedEvent, type IsWildcardPart, type Join, type KeyOf, type Keys, type ListenerErrorHook, type Max, type Merge, type MergeStrings, type MergeUnion, type Min, type MutableMessage, type MutableRecord, type NormalEvents, type NotEqual, type NotPayload, type ObjectKeys, type OmitTransformedEvents, type OptionalKeys, type Overloads, type OverrideOptions, type PayloadValues, type PickEqualRecord, type PickInlcudeDelimiterRecord, type PickNotEqualRecord, type PickNotInlcudeDelimiterRecord, type PickPayload, type PickTransformedEvents, type PrefixNumber, type ProcessSegments, QueueOverflowError, type RemoveEmptyObject, type RemoveListenerHook, type ReplaceWildcard, type RequiredItems, type RequiredKeys, type ScopeEvents, type Slice, type Split, type SplitPath, type StrictEqual, TimeoutError, type ToFixedCounts, type ToKeyPrioritys, type ToWildcardMessage, type TransformedEvents, type Tuple, type TypedFastEventAnyListener, type TypedFastEventListener, type TypedFastEventMessage, type TypedFastEventMessageOptional, type UnTransformedEvents, UnboundError, type Union, type UnionToIntersection, type Unique, type ValueOf, type WildcardEvents, type WildcardKeyToObject, type WildcardKeys, type WildcardStyle, __FastEventScope__, __FastEvent__, __expandable__, createAsyncEventIterator, expandable, isAsyncIterable, isClass, type isEmpty, isExpandable, isFastEvent, isFastEventMessage, isFastEventScope, isFunction, isPathMatched, isString, isSubsctiber };
|