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

hear

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hear

Listen to any event emitter, with a single API.

  • 1.0.1
  • Source
  • npm
  • Socket score

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

hear

Listen to any event emitter with a single API.

.on, .addEventListener, .subscribe, ... Why are there so many method names ?

hear is an "universal binder" that allows you to use one method name with the different event emitters, whether it is a DOM node, Node EventEmitter, mediator... You can also pass a context and hear will handle this for you (no bind leak).

Supported emitter types

  • DOM nodes
  • jQuery events
  • Angular & Vue internal emitters
  • Google Maps events
  • Basically all objects with on/off methods. See events.js for API support list.

Installation & usage

npm i --save hearjs

var hear = require('hearjs');

var emitter = new EventEmitter();
var mediator = new Mediator();

function MyType() {
  hear($node, 'click', onEvent, this); // document.querySelector('.node');
  hear(emitter, 'onClick', onEvent, this); // EventEmitter
  hear(mediator, 'onClick', onEvent, this); // Mediator
}

MyType.prototype.onEvent = function() {
  // ...
};

API

  • hear.on(emitter, eventName, fn, context) listen eventName on the emitter.

  • hear.once(emitter, eventName, fn, context) like .on but is unbound after first call.

  • hear.off(emitter, eventName, fn, context) Unbind an event listener. If supported by the passed emitter:

    • if no fn is passed, all the eventName listeners will be unbound
    • if no eventName is passed, the emitter will be totally unbound

Contributing

Checkout from dev, merge back against dev. Add relevant test cases. 4 spaces, semicolon.

Todo

  • support off method without event/fn argument
  • add test with gmaps, angular/vue, jquery

Keywords

FAQs

Package last updated on 18 Apr 2015

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