Core Events

Tom Taylor edited this page Nov 30, 2017 · 10 revisions

Due to the modular approach we've taken for the architecture of the client application, we make heavy use of the observer code design pattern, and use events to keep the various parts of the application updated.

Additionally, our chosen framework for structuring the client application (Backbone.js) has very good support for an event-driven approach.

Backbone built-in events

Backbone supports a wide variety of different events which we make use of extensively throughout the application. Please see the Backbone.js documentation for more information:

Adapt built-in events

In addition to the Backbone events, we've added many events which we use throughout the application, and can be listened to by any plugin code.

You can listen to system events using the following syntax: Origin.on(FUNCTION, CALLBACK_FUNCTION)

For example:

Origin.on('origin:initialize', function() {
  console.log('App is ready to go');
});

Core Events

See below for a list of core events, and what they signal.

Origin events

Event name What it signals Parameters passed to callback
origin:dataReady The app's data has been loaded, and is about to initialise
origin:initialize The app has initialised
origin:showLoading Triggers the loading animation
origin:hideLoading Hides the loading animation
origin:sessionStarted A new user session has started
remove:views All views should be removed/destroyed

Window events

We've also included some of the Window object's events for ease of use:

Event name What it signals Parameters passed to callback
key:down A key has been pressed down See MDN's keydown documentation
window:resize The browser window has been resized See MDN's resize documentation
window:focus The browser window has been brought to the front See MDN's focus documentation
window:blur The browser window is no longer at the forefront See MDN's blur documentation

Misc events

Event name What it signals Parameters passed to callback
constants:loaded Sever configuration settings have been loaded
l10n:loaded The localised app data has been loaded
router:MODULE The user's location in the app has changed location1:String
location2:String
location3:String
location4:String
location:change Same as above location:Object
contentCollection:dataLoaded Data has been fetched from the server for a ContentCollection instance collectionType:String
VIEW:preRender Called before a view has been rendered The Backbone.View instance
VIEW:postRender Called after a view has been rendered The Backbone.View instance
Clone this wiki locally
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.