Download:
child 25:9636252f0f93
parent 23:803ba407e901
24:b7d97ca5ea2c
Anton Shestakov <av6@dwimlabs.net>, Wed, 22 Jun 2016 13:59:56 +0800
backbone.shard: add indexBy method, test it

2 файлов изменено, 3 вставок(+), 1 удалений(-) [+]
backbone.shard.js file | annotate | diff | comparison | revisions
test/underscore-methods.js file | annotate | diff | comparison | revisions
--- 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) {
--- 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');
});