Added mutation listener

This commit is contained in:
Henry
2016-03-30 14:25:53 -07:00
parent a4b79cdb5b
commit 0c00061cbc
6 changed files with 164 additions and 79 deletions

View File

@@ -39,6 +39,7 @@ define(
function TableConfiguration(domainObject, telemetryFormatter) {
this.domainObject = domainObject;
this.columns = [];
this.columnConfiguration = {};
this.telemetryFormatter = telemetryFormatter;
}
@@ -144,16 +145,32 @@ define(
{}).columns || {};
};
function equal(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
return obj1[key] === obj2[key];
});
}
/**
* Set the established configuration on the domain object
* @private
*/
TableConfiguration.prototype.saveColumnConfiguration = function (columnConfig) {
this.domainObject.useCapability('mutation', function (model) {
model.configuration = model.configuration || {};
model.configuration.table = model.configuration.table || {};
model.configuration.table.columns = columnConfig;
});
var self = this;
//Don't bother mutating if column configuration is unchanged
if (!equal(this.columnConfiguration, columnConfig)) {
this.domainObject.useCapability('mutation', function (model) {
model.configuration = model.configuration || {};
model.configuration.table = model.configuration.table || {};
model.configuration.table.columns = columnConfig;
self.columnConfiguration = columnConfig;
});
}
};
/**