diff --git a/src/dataset.js b/src/dataset.js index 130beee..6da1f32 100644 --- a/src/dataset.js +++ b/src/dataset.js @@ -483,7 +483,7 @@ Version 0.0.1.2 // don't attempt tp remove the rows while iterating over them // since that modifies the length of the dataset and thus // terminates the each loop early. - _.each(rowsToRemove, function(rowId) { + _.each(rowsToRemove.reverse(), function(rowId) { this._remove(rowId); }, this); diff --git a/src/types.js b/src/types.js index 8892c94..6ef08e8 100644 --- a/src/types.js +++ b/src/types.js @@ -109,7 +109,7 @@ number : { name : "number", - regexp : /^\s*[\-\.]?[0-9]+([\.][0-9]+)?\s*$/, + regexp : /^\s*[\-\.]?[0-9]+([\.][0-9]+)?([eE]\-?\d+)?\s*$/, coerce : function(v) { var cv = +v; if (_.isNull(v) || typeof v === "undefined" || _.isNaN(cv)) { diff --git a/src/view.js b/src/view.js index adeacf5..7c8c092 100644 --- a/src/view.js +++ b/src/view.js @@ -200,7 +200,7 @@ // existing row to update and now need to just add a new // one. Use the delta's changed properties as the new row // if it passes the filter. - if (this.filter.rows && this.filter.rows(d.changed)) { + if (this.filter.rows && this.filter.rows(d.changed)){ this._add(d.changed); eventType = "add"; } @@ -519,6 +519,11 @@ _.each(row, function(value, key) { var column = this.column(key); + //tried to catch that at the _synv function + if(typeof column === 'undefined'){ + return; + } + // is this a computed column? if so throw an error if (column.isComputed()) { throw "You're trying to update a computed column. Those get computed!"; diff --git a/test/unit/dataset.js b/test/unit/dataset.js index 6ef950b..7664ab0 100644 --- a/test/unit/dataset.js +++ b/test/unit/dataset.js @@ -75,6 +75,26 @@ ok( ds._rowIdByPosition[0] !== firstRowId ); equals(ds.length, 2); }); + + + test("removing multiple rows with a function", function() { + // this was failing before the rows were not reverse before removing + // removing the two first line was indeed removing the first and 3rd + var ds = Util.baseSample(); + var firstRowId = ds._rowIdByPosition[0]; + var secondRowId = ds._rowIdByPosition[1]; + + equals(ds.length, 3); + ds.remove(function(row) { return (row.one <= 2); }); + + strictEqual( ds._rowPositionById[firstRowId], undefined ); + strictEqual( ds._rowPositionById[secondRowId], undefined ); + + equals(ds.length, 1); + ok(_.isEqual(ds.column("one").data, [3])); + ok(_.isEqual(ds.column("two").data, [6])); + }); + test("updating a row with an incorrect type", function() { var ds = Util.baseSample(); diff --git a/test/unit/types.js b/test/unit/types.js index a89ec8a..75c7a88 100644 --- a/test/unit/types.js +++ b/test/unit/types.js @@ -2,7 +2,7 @@ var Dataset = global.Miso.Dataset; - var numbers = ['123', '0.34', '.23']; + var numbers = ['123', '0.34', '.23', '1.23e-2', '1.23e2']; var not_numbers = [null, NaN,undefined]; @@ -45,7 +45,7 @@ test("Coerce number type", function() { - var coerced = [123, 0.34, 0.23]; + var coerced = [123, 0.34, 0.23, 0.0123, 123]; _.each(numbers, function(num, i) { equals(Dataset.types.number.coerce(num), coerced[i], "Should return true for a number"); }); diff --git a/test/unit/views.js b/test/unit/views.js index 92b5fcb..9f04af4 100644 --- a/test/unit/views.js +++ b/test/unit/views.js @@ -233,6 +233,45 @@ equals(view.max("three"), 9); equals(view.min(["three"]), 7); }); + + + test("Basic view with adding a line to original dataset does not change if sync:false", function() { + var ds = Util.baseSample(); + var view = ds.where({}); + equal(view.length, 3, 'original view contains 3 lines'); + + ds.add({one:10, two:11, three:12}); + equal(view.length, 3, 'adding one line doe not change the view'); + }); + + test("Basic view with adding a line to original dataset, sync:true", function() { + var ds = Util.baseSyncingSample(); + var view = ds.where({ + rows:function(row){ + return row.one>2 + } + }); + equal(view.length, 1, 'original view contains 1 lines'); + + ds.add({one:10, two:11, three:12}); + ok(_.isEqual(view.column('three').data, [9,12]), 'adding one line to dataset flushes it to the to view'); + }); + + test("derived view, filtered on ureported column, adding a line - issue 207", function() { + var ds = Util.baseSyncingSample(); + + var view = ds.where({ + columns:['three'], + rows:function(row){ + return row.one>2; + } + }); + + ds.add({one:10, two:11, three:12}); + ds.add({one:-10, two:-11, three:-12}); + ok(_.isEqual(view.column('three').data, [9,12]), 'adding one line to dataset adds one to view'); + }); + test("Using string syntax for columns", function() { var ds = Util.baseSample();