[Code Style] Use prototypes in platform

WTD-1482
This commit is contained in:
Victor Woeltjen
2015-08-11 12:54:50 -07:00
parent f377c7cb71
commit b7765ff388
35 changed files with 1331 additions and 1379 deletions

View File

@ -36,23 +36,25 @@ define(
* object.
*
* @memberof platform/core
* @implements {Capability}
* @constructor
*/
function ViewCapability(viewService, domainObject) {
return {
/**
* Get all view definitions which are applicable to
* this object.
* @returns {View[]} an array of view definitions
* which are applicable to this object.
* @memberof platform/core.ViewCapability#
*/
invoke: function () {
return viewService.getViews(domainObject);
}
};
this.viewService = viewService;
this.domainObject = domainObject;
}
/**
* Get all view definitions which are applicable to
* this object.
* @returns {View[]} an array of view definitions
* which are applicable to this object.
* @memberof platform/core.ViewCapability#
*/
ViewCapability.prototype.invoke = function () {
return this.viewService.getViews(this.domainObject);
};
return ViewCapability;
}
);

View File

@ -29,6 +29,22 @@ define(
function () {
"use strict";
/**
* Provides definitions for views that are available for specific
* domain objects.
*
* @interface ViewService
*/
/**
* Get all views which are applicable to this domain object.
*
* @method ViewService#getViews
* @param {DomainObject} domainObject the domain object to view
* @returns {View[]} all views which can be used to visualize
* this domain object.
*/
/**
* A view provider allows view definitions (defined as extensions)
* to be read, and takes responsibility for filtering these down
@ -58,6 +74,8 @@ define(
* @memberof platform/core
* @constructor
* @param {View[]} an array of view definitions
* @param $log Angular's logging service
* @implements {ViewService}
*/
function ViewProvider(views, $log) {
@ -79,6 +97,13 @@ define(
return key;
}
// Filter out any key-less views
this.views = views.filter(validate);
}
ViewProvider.prototype.getViews = function (domainObject) {
var type = domainObject.useCapability("type");
// Check if an object has all capabilities designated as `needs`
// for a view. Exposing a capability via delegation is taken to
// satisfy this filter if `allowDelegation` is true.
@ -122,35 +147,16 @@ define(
return matches;
}
function getViews(domainObject) {
var type = domainObject.useCapability("type");
// First, filter views by type (matched to domain object type.)
// Second, filter by matching capabilities.
return views.filter(function (view) {
return viewMatchesType(view, type) && capabilitiesMatch(
// First, filter views by type (matched to domain object type.)
// Second, filter by matching capabilities.
return this.views.filter(function (view) {
return viewMatchesType(view, type) && capabilitiesMatch(
domainObject,
view.needs || [],
view.delegation || false
);
});
}
// Filter out any key-less views
views = views.filter(validate);
return {
/**
* Get all views which are applicable to this domain object.
*
* @param {DomainObject} domainObject the domain object to view
* @returns {View[]} all views which can be used to visualize
* this domain object.
* @memberof platform/core.ViewProvider#
*/
getViews: getViews
};
}
});
};
return ViewProvider;
}