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

hey-yall

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hey-yall

Basic event emitter

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-33.33%
Maintainers
1
Weekly downloads
 
Created
Source

hey-yall

An event emitter with southern charm.

  • Lightweight
  • Supports standard event emitter functionality
  • Browser and node.js support (browser support with Browserify or similar tool)
  • Standard event emitter functionality (i.e. on, off, emit, removeListener, etc.)
  • Single event listener registration with once

Install

npm install hey-yall

Creating emitters

  const makeEmitter = require('hey-yall');

  // Create an emitter object
  const emitter = makeEmitter();

Hey-Yall API

All emitter methods return the object on which they were called so that you can chain multiple method calls.

emitter.on(event, listener)

Adds an event listener to the emitter.

Arguments:

  • event: (String) key used to identify which events should trigger this listener
  • listener: (Function) the function to call when a matching event is emitted
  emitter.on('test', listener)  // Listen for 'test' events
  emitter.emit('test')     // listener function invoked

emitter.once(event, listener)

Adds an event listener but immediately removes the listener the first time it is triggered.

Arguments:

  • event: (String) key used to identify which events should trigger this listener
  • listener: (Function) the function to call when a matching event is emitted
  emitter.once('test', listener)  // Listen for one 'test' event
  emitter.emit('test')       // listener function invoked
  emitter.emit('test');   // listener function not invoked

emitter.off(event[, listener])

Removes listeners for the given event, optionally specifying a specific listener to remove. If listener is not passed then all listeners are removed.

Arguments:

  • event: (String) key used to identify which event's listeners to remove
  • listener: (Optional: Function) if specified then only listeners with this function as a listener will be removed
  emitter.on('test', listener1)  // Listen for 'test' events
  emitter.on('test', listener2)  // Listen for 'test' events
  emitter.emit('test')     // Listener1 and Listener2 are called for 'test' events
  emitter.off('test', listener1) // Remove the first listener
  emitter.emit('test')     // Listener2 for 'test' event is called  
  emitter.off('test')      // Remove the remaining listener
  emitter.emit('test');    // No listeners called

emitter.emit(event[, data...])

Emits an event and calls the listeners on all matching listeners. Additional data can be passed as arguments and they will be forwarded to listeners.

Arguments:

  • event: (String) key for which to emit to listeners
  emitter.on('test', listener)              // Listen for 'test' events
  emitter.emit('test')               // Listener invoked for 'test' events with no args
  emitter.emit('test', 'blah', 'badee', 'blah') // Listener invoked for 'test' events with 3 args of 'blah', 'badee', 'blah'

Keywords

FAQs

Package last updated on 29 Apr 2019

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