hooksjs

0.0.2 • Public • Published

hooksjs

Generic Hooks and Triggers

Runs a stack of new functions before or after (pre / post) of the original function

Install

npm install hoohsjs

See live example:

See the Pen HooksJS by Joo Neto (@joaoneto) on CodePen.

Examples

Write some code

class Model {
  save() {
    return { success: true };
  }
}
 
const model = new Model();

Wrap it

const modelHooks = new Hooks(model);

Add some hooks pre / post

modelHooks
  .pre('save', preSave1)
  .pre('save', preSave2);
 
modelHooks
  .post('save', postSave1)
  .post('save', postSave2);

Run it, the pre and post stack makes magic

model.save();
 

/hooksjs/

    Package Sidebar

    Install

    npm i hooksjs

    Weekly Downloads

    1

    Version

    0.0.2

    License

    MIT

    Last publish

    Collaborators

    • joaoneto