Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@peepso/hooks

rsusanto16MIT1.0.3

WordPress-like filter and action hooks implementation.

peepso, wordpress, hooks

readme

Hooks

WordPress-like filter and action hooks implementation.

Installation

npm install @peepso/hooks --save

Usage

import Hooks from '@peepso/hooks';

// You can instantiate it manually like in the example below:
let hooks = new Hooks();
hooks.addAction( 'actionName', 'fnName', ( ...args ) => console.log( args ) );

// Or, you can extend it to another class:
class Person extends Hooks {
    constructor() {
        this.addAction( 'actionName', 'fnName', ( ...args ) => console.log( args ) );
    }
}

Methods

Filter methods

addFilter( filterName, handlerName, handler, [priority=10] )
removeFilters( filterName, [handlerName, [handler]] )
applyFilters( filterName, ...args )

Action methods

addAction( actionName, handlerName, handler, [priority=10] )
removeActions( actionName, [handlerName, [handler]] )
doAction( actionName, ...args )