From 4b2c674c75189ac2abc5dc59f8e9b3e7e7208bb4 Mon Sep 17 00:00:00 2001 From: Alexandre Masselot Date: Fri, 20 Sep 2013 18:08:06 -0700 Subject: [PATCH 1/6] revmoving multiples rows with function was failing, when detected indices to be removed are stored increasingly. reversing the list of index solved it --- src/dataset.js | 2 +- test/unit/dataset.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) 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/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(); From 7b95de4ebc7b8a8521d180e25656134c903fdd00 Mon Sep 17 00:00:00 2001 From: Alexandre Masselot Date: Mon, 23 Sep 2013 22:54:59 -0700 Subject: [PATCH 2/6] issue 207, adding row on dataset fails if view is derived on a column. The fix at the _add colum should certainly happen better at the _sync level (but how to go from d.changed keeping only the column of interest???) --- src/view.js | 7 +++++- test/unit/views.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/view.js b/src/view.js index adeacf5..d4362a0 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 _sync method level, but without much success + if(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/views.js b/test/unit/views.js index 92b5fcb..7f619ed 100644 --- a/test/unit/views.js +++ b/test/unit/views.js @@ -233,6 +233,61 @@ 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 reported column, adding a line - issue 207", function() { + var ds = Util.baseSyncingSample(); + + var view = ds.where({ + columns:['three'], + rows:function(row){ + return row.three>8; + } + }); + + 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("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(); From dda829590450cc2cab7eca10938d79f57a33fa32 Mon Sep 17 00:00:00 2001 From: Alexandre Masselot Date: Mon, 23 Sep 2013 23:00:19 -0700 Subject: [PATCH 3/6] formating --- src/view.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/view.js b/src/view.js index d4362a0..d2ca59a 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"; } From 10f9e5d6f77de4dfe11ac6af3a9a17ba48fdb795 Mon Sep 17 00:00:00 2001 From: Alexandre Masselot Date: Tue, 1 Oct 2013 18:51:26 -0700 Subject: [PATCH 4/6] remove a somehow duplicate test --- test/unit/views.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/test/unit/views.js b/test/unit/views.js index 7f619ed..9f04af4 100644 --- a/test/unit/views.js +++ b/test/unit/views.js @@ -257,22 +257,6 @@ ok(_.isEqual(view.column('three').data, [9,12]), 'adding one line to dataset flushes it to the to view'); }); - - test("derived view, filtered on reported column, adding a line - issue 207", function() { - var ds = Util.baseSyncingSample(); - - var view = ds.where({ - columns:['three'], - rows:function(row){ - return row.three>8; - } - }); - - 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("derived view, filtered on ureported column, adding a line - issue 207", function() { var ds = Util.baseSyncingSample(); From 6e38ea15a91a0409f9344e5e7e838ff6cb910370 Mon Sep 17 00:00:00 2001 From: Alexandre Masselot Date: Tue, 1 Oct 2013 18:51:46 -0700 Subject: [PATCH 5/6] make it null proof --- src/view.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/view.js b/src/view.js index d2ca59a..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,8 +519,8 @@ _.each(row, function(value, key) { var column = this.column(key); - //tried to catch that at the _sync method level, but without much success - if(column === undefined){ + //tried to catch that at the _synv function + if(typeof column === 'undefined'){ return; } From 3a9e01bb248299576151f9cbae6917745472ebef Mon Sep 17 00:00:00 2001 From: Alexandre Masselot Date: Thu, 7 Nov 2013 08:31:18 -0800 Subject: [PATCH 6/6] propse fix for issue #217 123.23e-3 was not passing as number --- src/types.js | 2 +- test/unit/types.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) 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/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"); });