Hable

A simpler tapable alternative, which can be used to create hooks for plugins.
Install
>_ yarn add hable
>_ npm install hable
Usage
Extend your base class from Hable:
import Hookable from 'hable'
export default class MyLib extends Hookable {
constructor() {
super()
}
async someFunction() {
await this.callHook('foo')
await this.callHookAsync('bar')
}
}
Inside plugins, register for any hook:
const lib = new MyLib()
lib.hook('foo', async () => { })
lib.hookObj({
foo: async () => { },
bar: [ ]
})
API
Class functions
async callHook(name, ...args)
: Used by class itself to sequentially call handlers of a specific hook.async callHookAsync(name, ...args)
: Same as callHook
but calls handlers in parallel.hook(name, fn)
: Used by plugins to register a handler for an specific hook. fn
can be a single function or an array.hookObj(hooksObj)
: Register many hook using an object.
Class attributes
$hooks
: An object which maps from each hook name to it's handlers.
Credits
Extracted from Nuxt.js hooks system. Original author: Sébastien Chopin.
License
MIT