New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

jkroso-emitter

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jkroso-emitter

Basic event emitter

  • 0.4.0
  • latest
  • Source
  • npm
  • Socket score

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

Emitter

A simple event emitter. I implemented my own so I could optimise for performance and implement new features as I require. The main advantage of this implementation is its handling of context. It allows you to specify a context when you create a subscription (a la backbone.js) but also takes this into account when unsubscribing. So when unsubscribing you have three levels of specificity available to you. topic(s), topic(s)+callback, and topic(s)+callback+context. This makes it possible to work with methods defined on an objects prototype without wrapping them since you now have a way of differentiating between subscriptions belonging to different instances.

Getting Started

Download the production version or the development version.

With component

$ component install jkroso/emitter

with npm

$ npm install jkroso/emitter

API

Emitter()

Generate an instance of Emitter

var emitter = new Emitter

Emitter.new()

An alternative constructor syntax

Emitter.mixin(obj:Object)

Add emitter behavior to any object

proto.emit

Generate an event

emitter.emit('event', new Date)

proto.on(topics:String, callback:Function, context:Object)

Add a subscription under a topic name

emitter.on('event', function(data){})
emitter.on('a | b', function(data){})

proto.once()

Add the subscription but insure it never called more than once

proto.off([topics]:String, [callback]:Function, [context]:Any)

Remove subscriptions

emitter.off() // clears all topics
emitter.off('topic') // clears all handlers under 'topic'
emitter.off('topic', fn) // removes fn from 'topic'
emitter.off('topic', fn, window) // removes fn from 'topic' with context of `window`

Contributing

Throw down!

Release History

(Nothing yet)

License

Copyright (c) 2012 Jakeb Rosoman
Licensed under the MIT license.

Keywords

FAQs

Package last updated on 28 Dec 2012

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