Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

event-handle

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

event-handle

Events with closures.

  • 1.0.5
  • unpublished
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

EventHandle [ NPM ]

JavaScript event pattern with closures. (Built with Typescript!)

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

Default Export

EventHandle

Events with closures.

Function Exports

createEventHandle([config])function

Returns a function that triggers an event. The function has members such as .handle() to add a handler, .id (a string), .handlerCount() and .removeAllHandlers().

isEventHandle(fn)boolean

Returns true if fn is a function created by createEventHandle.

onEvent(evt, handler, [options])function

Adds a handler to the given event.

EventHandle

Events with closures.

Kind: global variable

EventHandle.create ⇒ function

Returns a function that triggers an event. The function has members such as .handle() to add a handler, .id (a string), .handlerCount() and .removeAllHandlers().

Kind: static property of EventHandle
Returns: function - The event.

ParamTypeDescription
[config]EventHandleConfiguration | stringEvent id or configuration.

EventHandle.isEventHandle ⇒ boolean

Returns true if fn is a function created by createEventHandle.

Kind: static property of EventHandle
Returns: boolean - True if the given fn is an EventHandle.

ParamTypeDescription
fnfunctionThe function to check.

EventHandle.on ⇒ function

Adds a handler to the given event.

Kind: static property of EventHandle
Returns: function - A function to remove the handler.

ParamTypeDescription
evtfunctionThe event to add a handler to.
handlerfunctionThe handler function for the event.
[options]EventHandlerOptionsOptions for the handler.

createEventHandle([config]) ⇒ function

Returns a function that triggers an event. The function has members such as .handle() to add a handler, .id (a string), .handlerCount() and .removeAllHandlers().

Kind: global function
Returns: function - The event.

ParamTypeDescription
[config]EventHandleConfiguration | stringEvent id or configuration.

isEventHandle(fn) ⇒ boolean

Returns true if fn is a function created by createEventHandle.

Kind: global function
Returns: boolean - True if the given fn is an EventHandle.

ParamTypeDescription
fnfunctionThe function to check.

onEvent(evt, handler, [options]) ⇒ function

Adds a handler to the given event.

Kind: global function
Returns: function - A function to remove the handler.

ParamTypeDescription
evtfunctionThe event to add a handler to.
handlerfunctionThe handler function for the event.
[options]EventHandlerOptionsOptions for the handler.

FAQs

Package last updated on 11 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc