reactive event system for Meteor
CoffeeScript JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


A basic reactive event system for Meteor. I've found that I often want to have one or more callbacks run when the application's reactive state reaches a particular point (such as logged in). This framework allows you to do that with a (hopefully) simple event system. You can fire an event when a function's return value changes with EventHorizon.fireOnChange, when it becomes true (EventHorizon.fireWhenTrue) or equal to a particular EJSON value (EventHorizon.fireWhenEqual), or manually with You can then set up one or more event handler functions with EventHorizon.on. Here is some example usage:

  return Meteor.userId() !== null;

  console.log('The user just logged in.');

  console.log('This function will also run when the event is fired.');

// Session.truthTester(key) returns a function that returns Session.isTrue(key).
// Those helpers are defined in the session-extras library.


  console.log('Events can also be triggered manually');

// the event name is not directly tied to the Session key, just

  // the return value of the trigger function is made available in this.result for fireOnChange.
  console.log('new value of Session.get("changeMe"): '+this.result);

// will fire the 'change' event since we're changing the value here.
Session.set('changeMe','could you spare some change?');

// you can also fire events manually with data:'change',{result: 'change that you can believe in'});

The triggers and handlers for a particular event can all be stopped by running EventHorizon.removeEvent(eventName). \

NOTE: currently, if you remove an event from inside a handler for that event, then you must have run EventHorizon.fireWhenTrue or EventHorizon.fireWhenEqual before EventHorizon.on for that event; otherwise the event will not be properly removed.

This library works well with the session-extras library, which provides some closures like Session.getter that are useful for associating changes to Session variables with events.