sails-hook-custom-events
v1.0.1
Published
Simple asynchronous emitter and event observer thanks to the `emittery` library.
Downloads
2
Readme
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', { ... });