GithubHelp home page GithubHelp logo

isabella232 / emissary-2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from atom-archive/emissary

0.0 0.0 0.0 579 KB

Node mixins for subscribing to and emitting events *no longer maintained*

License: MIT License

CoffeeScript 100.00%

emissary-2's Introduction

Emissary โ€“ Mixins for Events Build Status

Achtung! This library is currently used in Atom and various Atom dependencies, but our long-term plan is to transition away from it in favor of the simpler event-kit library. Don't depend on supporting this library forever.

Achtung Again! The Subscriber mixin requires ES6 Harmony WeakMaps. To enable them, run your program with the node --harmony_collections flag. If you're using it in a node framework such as jasmine, run its script with the flag enabled as follows: node --harmony-collections .bin/jasmine-node specs.

Emitter

Emitter is backward-compatible with Node's event emitter, but offers more functionality. You can construct standalone Emitter instances or use it as a mixin.

  • Emitter.extend(object) Turns the given object into an emitter by adding the appropriate methods.

  • Emitter.includeInto(class) Turns the class into an emitter by extending its prototype.

  • ::on(eventNames, handler) Subscribe to one or more events. Events names are separated by spaces, and can optionally be namespaced with a dot-suffix. E.g. event1 event2.namespace.

  • ::once(eventName, handler) Like ::on, but only fires the handler once before unsubscribing automatically.

  • ::off(eventNames[, handler]) Unsubscribe to one or more events. Event names are separated by spaces. Passing a non-namespaced event name unsubscribes from every namespace for that event. Passing only a namespace unsubscribes from that entire namespace. Passing a handler removes only a subscription corresponding to the given event name(s) and that handler.

  • ::emit(eventName[, data...]) Emit an event with the given name. If the event name is namespaced, only calls handlers for the event associated with the namespace, otherwise it fires all handlers. Handlers are called with zero or more data arguments provided after the event name.

  • ::pauseEvents() Buffers events instead of emitting them until ::resumeEvents is called.

  • ::resumeEvents() Emits all events buffered since pausing and resumes normal emitting behavior.

  • ::getSubscriptionCount() Get the total number of handlers registered on the emitter.

Subscriber

Subscriber works in partnership with an emitter or any object supporting subscription cancellation with .off. This includes standard Node event emitters and jQuery objects.

  • ::subscribe(object, eventNames, handler) Subscribe to the given event name(s) on the given object.

  • ::subscribeWith(object, methodName, eventNames, handler) Subscribe to the given object with a method other than .on.

  • ::unsubscribe([object]) Cancel subscriptions previously registered with ::subscribe. If an object is given, only unsubscribe from that object. If called without an object, unsubscribe from everything.

emissary-2's People

Contributors

kevinsawicki avatar liuxiong332 avatar peterdavehello avatar samypesse avatar termina1 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.