Skip to content
millermedeiros edited this page Nov 27, 2010 · 12 revisions

JS-Signals

Custom event/messaging system for JavaScript inspired by AS3-Signals.

Introduction

A Signal is similar to an Event Emitter/Dispatcher or a Pub/Sub system, the main difference is that each event type has it's own controller and doesn't rely on strings to broadcast/subscribe to events. To know more about the differences check the Wiki page.

This implementation is heavily inspired by Robert Penner's AS3-Signals but it is not a direct port, it has a different set of features (some extras and some missing) and some methods were renamed to avoid confusions and/or for brevity.

The main focus for now is custom events, there are no plans to add native DOM events support yet (AS3-signals has a NativeSignal class that emulates native flash events) specially since most of the JavaScript frameworks already have some kind of facade on top of the native events.

Advantages

  • Doesn't rely on strings for subscribing/publishing to event types, reducing chances of error.
  • Arbitrary number of parameters to event handlers;
  • Convenience methods that usually aren't present on other implementations of the observer pattern like:
    • disable/enable event dispatching per event type.
    • remove all event listeners attached to specific event type.
    • option to automatically remove listener after first execution.
    • option to bind an execution context to the event handler, avoiding scope issues.
  • Favor composition over inheritance.
  • Easy to identify which event types the object dispatch.

Wiki Table of Contents

Clone this wiki locally