Skip to content

Commit

Permalink
removing some underscore model methods, adding others
Browse files Browse the repository at this point in the history
  • Loading branch information
jashkenas committed Mar 19, 2013
1 parent 4e3f923 commit 83eb26f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 18 deletions.
5 changes: 2 additions & 3 deletions backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,11 +556,10 @@
});

// Underscore methods that we want to implement on the Model.
var methods = ['each', 'forEach', 'sortBy', 'groupBy', 'size', 'keys',
'values', 'invert', 'pick', 'omit', 'isEqual', 'isEmpty', 'chain'];
var modelMethods = ['keys', 'values', 'pairs', 'invert', 'pick', 'omit'];

// Mix in each Underscore method as a proxy to `Model#attributes`.
_.each(methods, function(method) {
_.each(modelMethods, function(method) {
Model.prototype[method] = function() {
var args = slice.call(arguments);
args.unshift(this.attributes);
Expand Down
16 changes: 1 addition & 15 deletions test/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,14 @@ $(document).ready(function() {
equal(model.url(), '/nested/1/collection/2');
});

test("underscore methods", 15, function() {
test("underscore methods", 5, function() {
var model = new Backbone.Model({ 'foo': 'a', 'bar': 'b', 'baz': 'c' });
var model2 = model.clone();
deepEqual(model.keys(), ['foo', 'bar', 'baz']);
deepEqual(model.values(), ['a', 'b', 'c']);
deepEqual(model.invert(), { 'a': 'foo', 'b': 'bar', 'c': 'baz' });
deepEqual(model.pick('foo', 'baz'), {'foo': 'a', 'baz': 'c'});
deepEqual(model.omit('foo', 'bar'), {'baz': 'c'});
model.each(function(attr, index, attrs) {
ok(true);
});
equal(model.isEqual(model2.attributes), true);
equal(model.isEqual({ 'foo': 'a', 'bop': 'd' }), false);
equal(model.isEmpty(), false);
equal(model.size(), 3);
equal(model.chain().keys().contains('foo').value(), true);
deepEqual(model.sortBy(function(val) { return val === 'b' }), ["c", "a", "b"]);
deepEqual(model.groupBy(), {
'a': ['a'],
'b': ['b'],
'c': ['c']
});
});

test("clone", 10, function() {
Expand Down

0 comments on commit 83eb26f

Please sign in to comment.