progress-hooks
The manager of sequential hooks to work with tapable
.
progress-hooks
applies the taps(plugins) only if the previous hook has been called.
Usually, it used to replace the code slice this.hooks = {}
of the tapable
example
Install
$ npm i progress-hooks
Usage
const SyncHook AsyncParallelHook } = const Hooks ADD CLEAN COUNT } = { // this.hooks = { // accelerate: new SyncHook(['newSpeed']), // brake: new SyncHook() // } // Instead of the code above, we create hooks by `new Hooks()` thishooks = accelerate: 'newSpeed' brake: hook: // The car needs to brake twice, then stop plan: 2 stop: } const car = let speed = 0 // The `LoggerPlugin` method is not actually tapped into the `car.hooks.brake`,// but instead, it is held by `progress-hooks`carhooksbrake carhooksstop // And it will not be calledcarhooksbrake carhooksaccelerate carhookaccelerate// And after `car.hook.accelerate.call()` is invoked,// The `LoggerPlugin` will be applied carhooksbrake// prints: 'brake' carhooksstop// nothing `console.log`ged, because of `plan: 2` carhooksbrakecarhooksstop// prints: stopped
new Hooks(rawHooks, options)
- rawHooks
{[string]: tapable.Hook | PlannedHook}
- options?
Object
- disableAfterCalled?
boolean=true
Iftrue
(the default value) the hook will be disabled after called.
- disableAfterCalled?
Returns hooks
The returned hooks
is a relatively clean object that we can get all hook names just with Object.keys(hooks)
:
Object// ['accelerate', 'brake']
hooks[ADD](name, hook): void
Adds a new hook.
const hooks = hooksADD'accelerate' 'newSpeed'
hooks[CLEAN](): void
Cleans hook taps if the hook is not enabled, so that we could reload plugins.
License
MIT