Events
Durandal events originate from backbone.js but also combine some ideas from signals.js as well as some additional improvements.
Events can be added to any object. By default they are added to the app module for use as an application-wide event aggregator. Every object that has events installed has the following functions:
function on(events, callback, context)- The events parameter is a space delimited string containing one or more event identifiers. When one of these events is triggered, the callback is called and passed the event data provided by the trigger. The special events value of "all" binds all events on the object to the callback. If a context is provided, it will be bound to this for the callback. If the callback is omitted, then a promise-like object is returned from on. This object represents a subscription and has a then function used to register callbacks.function off(events, callback, context)- Unwires callbacks from events. If no context is specified, all callbacks with different contexts will be removed. If no callback is specified, all callbacks for the event will be removed. If no event is specified, all event callbacks on the object will be removed.function trigger(events, args...)- Triggers an event, or space-delimited list of events. Subsequent arguments to trigger will be passed along to the event callbacks.function proxy(events)- Provides a function which can be used as a callback to trigger the events. This is useful in combination with jQuery events which may need to trigger the aggregator's events.
You can install events into any object by invoking the events module function includeIn(targetObject). The events module can also be invoked itself with new in order to create a new event aggregator.