Sha256: e07aed9015ab2a1d93a2f6baa6e98dba71d6c265c0d96531b220d61a68b7135d
Contents?: true
Size: 1.25 KB
Versions: 1
Compression:
Stored size: 1.25 KB
Contents
###* Event bus for up-related events: - `app:ready` - `fragment:ready` with arguments `($fragment)` - `fragment:destroy` with arguments `($fragment)` TODO: This might eventually be rolled into regular document events. @class up.bus ### up.bus = (-> callbacksByEvent = {} callbacksFor = (event) -> callbacksByEvent[event] ||= [] ###* Registers an event handler to be called when the given event is triggered. @method up.bus.listen @param {String} eventName The event name to match. @param {Function} handler The event handler to be called with the event arguments. ### # We cannot call this function "on" because Coffeescript # https://makandracards.com/makandra/29733-english-words-that-you-cannot-use-in-coffeescript listen = (eventName, handler) -> callbacksFor(eventName).push(handler) ###* Triggers an event. @method up.bus.emit @param {String} eventName The name of the event. @param {Anything...} args The arguments that describe the event. ### emit = (eventName, args...) -> console.log("bus emitting", eventName, args) callbacks = callbacksFor(eventName) up.util.each(callbacks, (callback) -> callback(args...) ) return ( on: listen emit: emit ) )()
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
upjs-rails-0.1.0 | lib/assets/javascripts/up/bus.js.coffee |