Skip to content

Commit

Permalink
Merge pull request misoproject#146 from misoproject/where-short-syntax
Browse files Browse the repository at this point in the history
support for row function as first param
  • Loading branch information
iros committed Jun 15, 2012
2 parents 84b4768 + cecb3ee commit e0f5772
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,14 @@
*/
where : function(filter, options) {
options = options || {};
options.filter = options.filter || {};
if ( _.isFunction(filter) ) {
options.filter.rows = filter;
} else {
options.filter = filter;
}

options.parent = this;
options.filter = filter || {};

return new Miso.DataView(options);
},
Expand Down
11 changes: 11 additions & 0 deletions test/unit/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@
});
});

test("One Row Filter View creation with short syntax", function() {
var ds = Util.baseSample();
var view = ds.where(function(row) {
return row._id === ds._columns[0].data[0];
});

_.each(ds._columns, function(column, i) {
ok(_.isEqual(ds._columns[i].data.slice(0, 1), view._columns[i].data), "data has been copied");
});
});

test("Two Row Filter View creation", function() {
var ds = Util.baseSample();
var view = ds.where({
Expand Down

0 comments on commit e0f5772

Please sign in to comment.