@aneesijaz/jshooks

1.0.6 • Public • Published

@aneesijaz/jshooks

jshooks is a simple javascript module to create , listen and trigger hooks.

Installation

Using npm npm to install jshooks.

npm install @aneesijaz/jshooks

Usage

const Hooks = require('@aneesijaz/jshooks');
const triggerTimeout = 2000;
const hooks = new Hooks(triggerTimeout);
            
 // register a listener - note: 2nd parameter is priority higher priority means 1st to listen
hooks.listen('on_load', 1, (data, next) => {
    console.log("#2");
    data.saregama = 'saregama';
    next(data);
});

 // register a listener
hooks.listen('on_load', 2, (data, next) => {
    console.log("#1");
    data.padanisa = 'padanisa';
    next(data);
});

setTimeout(() => {
    let dataSent = { padanisa: 'saregama' };

    // before data
    console.log("BEFORE DATA", dataSent);

    // trigget hook with the data
    hooks.trigger('on_load', dataSent).then(data => {

        // after the listeners has modified data
        console.log("FINAL DATA", data);

    }).catch(err => console.log(err));
    
}, 2000);

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

Support

Follow me to show your support. Facebook Twitter Fasterbyte Instagram

Package Sidebar

Install

npm i @aneesijaz/jshooks

Weekly Downloads

0

Version

1.0.6

License

MIT

Unpacked Size

7.71 kB

Total Files

8

Last publish

Collaborators

  • aneesijaz