Skip to content

A simple javascript module to create , listen and trigger hooks

License

Notifications You must be signed in to change notification settings

aneesijaz/jshooks

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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

About

A simple javascript module to create , listen and trigger hooks

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published