simple event emitter.
- Small - The source code is less than 100 lines. After minified and gzipped, only 450B.
- Simple - Only 4 api, but it can solve most of the scenes.
- Cross platform - It can work on nodejs, browser...
npm i emitry
or
<script src="/path/emitry.umd.min.js"></script>
var emitry = new Emitry();
import Emitry from 'emitry';
const emitry = new Emitry();
Subscribe to an event.
emitry.on('oh', (value1, value2) => {
console.log(value1, value2);
});
Subscribe to an event. Only trigger once, after triggered will remove from events list.
emitry.once('oh', (value1, value2) => {
console.log(value1, value2);
});
Emit an event.
emitry.emit('oh', 'my god', 'my dear'); // 'mygod' 'my dear
Remove a listener from the listener array for the specified event.
emitry.off('oh', (value1, value2) => {
console.log(value1, value2);
});
Remove specify events by a list of names.
emitry.off(['a', 'b']);
Remove all events.
emitry.off();