Module: Core/Events

Events proxy object. For inter-component communications, please register your events and please subscribe to your events from the events hub. This reduces coupling between components.

Usage example:

const Events = require('core/Events');
var foo = {
    initialize: function() {
        // Register the event with the events hub.
        Events.register('mynamespaced:event', this);
    },
    action: function() {
        // Broadcast your event to the events hub.
        // The events hub will then broadcast this event to all its subscribers.
        this.trigger('mynamespaced:event');
    }
}

var bar = {
    initialize: function() {
        // Call a callback when the event is received.
        Events.on('mynamespaced:event', function() {
            alert('Event!');
        });
    }
}

Methods


<inner> on()

Wraps Backbone.Events#on to throw a warning if the event listened to is deprecated.


<inner> register(event, context [, options])

Registers an event with the event proxy.

Parameters:
Name Type Argument Description
event string

The name of the event. A good practice is to namespace your events with a colon. For example: app:start.

context Object

The object that will trigger the event.

options Object <optional>

Optional params.

Properties
Name Type Argument Default Description
deprecated boolean <optional>
false

true if the event is deprecated.

message string <optional>

The deprecation message to log. A default message will be triggered if not defined.


<inner> registerAjaxEvents()

Subscribes to global ajax events.


<inner> unregister(context [, event])

Unregisters an event from the event proxy.

Parameters:
Name Type Argument Description
context Object

Source to be cleared from.

event string <optional>

Name of the event to be cleared. If not specified, all events registered on context will be cleared.