[Code Style] Use prototypes in Browse bundle

WTD-1482.
This commit is contained in:
Victor Woeltjen
2015-08-10 11:52:23 -07:00
parent 78146d97f8
commit a77920bd18
10 changed files with 418 additions and 365 deletions

View File

@ -36,67 +36,52 @@ define(
* @constructor
*/
function NavigationService() {
var navigated,
callbacks = [];
this.navigated = undefined;
this.callbacks = [];
}
// Getter for current navigation
function getNavigation() {
return navigated;
}
/**
* Get the current navigation state.
* @returns {DomainObject} the object that is navigated-to
*/
NavigationService.prototype.getNavigation = function () {
return this.navigated;
};
// Setter for navigation; invokes callbacks
function setNavigation(value) {
if (navigated !== value) {
navigated = value;
callbacks.forEach(function (callback) {
callback(value);
});
}
}
// Adds a callback
function addListener(callback) {
callbacks.push(callback);
}
// Filters out a callback
function removeListener(callback) {
callbacks = callbacks.filter(function (cb) {
return cb !== callback;
/**
* Set the current navigation state. This will invoke listeners.
* @param {DomainObject} domainObject the domain object to navigate to
*/
NavigationService.prototype.setNavigation = function (value) {
if (this.navigated !== value) {
this.navigated = value;
this.callbacks.forEach(function (callback) {
callback(value);
});
}
};
return {
/**
* Get the current navigation state.
* @memberof platform/commonUI/browse.NavigationService#
*/
getNavigation: getNavigation,
/**
* Set the current navigation state. Thiswill invoke listeners.
* @param {DomainObject} value the domain object to navigate
* to
* @memberof platform/commonUI/browse.NavigationService#
*/
setNavigation: setNavigation,
/**
* Listen for changes in navigation. The passed callback will
* be invoked with the new domain object of navigation when
* this changes.
* @param {function} callback the callback to invoke when
* navigation state changes
* @memberof platform/commonUI/browse.NavigationService#
*/
addListener: addListener,
/**
* Stop listening for changes in navigation state.
* @param {function} callback the callback which should
* no longer be invoked when navigation state
* changes
* @memberof platform/commonUI/browse.NavigationService#
*/
removeListener: removeListener
};
/**
* Listen for changes in navigation. The passed callback will
* be invoked with the new domain object of navigation when
* this changes.
* @param {function} callback the callback to invoke when
* navigation state changes
*/
NavigationService.prototype.addListener = function (callback) {
this.callbacks.push(callback);
}
/**
* Stop listening for changes in navigation state.
* @param {function} callback the callback which should
* no longer be invoked when navigation state
* changes
*/
NavigationService.prototype.removeListener = function (callback) {
this.callbacks = this.callbacks.filter(function (cb) {
return cb !== callback;
});
}
return NavigationService;