@tsed/hooks 8.3.4 → 8.3.5
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.umd.min.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAQ,eAAiBD,IAEzBD,EAAK,eAAiBC,GACvB,CATD,CASGK,MAAM,I,mBCRT,IAAIC,EAAsB,CCA1BA,EAAwB,CAACL,EAASM,KACjC,IAAI,IAAIC,KAAOD,EACXD,EAAoBG,EAAEF,EAAYC,KAASF,EAAoBG,EAAER,EAASO,IAC5EE,OAAOC,eAAeV,EAASO,EAAK,CAAEI,YAAY,EAAMC,IAAKN,EAAWC,IAE1E,ECNDF,EAAwB,CAACQ,EAAKC,IAAUL,OAAOM,UAAUC,eAAeC,KAAKJ,EAAKC,GCClFT,EAAyBL,IACH,oBAAXkB,QAA0BA,OAAOC,aAC1CV,OAAOC,eAAeV,EAASkB,OAAOC,YAAa,CAAEC,MAAO,WAE7DX,OAAOC,eAAeV,EAAS,aAAc,CAAEoB,OAAO,GAAO,G,KCL9D,SAASC,EAAMC,EAAKC,GAChB,OAAQD,IAAQC,EAAKD,KAAQA,GAAOC,EAAKD,MAAQA,CACrD,C,qIACO,MAAME,EACT,GAAa,IAAIC,
|
|
1
|
+
{"version":3,"file":"hooks.umd.min.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAQ,eAAiBD,IAEzBD,EAAK,eAAiBC,GACvB,CATD,CASGK,MAAM,I,mBCRT,IAAIC,EAAsB,CCA1BA,E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AW6B,OACpB,EAEG,MAAMC,EAAQ,IAAIlC,EACZmC,EAAMD,EAAM5B,GAAG8B,KAAKF,GACpBG,EAAQH,EAAMrB,KAAKuB,KAAKF,GACxBI,EAAOJ,EAAMlB,IAAIoB,KAAKF,GACtBK,EAAQL,EAAMd,KAAKgB,KAAKF,GACxBM,EAAaN,EAAMV,UAAUY,KAAKF,GAClCO,EAASP,EAAML,MAAMO,KAAKF,GAC1BQ,EAAcR,EAAMH,WAAWK,KAAKF,G","sources":["webpack://@tsed/hooks/webpack/universalModuleDefinition","webpack://@tsed/hooks/webpack/bootstrap","webpack://@tsed/hooks/webpack/runtime/define property getters","webpack://@tsed/hooks/webpack/runtime/hasOwnProperty shorthand","webpack://@tsed/hooks/webpack/runtime/make namespace object","webpack://@tsed/hooks/./src/Hooks.ts"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"@tsed/hooks\"] = factory();\n\telse\n\t\troot[\"@tsed/hooks\"] = factory();\n})(self, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","function match(ref, item) {\n return !ref || !item.ref || (ref && item.ref === ref);\n}\nexport class Hooks {\n #listeners = new Map();\n /**\n * Check if an event has listeners\n * @param event\n */\n has(event) {\n return !!this.#listeners.get(event)?.length;\n }\n on(event, cbORef, cb) {\n let ref = cbORef;\n if (!cb) {\n cb = ref;\n ref = undefined;\n }\n const items = this.#listeners.get(event) || [];\n items.push({\n cb,\n ref\n });\n this.#listeners.set(event, items);\n return this;\n }\n once(event, ref, cb) {\n if (!cb) {\n cb = ref;\n }\n const onceCb = (...args) => {\n cb(...args);\n this.off(event, onceCb);\n };\n this.on(event, ref, onceCb);\n return this;\n }\n off(event, cb) {\n const set = (event, items) => {\n if (items.length) {\n this.#listeners.set(event, items);\n }\n else {\n this.#listeners.delete(event);\n }\n };\n if (typeof event === \"string\" && cb) {\n let items = this.#listeners.get(event);\n if (items) {\n set(event, items.filter((item) => item.cb !== cb));\n }\n }\n else {\n const ref = event;\n this.#listeners.forEach((items, event) => {\n set(event, items.filter((item) => item.ref !== ref));\n });\n }\n return this;\n }\n emit(event, ref, args) {\n if (Array.isArray(ref)) {\n args = ref;\n ref = undefined;\n }\n args ||= [];\n const items = this.#listeners.get(event);\n if (items?.length) {\n for (const item of items) {\n if (match(ref, item)) {\n item.cb.apply(null, args);\n }\n }\n }\n }\n async asyncEmit(event, ref, args) {\n if (Array.isArray(ref)) {\n args = ref;\n ref = undefined;\n }\n const items = this.#listeners.get(event);\n if (items?.length) {\n const promises = items.filter((item) => match(ref, item)).map((item) => item.cb.apply(null, args));\n await Promise.all(promises);\n }\n }\n /**\n * Trigger an event, listener alter given value and return it.\n * @param event\n * @param value\n * @param args\n * @param callThis\n */\n alter(event, value, args = [], callThis = null) {\n const items = this.#listeners.get(event);\n if (items?.length) {\n for (const { cb } of items) {\n value = cb.call(callThis, value, ...args);\n }\n }\n return value;\n }\n /**\n * Trigger an event, async listener alter given value and return it.\n * @param event\n * @param value\n * @param args\n * @param callThis\n */\n async asyncAlter(event, value, args = [], callThis = null) {\n const items = this.#listeners.get(event);\n if (items?.length) {\n for (const item of items) {\n value = await item.cb.call(callThis, value, ...args);\n }\n }\n return value;\n }\n destroy() {\n this.#listeners.clear();\n }\n}\nexport const hooks = new Hooks();\nexport const $on = hooks.on.bind(hooks);\nexport const $once = hooks.once.bind(hooks);\nexport const $off = hooks.off.bind(hooks);\nexport const $emit = hooks.emit.bind(hooks);\nexport const $asyncEmit = hooks.asyncEmit.bind(hooks);\nexport const $alter = hooks.alter.bind(hooks);\nexport const $asyncAlter = hooks.asyncAlter.bind(hooks);\n"],"names":["root","factory","exports","module","define","amd","self","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","match","ref","item","Hooks","Map","has","event","this","length","on","cbORef","cb","undefined","items","push","set","once","onceCb","args","off","delete","filter","forEach","emit","Array","isArray","apply","asyncEmit","promises","map","Promise","all","alter","callThis","asyncAlter","destroy","clear","hooks","$on","bind","$once","$off","$emit","$asyncEmit","$alter","$asyncAlter"],"sourceRoot":""}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/hooks",
|
|
3
3
|
"description": "Hooks module for Ts.ED Framework",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.3.
|
|
5
|
+
"version": "8.3.5",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@tsed/monorepo-utils": "2.3.9",
|
|
38
|
-
"@tsed/typescript": "8.3.
|
|
39
|
-
"@tsed/vitest": "8.3.
|
|
38
|
+
"@tsed/typescript": "8.3.5",
|
|
39
|
+
"@tsed/vitest": "8.3.5",
|
|
40
40
|
"eslint": "9.12.0",
|
|
41
41
|
"typescript": "5.4.5",
|
|
42
42
|
"vite": "^5.4.8",
|