-
Notifications
You must be signed in to change notification settings - Fork 12
Message.js
Bob Holt edited this page May 14, 2013
·
3 revisions
Previous: ExceptionUtil.js
Message is an enum-like singleton object that stores string values for event messages passed through the MessageBus. Creating a singleton like this gives us a number of benefits.
- Typos in event message string values are eliminated. Without this Message object, a typo in a string will not break the MessageBus; the listener will just fail to fire. Keeping the string value locked away in a Message object helps prevent this.
- String literals aren't generally tokenized by minifiers. Creating the Message object allows references to these strings to be tokenized, allowing better file minification.
- It provides a catalogue of all events. Being forced to catalogue our new event in the Message object will allow us the opportunity to be reminded of events we may have created in the past that serve the same purpose, promoting reuse.
Message.js ships with built-in PageChange
and PageBeforeChange
events that are used by Keel's built-in page routing mechanism. Message.js should be extended by the application, likely in app/framework/Message.js
like so:
define([
'keel/Message',
'underscore'
],
function(frameworkMessage, _) {
'use strict';
var message = _.extend({
// Application-specific messages
}, frameworkMessage);
return message;
});
Next: MessageBus.js