[Tables] Addressed style concerns from code review

This commit is contained in:
Henry 2016-03-31 12:56:29 -07:00
parent 0c00061cbc
commit 200a426f17
2 changed files with 22 additions and 28 deletions

View File

@ -145,25 +145,23 @@ define(
{}).columns || {}; {}).columns || {};
}; };
function equal(obj1, obj2) { function configEqual(obj1, obj2) {
var obj1Keys = Object.keys(obj1), var obj1Keys = Object.keys(obj1),
obj2Keys = Object.keys(obj2); obj2Keys = Object.keys(obj2);
return (obj1Keys.length === obj2Keys.length) && return (obj1Keys.length === obj2Keys.length) &&
obj1Keys.every(function(key){ obj1Keys.every(function (key) {
//To do a deep equals, could recurse here if typeof
// obj1 === Object
return obj1[key] === obj2[key]; return obj1[key] === obj2[key];
}); });
} }
/** /**
* Set the established configuration on the domain object * Set the established configuration on the domain object. Will noop
* if configuration is unchanged
* @private * @private
*/ */
TableConfiguration.prototype.saveColumnConfiguration = function (columnConfig) { TableConfiguration.prototype.saveColumnConfiguration = function (columnConfig) {
var self = this; var self = this;
//Don't bother mutating if column configuration is unchanged if (!configEqual(this.columnConfiguration, columnConfig)) {
if (!equal(this.columnConfiguration, columnConfig)) {
this.domainObject.useCapability('mutation', function (model) { this.domainObject.useCapability('mutation', function (model) {
model.configuration = model.configuration || {}; model.configuration = model.configuration || {};
model.configuration.table = model.configuration.table || {}; model.configuration.table = model.configuration.table || {};

View File

@ -203,24 +203,22 @@ define(
} }
} }
//if (handle) { //Add telemetry metadata (if any) for parent object
//Add telemetry metadata (if any) for parent object addMetadata(domainObject);
addMetadata(domainObject);
//If object is composed of multiple objects, also add //If object is composed of multiple objects, also add
// telemetry metadata from children // telemetry metadata from children
if (domainObject.hasCapability('composition')) { if (domainObject.hasCapability('composition')) {
domainObject.useCapability('composition').then(function (composition) { domainObject.useCapability('composition').then(function (composition) {
composition.forEach(addMetadata); composition.forEach(addMetadata);
}).then(function () { }).then(function () {
//Build columns based on available metadata //Build columns based on available metadata
buildAndFilterColumns();
});
} else {
//Build columns based on collected metadata
buildAndFilterColumns(); buildAndFilterColumns();
} });
// } } else {
//Build columns based on collected metadata
buildAndFilterColumns();
}
}; };
/** /**
@ -228,11 +226,9 @@ define(
* accordingly. * accordingly.
* @private * @private
*/ */
TelemetryTableController.prototype.filterColumns = function (columnConfig) { TelemetryTableController.prototype.filterColumns = function () {
if (!columnConfig){ var columnConfig = this.table.getColumnConfiguration();
columnConfig = this.table.getColumnConfiguration(); this.table.saveColumnConfiguration(columnConfig);
this.table.saveColumnConfiguration(columnConfig);
}
//Populate headers with visible columns (determined by configuration) //Populate headers with visible columns (determined by configuration)
this.$scope.headers = Object.keys(columnConfig).filter(function (column) { this.$scope.headers = Object.keys(columnConfig).filter(function (column) {
return columnConfig[column]; return columnConfig[column];