# HG changeset patch # User Anton Shestakov <av6@dwimlabs.net> # Date 1466575196 -28800 # Node ID b7d97ca5ea2c6b6f9dee3cbe9978ab8f6be1b516 # Parent 803ba407e90127532589bb6fb8fa413f93a59a65 backbone.shard: add indexBy method, test it diff -r 803ba407e901 -r b7d97ca5ea2c backbone.shard.js --- a/backbone.shard.js Wed Jun 22 13:36:10 2016 +0800 +++ b/backbone.shard.js Wed Jun 22 13:59:56 2016 +0800 @@ -78,7 +78,7 @@ }); // Underscore methods that take a property name as an argument. -var attributeMethods = ['groupBy', 'countBy', 'sortBy']; +var attributeMethods = ['countBy', 'groupBy', 'indexBy', 'sortBy']; // Use attributes instead of properties. _.each(attributeMethods, function(method) { diff -r 803ba407e901 -r b7d97ca5ea2c test/underscore-methods.js --- a/test/underscore-methods.js Wed Jun 22 13:36:10 2016 +0800 +++ b/test/underscore-methods.js Wed Jun 22 13:59:56 2016 +0800 @@ -39,6 +39,8 @@ return model.get('data').charCodeAt(0) % 2; }), {0: [b], 1: [a, c]}, 'groupBy() works'); + deepEqual(shard.indexBy('data'), {a: a, b: b, c: c}, 'indexBy() works'); + var sh = shard.shuffle().reduce(function(memo, model) { return memo += model.get('data'); }, ''); ok(sh.length == 3 && _(sh).contains('a') && _(sh).contains('b') && _(sh).contains('c'), 'shuffle() works'); });