Migrated, see @vzt7/unhook.
Can be used to create hooks for plugins.
- ✅ Get all returns of each hook.
- ✅ Types friendly, specify the hook type you want.
- ✅ Almost likes tapable, more light & clear.
# with pnpm
pnpm install patable
# with yarn
yarn add patable
# with npm
npm install patable
Almost refer to tapable.
- AsyncParallelBailHook
- AsyncParallelHook
- AsyncSeriesBailHook
- AsyncSeriesHook
- AsyncSeriesWaterfallHook
- TODO: Sync hooks
import { AsyncSeriesHook } from 'patable';
const hook = new AsyncSeriesHook();
hook.tap('say', () => {
console.log('Hello World');
});
hook.tap('scream', () => {
console.log('Hello World!!!');
});
hook.dispatch();
// Hello World
// Hello World!!!
Only the dispatch method is different implementation for each hook, and all hooks follow the usage below.
import { AsyncSeriesHook } from 'patable';
const hook = new AsyncSeriesHook<(arg0: string) => string>();
hook.tap({ name: 'say', once: true }, (arg0) => {
console.log('Hello World');
});
hook.tap('scream', (arg0) => {
console.log('Hello World!!!');
return 'screaming';
});
hook.tap({ name: 'smile', stage: -10 }, async (arg0) => {
return 'smiling';
});
hook.tap({ name: 'silent', before: 'scream' }, (arg0) => {
console.log(arg0);
});
hook.dispatch('Anyone else').then((result) => {
console.log(result); // ['smiling', undefined, undefined, 'screaming'];
});
// Hello World
// Anyone else
// Hello World!!!
- Clone this repository
- Enable Corepack using
corepack enable
(usenpm i -g corepack
for Node.js < 16.10) - Install dependencies using
pnpm install
- Run interactive tests using
pnpm dev
Published under WTFPL.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.