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

generate-js-events

Package Overview
Dependencies
Maintainers
2
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

generate-js-events

A generator for EventEmitter, lets you create an objects that can emit events.

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-16.67%
Maintainers
2
Weekly downloads
 
Created
Source

Generate-JS-Events

GitHub release npm version npm downloads npm downloads

Table of Contents

EventEmitter

A generator for EventEmitter, lets you create an objects that can emit events, or generate a new generator that inherits from EventEmitter.

Install:

$ npm install generate-js-events

new EventEmitter()

  • return: Object A new object that inherits from EventEmitter.

Creates a new object that inherits from EventEmitter.

Example:

var EventEmitter = require('generate-js-events');

var myEmitter = new EventEmitter();

EventEmitter.generate(create)

  • create Function Create method that gets called when creating a new object that inherits from EventEmitter.
  • return: Generator A new generator that inherits from EventEmitter.

Returns a new generator that inherits from EventEmitter.

Example:

var myGenerator = EventEmitter.generate(
	/* create method */
	function myGenerator() {
		// my create code here
	}
);

myGenerator.definePrototype(
	{
		// my descriptor here
	},
	{
		// my prototype here
	}
);

Class: Generation

A new generator that inherits from the generator that generated it using the EventEmitter.generate(create) method.

Class: Creation

A new object that inherits from the generator that created it using the new EventEmitter() method.

Creation.on(event, listener[, observer]

  • event String Name of event.
  • listener Function Event handler function.
  • observer Object Object reference for binding.
  • return: Object This object.

Adds a 'listener' on 'event' to this EventEmitter instance.

Example:

/*
 * Set lestener.
 * NOTE: myEmitter.off('error') does not remove *this* listener.
 */
myEmitter.onerror = function (err) {
	console.log(err);
}

/*
 * Add listener.
 */
myEmitter.on('myevent', function(a, b, c) {
	console.log(a, b, c);
});

Creation.once(event, listener[, observer])

  • event String Name of event.

  • listener Function Event handler function.

  • observer Object Object reference for binding.

  • return: Object This object.

Adds a 'listener' on 'event' to this EventEmitter instance which is removed after one 'event'.

Example:

/*
 * Add one-time listener.
 */
myEmitter.once('myobjectevent', function(event) {
	console.log(event);
});

Creation.off([event][, listener][, observer])

  • event String Name of event.
  • listener Function Event handler function.
  • observer Object Object reference for binding.
  • return: Object This object.

Removes a 'listener' on 'event', or all listeners on 'event', or all listeners from this EventEmitter instance.

Example:

/*
 * Remove specific listener.
 */
function specific(event) {
	console.log(event);
}

myEmitter.on('specific', specific);

myEmitter.off('specific', specific);

/*
 * Remove all listeners on same event.
 */
myEmitter.off('same');

/*
 * Remove All listeners.
 */
myEmitter.off();

Creation.emit(event, [...args])

  • event String Name of event.
  • args Arguments All other arguments to be emitted to listeners.
  • return: Object This object.

Emits an 'event' with 'args' on this EventEmitter instance.

Example:

/*
 * Emits 1, 2, 3 on 'myevent' listener(s).
 */
myEmitter.emit('myevent', 1, 2, 3);

Creation.emitEvent(event, eventObject)

  • event String Name of event.
  • eventObject Object An event object to be emitted to listeners.
  • return: Object This object.

Emits an event object containing 'eventObject' on this EventEmitter instance.

Example:

/*
 * Emits {eventData: 'data'} on 'myobjectevent' listener(s).
 */
myEmitter.emitEvent('myobjectevent', {eventData: 'data'});

Keywords

FAQs

Package last updated on 09 Jan 2017

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