event-handle
Events with closures.
npmjs.com
Install
npm install event-handle
or yarn add event-handle
Import
import EventHandle from 'event-handle';
import {
createEventHandle,
isEventHandle,
onEvent,
} from 'event-handle';
const EventHandle = require('event-handle');
Example
let demoStarted = EventHandle.create();
EventHandle.on(demoStarted, (...args) => {
console.log('The demo started!', args)
});
let remove = demoStarted.handle((...args) => {
console.log('Got it...', args);
});
demoStarted('a','r','g','s');
console.log('removed: ', remove());
console.log('handlerCount: ', demoStarted.handlerCount());
console.log('id: ', demoStarted.id);
console.log('isEventHandle: ', EventHandle.isEventHandle(demoStarted));
console.log('removeAllHandlers: ', demoStarted.removeAllHandlers());
See also:
- Test code in
spec/index.spec.ts
- Example code in
examples/
API
See: docs/API.md