hable.js.map 4.2 KB

1
  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","clearHook","clearHooks"],"mappings":"aAAO,SAASA,UAAWC,EAAaC,EAAQ,GAAIC,OAC7C,MAAMC,KAAOH,EAAa,OACvBI,EAAUJ,EAAYG,GACtBE,EAAOH,KAAgBA,KAAcC,IAAQA,EAC5B,iBAAZC,GAAoC,OAAZA,EACjCL,UAAUK,EAASH,EAAOI,GAE1BJ,EAAMI,GAAQD,SAGXH,EAGF,SAASK,OAAQC,EAAOC,UACtBD,EAAME,OAAO,CAACC,EAASC,IAASD,EAAQE,KAAKC,GAAYL,EAAGG,EAAME,IAAYC,QAAQC,QAAQ,aCZlFC,SACnBC,YAAaC,EAASC,cACfC,QAAUF,OACVG,OAAS,QACTC,iBAAmB,QAGnBC,KAAOC,KAAKD,KAAKE,KAAKD,WACtBE,SAAWF,KAAKE,SAASD,KAAKD,MAGrCD,KAAMlB,EAAMG,OACLH,GAAsB,mBAAPG,eAIdmB,EAAetB,MACjBuB,OACGJ,KAAKF,iBAAiBjB,IAEG,iBAD9BuB,EAAiBJ,KAAKF,iBAAiBjB,MAErCuB,EAAiB,CAAEC,GAAID,IAEzBvB,EAAOuB,EAAeC,GAEpBD,IACGA,EAAeE,aAMbV,QAAQW,KAAKH,EAAeE,cAL5BV,QAAQW,QACRJ,8BACFC,EAAeC,mBAAqBD,EAAeC,KAAO,WAO5DR,OAAOhB,GAAQmB,KAAKH,OAAOhB,IAAS,QACpCgB,OAAOhB,GAAM2B,KAAKxB,GAGzByB,cAAeC,E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