Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revmoving multiples rows with function was failing, when detected indice... #210

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
7 changes: 6 additions & 1 deletion src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down Expand Up @@ -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!";
Expand Down
20 changes: 20 additions & 0 deletions test/unit/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions test/unit/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];


Expand Down Expand Up @@ -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");
});
Expand Down
39 changes: 39 additions & 0 deletions test/unit/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down