Download:
child 35:cd1a82b0e415
parent 33:b78d604b9136
34:36496092e7d7
Anton Shestakov <av6@dwimlabs.net>, Thu, 05 Jul 2018 09:23:57 +0800
backbone.shard: add partition() and chunk()

2 файлов изменено, 14 вставок(+), 7 удалений(-) [+]
backbone.shard.js file | annotate | diff | comparison | revisions
test/underscore-methods.js file | annotate | diff | comparison | revisions
--- a/backbone.shard.js Thu Jul 05 09:23:39 2018 +0800
+++ b/backbone.shard.js Thu Jul 05 09:23:57 2018 +0800
@@ -1,7 +1,7 @@
/*
* backbone.shard.js.
*
- * (c) 2013-2017 Anton Shestakov.
+ * (c) 2013-2018 Anton Shestakov.
*
* This extension to Backbone may be freely distributed
* under the MIT license:
@@ -62,12 +62,13 @@
// Underscore methods that we want to implement on the Shard.
var methods = [
- 'all', 'any', 'chain', 'collect', 'contains', 'detect', 'difference',
- 'drop', 'each', 'every', 'filter', 'find', 'findIndex', 'findLastIndex',
- 'first', 'foldl', 'foldr', 'forEach', 'head', 'include', 'includes',
- 'indexOf', 'initial', 'inject', 'invoke', 'isEmpty', 'last', 'lastIndexOf',
- 'map', 'max', 'min', 'reduce', 'reduceRight', 'reject', 'rest', 'sample',
- 'select', 'shuffle', 'size', 'some', 'tail', 'take', 'toArray', 'without'
+ 'all', 'any', 'chain', 'chunk', 'collect', 'contains', 'detect',
+ 'difference', 'drop', 'each', 'every', 'filter', 'find', 'findIndex',
+ 'findLastIndex', 'first', 'foldl', 'foldr', 'forEach', 'head', 'include',
+ 'includes', 'indexOf', 'initial', 'inject', 'invoke', 'isEmpty', 'last',
+ 'lastIndexOf', 'map', 'max', 'min', 'partition', 'reduce', 'reduceRight',
+ 'reject', 'rest', 'sample', 'select', 'shuffle', 'size', 'some', 'tail',
+ 'take', 'toArray', 'without'
];
// Mix in each Underscore method as a proxy to `Shard#models`.
--- a/test/underscore-methods.js Thu Jul 05 09:23:39 2018 +0800
+++ b/test/underscore-methods.js Thu Jul 05 09:23:57 2018 +0800
@@ -34,6 +34,12 @@
return model.get('data').charCodeAt(0) % 2;
}), {0: [b], 1: [a, c]}, 'groupBy() works');
+ deepEqual(shard.partition(function(model) {
+ return model.get('data').charCodeAt(0) % 2;
+ }), [[a, c], [b]], 'partition() works');
+
+ deepEqual(shard.chunk(1), [[a], [b], [c]], 'chunk() 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'); }, '');