Skip to content
Browse files

couple of small logic fixes and tidying

  • Loading branch information...
1 parent 66dddf5 commit d2e2228076d4c24ff1f83c49fc34d6f149c88e1d @alexgraul alexgraul committed Oct 25, 2012
Showing with 15 additions and 7 deletions.
  1. +15 −7 src/dataset.js
View
22 src/dataset.js
@@ -493,13 +493,12 @@ Version 0.0.1.2
}
},
-
_arrayUpdate : function(rows) {
var deltas = [];
_.each(rows, function(newRow) {
var delta = { old : {}, changed : {} };
delta[this.idAttribute] = newRow[this.idAttribute];
-
+
var pos = this._rowPositionById[newRow[this.idAttribute]];
_.each(newRow, function(value, prop) {
var column = this._columns[this._columnPositionByName[prop]];
@@ -515,7 +514,12 @@ Version 0.0.1.2
//Ensure value passes the type test
if (!type.test(value, column)) {
- throw "You're trying to update a computed column. Those get computed!";
+ throw "Value is incorrect type";
+ }
+
+ //skip if computed column
+ if (this._computedColumns[column.name]) {
+ return;
}
value = type.coerce(value, column);
@@ -531,21 +535,25 @@ Version 0.0.1.2
delta.changed[prop] = value;
}
+
+ }, this);
+
// Update any computed columns
if (typeof this._computedColumns !== "undefined") {
_.each(this._computedColumns, function(column) {
- var temprow = _.extend({}, this._row(pos), newRow),
+ var temprow = _.extend({}, this._row(pos)),
oldValue = temprow[column.name],
newValue = column.compute(temprow, pos);
if (oldValue !== newValue) {
delta.old[column.name] = oldValue;
+ column.data[pos] = newValue;
delta.changed[column.name] = newValue;
}
}, this);
}
-
- }, this);
- deltas.push(delta);
+ if ( _.keys(delta.changed).length > 0 ) {
+ deltas.push(delta);
+ }
}, this);
return deltas;
},

0 comments on commit d2e2228

Please sign in to comment.
Something went wrong with that request. Please try again.