Giter Site home page Giter Site logo

event-box's Introduction

event-box

event-box is an alternative to node's built in EventEmitter. It exposes a similar API but is not intended to be a drop-in replacement; some differences exist.

Hierarchical Events

event-box supports hierarchical events, using : as a separator. If event foo:bar:baz is emitted, listeners for foo:bar:baz, foo:bar and foo will all be triggered.

Installation

Get it:

npm install event-box

Require it:

var EventBox = require('event-box');

API

Creation

var box = new EventBox()

Create a new EventBox.

util.inherits(MyConstructor, EventBox)

It's also possible for your own constructors to inherit from EventBox.

box.on(ev, cb, [ctx])

Register callback cb to be called when event ev is emitted, using optional this context ctx. Returns a callback that can later be passed off() to remove the listener.

box.on_c(ev, cb, [ctx])

As above but instead returns a cancellation function that can be used to remove the event listener.

box.once(ev, cb, [ctx])

Register callback cb to be called the next time event ev is emitted, using optional this context ctx. After being called once the listener is then automatically removed. Returns a callback that can later be passed off() to remove the listener.

box.once_c(ev, cb, [ctx])

As above but instead returns a cancellation function that can be used to remove the event listener.

box.off()

Remove all event bindings.

box.off(ev)

Remove all event bindings for event ev.

box.off(ev, cb)

Remove the single binding cb for event ev.

box.bind(obj, [events])

Bind all functions contained in obj as listeners for the events denoted by their respective keys. For example:

box.bind({
	foo: doFoo,
	bar: doBar
});

is equivalent to:

box.on('foo', doFoo, obj);
box.on('bar', doBar, obj);

Attached functions will be called in the context of the bound object.

The optional argument events can be used to specify the handlers which should be plucked from the supplied object, otherwise all functions found in the object will be attached.

box.bind_c(obj, [events])

As above but returns a cancellation function that can be used to remove the object binding.

box.unbind(obj)

Unbind all functions previously bound to this EventBox via call to bind().

box.emit(ev, args...)

Emit event ev with event arguments specified as successive function arguments.

box.emitArray(ev, args)

Emit event ev with event arguments specified as an array.

box.emitAfter(delay, ev, args...)

Emit event ev after delay milliseconds. Event arguments are specified as successive function arguments. Returns a function that can be used to cancel the event emission before it occurs.

box.emitEvery(interval, ev, args...)

Emit event ev every delay milliseconds. Event arguments are specified as successive function arguments. Returns a function that can be used to cancel the event emission.

Copyright & License

© 2014 Jason Frame [ @jaz303 / [email protected] ]

Released under the ISC license.

event-box's People

Stargazers

timelyportfolio avatar

Watchers

Jason Frame avatar timelyportfolio avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.