1.0.1 • Published 3 years ago

sails-hook-custom-events v1.0.1

Weekly downloads
10
License
MIT
Repository
github
Last release
3 years ago

Sails Hook Custom Events

Simple asynchronous emitter and event observer thanks to the emittery library.

Getting Started

Install it via npm:

npm install sails-hook-custom-events --save

Create a directory structure:

.
├── api/
│   ├── ...
│   ├── observers/
│   │   ├── event-name-1/
│   │   │   ├── observer-name-1.js
│   │   │   ├── observer-name-2.js
│   │   │   └── ... 
│   │   ├── event-name-2/
│   │   └── ... 
|   └── ... 
└── ...

Events and observers are automatically discovered based on the directory structure. Their names can be anything.

The observer must return the function:

module.exports = function (data) {

};

Emitting an event:

sails.hooks.events.emit('event-name-1', { ... });

License

MIT