1.0.6 • Published 6 years ago

event-handle v1.0.6

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

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

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago