This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+2
View File
@@ -0,0 +1,2 @@
export default class{constructor(o=console){this._logger=o,this._hooks={},this._deprecatedHooks={},this.hook=this.hook.bind(this),this.callHook=this.callHook.bind(this)}hook(o,t){if(!o||"function"!=typeof t)return;const s=o;let e;for(;this._deprecatedHooks[o];)"string"==typeof(e=this._deprecatedHooks[o])&&(e={to:e}),o=e.to;e&&(e.message?this._logger.warn(e.message):this._logger.warn(`${s} hook has been deprecated`+(e.to?`, please use ${e.to}`:""))),this._hooks[o]=this._hooks[o]||[],this._hooks[o].push(t)}deprecateHook(o,t){this._deprecatedHooks[o]=t}deprecateHooks(o){Object.assign(this._deprecatedHooks,o)}addHooks(o){const t=function o(t,s={},e){for(const h in t){const r=t[h],i=e?`${e}:${h}`:h;"object"==typeof r&&null!==r?o(r,s,i):s[i]=r}return s}(o);for(const o in t)this.hook(o,t[o])}async callHook(o,...t){var s,e;if(this._hooks[o])try{await(s=this._hooks[o],e=(o=>o(...t)),s.reduce((o,t)=>o.then(o=>e(t,o)),Promise.resolve(null)))}catch(t){"error"!==o&&await this.callHook("error",t),this._logger.fatal?this._logger.fatal(t):this._logger.error(t)}}clearHook(o){o&&delete this._hooks[o]}clearHooks(){this._hooks={}}}
//# sourceMappingURL=hable.esm.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"hable.esm.js","sources":["../src/hable.js","../src/utils.js"],"sourcesContent":["import { serial, flatHooks } from './utils'\n\nexport default class Hookable {\n constructor (logger = console) {\n this._logger = logger\n this._hooks = {}\n this._deprecatedHooks = {}\n\n // Allow destructuring hook and callHook functions out of instance object\n this.hook = this.hook.bind(this)\n this.callHook = this.callHook.bind(this)\n }\n\n hook (name, fn) {\n if (!name || typeof fn !== 'function') {\n return\n }\n\n const originalName = name\n let deprecatedHook\n while (this._deprecatedHooks[name]) {\n deprecatedHook = this._deprecatedHooks[name]\n if (typeof deprecatedHook === 'string') {\n deprecatedHook = { to: deprecatedHook }\n }\n name = deprecatedHook.to\n }\n if (deprecatedHook) {\n if (!deprecatedHook.message) {\n this._logger.warn(\n `${originalName} hook has been deprecated` +\n (deprecatedHook.to ? `, please use ${deprecatedHook.to}` : '')\n )\n } else {\n this._logger.warn(deprecatedHook.message)\n }\n }\n\n this._hooks[name] = this._hooks[name] || []\n this._hooks[name].push(fn)\n }\n\n deprecateHook (old, name) {\n this._deprecatedHooks[old] = name\n }\n\n deprecateHooks (deprecatedHooks) {\n Object.assign(this._deprecatedHooks, deprecatedHooks)\n }\n\n addHooks (configHooks) {\n const hooks = flatHooks(configHooks)\n for (const key in hooks) {\n this.hook(key, hooks[key])\n }\n }\n\n async callHook (name, ...args) {\n if (!this._hooks[name]) {\n return\n }\n try {\n await serial(this._hooks[name], fn => fn(...args))\n } catch (err) {\n if (name !== 'error') {\n await this.callHook('error', err)\n }\n if (this._logger.fatal) {\n this._logger.fatal(err)\n } else {\n this._logger.error(err)\n }\n }\n }\n\n clearHook (name) {\n if (name) {\n delete this._hooks[name]\n }\n }\n\n clearHooks () {\n this._hooks = {}\n }\n}\n","export function flatHooks (configHooks, hooks = {}, parentName) {\n for (const key in configHooks) {\n const subHook = configHooks[key]\n const name = parentName ? `${parentName}:${key}` : key\n if (typeof subHook === 'object' && subHook !== null) {\n flatHooks(subHook, hooks, name)\n } else {\n hooks[name] = subHook\n }\n }\n return hooks\n}\n\nexport function serial (tasks, fn) {\n return tasks.reduce((promise, task) => promise.then(previous => fn(task, previous)), Promise.resolve(null))\n}\n"],"names":["constructor","logger","console","_logger","_hooks","_deprecatedHooks","hook","this","bind","callHook","name","fn","originalName","deprecatedHook","to","message","warn","push","deprecateHook","old","deprecateHooks","deprecatedHooks","Object","assign","addHooks","configHooks","hooks","flatHooks","parentName","key","subHook","args","tasks","reduce","promise","task","then","previous","Promise","resolve","err","fatal","error","clearHook","clearHooks"],"mappings":"qBAGEA,YAAaC,EAASC,cACfC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D,QAEdrC,QAAQuC,MAAMF,IAKzBG,UAAWjC,GACLA,UACKH,KAAKH,OAAOM,GAIvBkC,kBACOxC,OAAS"}
+2
View File
@@ -0,0 +1,2 @@
"use strict";function flatHooks(o,s={},t){for(const e in o){const r=o[e],h=t?`${t}:${e}`:e;"object"==typeof r&&null!==r?flatHooks(r,s,h):s[h]=r}return s}function serial(o,s){return o.reduce((o,t)=>o.then(o=>s(t,o)),Promise.resolve(null))}class Hookable{constructor(o=console){this._logger=o,this._hooks={},this._deprecatedHooks={},this.hook=this.hook.bind(this),this.callHook=this.callHook.bind(this)}hook(o,s){if(!o||"function"!=typeof s)return;const t=o;let e;for(;this._deprecatedHooks[o];)"string"==typeof(e=this._deprecatedHooks[o])&&(e={to:e}),o=e.to;e&&(e.message?this._logger.warn(e.message):this._logger.warn(`${t} hook has been deprecated`+(e.to?`, please use ${e.to}`:""))),this._hooks[o]=this._hooks[o]||[],this._hooks[o].push(s)}deprecateHook(o,s){this._deprecatedHooks[o]=s}deprecateHooks(o){Object.assign(this._deprecatedHooks,o)}addHooks(o){const s=flatHooks(o);for(const o in s)this.hook(o,s[o])}async callHook(o,...s){if(this._hooks[o])try{await serial(this._hooks[o],o=>o(...s))}catch(s){"error"!==o&&await this.callHook("error",s),this._logger.fatal?this._logger.fatal(s):this._logger.error(s)}}clearHook(o){o&&delete this._hooks[o]}clearHooks(){this._hooks={}}}module.exports=Hookable;
//# sourceMappingURL=hable.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"hable.js","sources":["../src/utils.js","../src/hable.js"],"sourcesContent":["export function flatHooks (configHooks, hooks = {}, parentName) {\n for (const key in configHooks) {\n const subHook = configHooks[key]\n const name = parentName ? `${parentName}:${key}` : key\n if (typeof subHook === 'object' && subHook !== null) {\n flatHooks(subHook, hooks, name)\n } else {\n hooks[name] = subHook\n }\n }\n return hooks\n}\n\nexport function serial (tasks, fn) {\n return tasks.reduce((promise, task) => promise.then(previous => fn(task, previous)), Promise.resolve(null))\n}\n","import { serial, flatHooks } from './utils'\n\nexport default class Hookable {\n constructor (logger = console) {\n this._logger = logger\n this._hooks = {}\n this._deprecatedHooks = {}\n\n // Allow destructuring hook and callHook functions out of instance object\n this.hook = this.hook.bind(this)\n this.callHook = this.callHook.bind(this)\n }\n\n hook (name, fn) {\n if (!name || typeof fn !== 'function') {\n return\n }\n\n const originalName = name\n let deprecatedHook\n while (this._deprecatedHooks[name]) {\n deprecatedHook = this._deprecatedHooks[name]\n if (typeof deprecatedHook === 'string') {\n deprecatedHook = { to: deprecatedHook }\n }\n name = deprecatedHook.to\n }\n if (deprecatedHook) {\n if (!deprecatedHook.message) {\n this._logger.warn(\n `${originalName} hook has been deprecated` +\n (deprecatedHook.to ? `, please use ${deprecatedHook.to}` : '')\n )\n } else {\n this._logger.warn(deprecatedHook.message)\n }\n }\n\n this._hooks[name] = this._hooks[name] || []\n this._hooks[name].push(fn)\n }\n\n deprecateHook (old, name) {\n this._deprecatedHooks[old] = name\n }\n\n deprecateHooks (deprecatedHooks) {\n Object.assign(this._deprecatedHooks, deprecatedHooks)\n }\n\n addHooks (configHooks) {\n const hooks = flatHooks(configHooks)\n for (const key in hooks) {\n this.hook(key, hooks[key])\n }\n }\n\n async callHook (name, ...args) {\n if (!this._hooks[name]) {\n return\n }\n try {\n await serial(this._hooks[name], fn => fn(...args))\n } catch (err) {\n if (name !== 'error') {\n await this.callHook('error', err)\n }\n if (this._logger.fatal) {\n this._logger.fatal(err)\n } else {\n this._logger.error(err)\n }\n }\n }\n\n clearHook (name) {\n if (name) {\n delete this._hooks[name]\n }\n }\n\n clearHooks () {\n this._hooks = {}\n }\n}\n"],"names":["flatHooks","configHooks","hooks","parentName","key","subHook","name","serial","tasks","fn","reduce","promise","task","then","previous","Promise","resolve","Hookable","constructor","logger","console","_logger","_hooks","_deprecatedHooks","hook","this","bind","callHook","originalName","deprecatedHook","to","message","warn","push","deprecateHook","old","deprecateHooks","deprecatedHooks","Object","assign","addHooks","args","err","fatal","error","cl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KJ,QAAQsB,WACVtB,QAAQsB,MAAMD,QAEdrB,QAAQuB,MAAMF,IAKzBG,UAAWvC,GACLA,UACKmB,KAAKH,OAAOhB,GAIvBwC,kBACOxB,OAAS"}
+2
View File
@@ -0,0 +1,2 @@
!function(o,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(o=o||self).hable=e()}(this,function(){"use strict";return class{constructor(o=console){this._logger=o,this._hooks={},this._deprecatedHooks={},this.hook=this.hook.bind(this),this.callHook=this.callHook.bind(this)}hook(o,e){if(!o||"function"!=typeof e)return;const t=o;let s;for(;this._deprecatedHooks[o];)"string"==typeof(s=this._deprecatedHooks[o])&&(s={to:s}),o=s.to;s&&(s.message?this._logger.warn(s.message):this._logger.warn(`${t} hook has been deprecated`+(s.to?`, please use ${s.to}`:""))),this._hooks[o]=this._hooks[o]||[],this._hooks[o].push(e)}deprecateHook(o,e){this._deprecatedHooks[o]=e}deprecateHooks(o){Object.assign(this._deprecatedHooks,o)}addHooks(o){const e=function o(e,t={},s){for(const i in e){const r=e[i],h=s?`${s}:${i}`:i;"object"==typeof r&&null!==r?o(r,t,h):t[h]=r}return t}(o);for(const o in e)this.hook(o,e[o])}async callHook(o,...e){var t,s;if(this._hooks[o])try{await(t=this._hooks[o],s=(o=>o(...e)),t.reduce((o,e)=>o.then(o=>s(e,o)),Promise.resolve(null)))}catch(e){"error"!==o&&await this.callHook("error",e),this._logger.fatal?this._logger.fatal(e):this._logger.error(e)}}clearHook(o){o&&delete this._hooks[o]}clearHooks(){this._hooks={}}}});
//# sourceMappingURL=hable.umd.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"hable.umd.js","sources":["../src/hable.js","../src/utils.js"],"sourcesContent":["import { serial, flatHooks } from './utils'\n\nexport default class Hookable {\n constructor (logger = console) {\n this._logger = logger\n this._hooks = {}\n this._deprecatedHooks = {}\n\n // Allow destructuring hook and callHook functions out of instance object\n this.hook = this.hook.bind(this)\n this.callHook = this.callHook.bind(this)\n }\n\n hook (name, fn) {\n if (!name || typeof fn !== 'function') {\n return\n }\n\n const originalName = name\n let deprecatedHook\n while (this._deprecatedHooks[name]) {\n deprecatedHook = this._deprecatedHooks[name]\n if (typeof deprecatedHook === 'string') {\n deprecatedHook = { to: deprecatedHook }\n }\n name = deprecatedHook.to\n }\n if (deprecatedHook) {\n if (!deprecatedHook.message) {\n this._logger.warn(\n `${originalName} hook has been deprecated` +\n (deprecatedHook.to ? `, please use ${deprecatedHook.to}` : '')\n )\n } else {\n this._logger.warn(deprecatedHook.message)\n }\n }\n\n this._hooks[name] = this._hooks[name] || []\n this._hooks[name].push(fn)\n }\n\n deprecateHook (old, name) {\n this._deprecatedHooks[old] = name\n }\n\n deprecateHooks (deprecatedHooks) {\n Object.assign(this._deprecatedHooks, deprecatedHooks)\n }\n\n addHooks (configHooks) {\n const hooks = flatHooks(configHooks)\n for (const key in hooks) {\n this.hook(key, hooks[key])\n }\n }\n\n async callHook (name, ...args) {\n if (!this._hooks[name]) {\n return\n }\n try {\n await serial(this._hooks[name], fn => fn(...args))\n } catch (err) {\n if (name !== 'error') {\n await this.callHook('error', err)\n }\n if (this._logger.fatal) {\n this._logger.fatal(err)\n } else {\n this._logger.error(err)\n }\n }\n }\n\n clearHook (name) {\n if (name) {\n delete this._hooks[name]\n }\n }\n\n clearHooks () {\n this._hooks = {}\n }\n}\n","export function flatHooks (configHooks, hooks = {}, parentName) {\n for (const key in configHooks) {\n const subHook = configHooks[key]\n const name = parentName ? `${parentName}:${key}` : key\n if (typeof subHook === 'object' && subHook !== null) {\n flatHooks(subHook, hooks, name)\n } else {\n hooks[name] = subHook\n }\n }\n return hooks\n}\n\nexport function serial (tasks, fn) {\n return tasks.reduce((promise, task) => promise.then(previous => fn(task, previous)), Promise.resolve(null))\n}\n"],"names":["constructor","logger","console","_logger","_hooks","_deprecatedHooks","hook","this","bind","callHook","name","fn","originalName","deprecatedHook","to","message","warn","push","deprecateHook","old","deprecateHooks","deprecatedHooks","Object","assign","addHooks","configHooks","hooks","flatHooks","parentName","key","subHook","args","tasks","reduce","promise","task","then","previous","Promise","resolve","err","fatal","error","clearHook","clearHooks"],"mappings":"wMAGEA,YAAaC,EAASC,cACfC,QAAUF,OACVG,OAAS,QACTC,iBAAmB,QAGnBC,KAAOC,KAAKD,KAAKE,KAAKD,WACtBE,SAAWF,KAAKE,SAASD,KAAKD,MAGrCD,KAAMI,EAAMC,OACLD,GAAsB,mBAAPC,eAIdC,EAAeF,MACjBG,OACGN,KAAKF,iBAAiBK,IAEG,iBAD9BG,EAAiBN,KAAKF,iBAAiBK,MAErCG,EAAiB,CAAEC,GAAID,IAEzBH,EAAOG,EAAeC,GAEpBD,IACGA,EAAeE,aAMbZ,QAAQa,KAAKH,EAAeE,cAL5BZ,QAAQa,QACRJ,8BACFC,EAAeC,mBAAqBD,EAAeC,KAAO,WAO5DV,OAAOM,GAAQH,KAAKH,OAAOM,IAAS,QACpCN,OAAOM,GAAMO,KAAKN,GAGzBO,cAAeC,EAAKT,QACbL,iBAAiBc,GAAOT,EAG/BU,eAAgBC,GACdC,OAAOC,OAAOhB,KAAKF,iBAAkBgB,GAGvCG,SAAUC,SACFC,ECnDH,SAASC,EAAWF,EAAaC,EAAQ,GAAIE,OAC7C,MAAMC,KAAOJ,EAAa,OACvBK,EAAUL,EAAYI,GACtBnB,EAAOkB,KAAgBA,KAAcC,IAAQA,EAC5B,iBAAZC,GAAoC,OAAZA,EACjCH,EAAUG,EAASJ,EAAOhB,GAE1BgB,EAAMhB,GAAQoB,SAGXJ,EDyCSC,CAAUF,OACnB,MAAMI,KAAOH,OACXpB,KAAKuB,EAAKH,EAAMG,mBAITnB,KAASqB,GC5CpB,IAAiBC,EAAOrB,KD6CtBJ,KAAKH,OAAOM,aC7CGsB,EDiDLzB,KAAKH,OAAOM,GCjDAC,EDiDOA,CAAAA,GAAMA,KAAMoB,IChDzCC,EAAMC,OAAO,CAACC,EAASC,IAASD,EAAQE,KAAKC,GAAY1B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