hable.umd.js 1.3 KB

12
  1. !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={}}}});
  2. //# sourceMappingURL=hable.umd.js.map