event-handle
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

event-handle

Events with closures.

npmjs.com

Install

npm install event-handle    or    yarn add event-handle

Import

import EventHandle from 'event-handle'; // ES6
import {              // ES6 Functional Import
  createEventHandle,
  isEventHandle,
  onEvent,
} from 'event-handle';
const EventHandle = require('event-handle'); // CommonJS / Node.js

Example

// Create an event.
let demoStarted = EventHandle.create();
 
// Create a handler.
EventHandle.on(demoStarted, (...args) => {
  console.log('The demo started!', args)
}); // options: , { prepend: false, once: false }
 
// Create another handler.
let remove = demoStarted.handle((...args) => {
  console.log('Got it...', args);
});
 
// Trigger the event, calling all handlers.
demoStarted('a','r','g','s');
 
// Remove the handler.
console.log('removed: ', remove());
 
// Other functions:
console.log('handlerCount: ', demoStarted.handlerCount());
console.log('id: ', demoStarted.id); // defined if create was passed an 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

Readme

Keywords

none

Package Sidebar

Install

npm i event-handle

Weekly Downloads

9

Version

1.0.6

License

MIT

Unpacked Size

13.8 kB

Total Files

6

Last publish

Collaborators

  • waynebloss