From 200a426f17199b384aade092565f746b48b3b0d6 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 31 Mar 2016 12:56:29 -0700 Subject: [PATCH] [Tables] Addressed style concerns from code review --- .../features/table/src/TableConfiguration.js | 12 +++--- .../controllers/TelemetryTableController.js | 38 +++++++++---------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/platform/features/table/src/TableConfiguration.js b/platform/features/table/src/TableConfiguration.js index 32c0a69601..6353a4505b 100644 --- a/platform/features/table/src/TableConfiguration.js +++ b/platform/features/table/src/TableConfiguration.js @@ -145,25 +145,23 @@ define( {}).columns || {}; }; - function equal(obj1, obj2) { + function configEqual(obj1, obj2) { var obj1Keys = Object.keys(obj1), obj2Keys = Object.keys(obj2); return (obj1Keys.length === obj2Keys.length) && - obj1Keys.every(function(key){ - //To do a deep equals, could recurse here if typeof - // obj1 === Object + obj1Keys.every(function (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 */ TableConfiguration.prototype.saveColumnConfiguration = function (columnConfig) { var self = this; - //Don't bother mutating if column configuration is unchanged - if (!equal(this.columnConfiguration, columnConfig)) { + if (!configEqual(this.columnConfiguration, columnConfig)) { this.domainObject.useCapability('mutation', function (model) { model.configuration = model.configuration || {}; model.configuration.table = model.configuration.table || {}; diff --git a/platform/features/table/src/controllers/TelemetryTableController.js b/platform/features/table/src/controllers/TelemetryTableController.js index 6131521d8d..3c3fb7665d 100644 --- a/platform/features/table/src/controllers/TelemetryTableController.js +++ b/platform/features/table/src/controllers/TelemetryTableController.js @@ -203,24 +203,22 @@ define( } } - //if (handle) { - //Add telemetry metadata (if any) for parent object - addMetadata(domainObject); + //Add telemetry metadata (if any) for parent object + addMetadata(domainObject); - //If object is composed of multiple objects, also add - // telemetry metadata from children - if (domainObject.hasCapability('composition')) { - domainObject.useCapability('composition').then(function (composition) { - composition.forEach(addMetadata); - }).then(function () { - //Build columns based on available metadata - buildAndFilterColumns(); - }); - } else { - //Build columns based on collected metadata + //If object is composed of multiple objects, also add + // telemetry metadata from children + if (domainObject.hasCapability('composition')) { + domainObject.useCapability('composition').then(function (composition) { + composition.forEach(addMetadata); + }).then(function () { + //Build columns based on available metadata buildAndFilterColumns(); - } - // } + }); + } else { + //Build columns based on collected metadata + buildAndFilterColumns(); + } }; /** @@ -228,11 +226,9 @@ define( * accordingly. * @private */ - TelemetryTableController.prototype.filterColumns = function (columnConfig) { - if (!columnConfig){ - columnConfig = this.table.getColumnConfiguration(); - this.table.saveColumnConfiguration(columnConfig); - } + TelemetryTableController.prototype.filterColumns = function () { + var columnConfig = this.table.getColumnConfiguration(); + this.table.saveColumnConfiguration(columnConfig); //Populate headers with visible columns (determined by configuration) this.$scope.headers = Object.keys(columnConfig).filter(function (column) { return columnConfig[column];