Download:
child 15:435c0fa0c9ff
parent 13:32f98d0cd21b
14:01b83171cef5
Anton Shestakov <engored@ya.ru>, Thu, 21 Mar 2013 15:47:33 +0900
Works with Backbone 1.0.0.

4 файлов изменено, 9 вставок(+), 14 удалений(-) [+]
backbone.shard.js file | annotate | diff | comparison | revisions
demo.html file | annotate | diff | comparison | revisions
test/index.html file | annotate | diff | comparison | revisions
test/underscore-methods.js file | annotate | diff | comparison | revisions
--- a/backbone.shard.js Thu Mar 21 15:30:18 2013 +0900
+++ b/backbone.shard.js Thu Mar 21 15:47:33 2013 +0900
@@ -1,7 +1,7 @@
/*
* backbone.shard.js.
*
- * (c) 2012 Anton Shestakov.
+ * (c) 2013 Anton Shestakov.
*
* This extension to Backbone may be freely distributed
* under the MIT license:
@@ -57,20 +57,16 @@
pluck: function(attr) {
return _.map(this.models, function(model) { return model.get(attr); });
- },
-
- chain: function () {
- return _(this.models).chain();
}
});
// Underscore methods that we want to implement on the Shard.
var methods = ['forEach', 'each', 'map', 'collect', 'reduce', 'foldl',
'inject', 'reduceRight', 'foldr', 'find', 'detect', 'filter', 'select',
- 'reject', 'every', 'all', 'some', 'any', 'include', 'contains', 'invoke'
- , 'max', 'min', 'sortedIndex', 'toArray', 'size', 'first', 'head',
- 'take', 'initial', 'rest', 'tail', 'last', 'without', 'indexOf',
- 'shuffle', 'lastIndexOf', 'isEmpty'];
+ 'reject', 'every', 'all', 'some', 'any', 'include', 'contains', 'invoke',
+ 'max', 'min', 'toArray', 'size', 'first', 'head', 'take', 'initial', 'rest',
+ 'tail', 'drop', 'last', 'without', 'indexOf', 'shuffle', 'lastIndexOf',
+ 'isEmpty', 'chain'];
// Mix in each Underscore method as a proxy to `Shard#models`.
_.each(methods, function(method) {
--- a/demo.html Thu Mar 21 15:30:18 2013 +0900
+++ b/demo.html Thu Mar 21 15:47:33 2013 +0900
@@ -6,7 +6,7 @@
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
- <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script>
+ <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
<script src="backbone.shard.js"></script>
</head>
--- a/test/index.html Thu Mar 21 15:30:18 2013 +0900
+++ b/test/index.html Thu Mar 21 15:47:33 2013 +0900
@@ -6,7 +6,7 @@
<script src="http://code.jquery.com/qunit/qunit-1.10.0.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
- <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script>
+ <script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
<script src="../backbone.shard.js"></script>
<script src="basic-filters.js"></script>
--- a/test/underscore-methods.js Thu Mar 21 15:30:18 2013 +0900
+++ b/test/underscore-methods.js Thu Mar 21 15:47:33 2013 +0900
@@ -14,8 +14,6 @@
}
});
-// TODO: test sortedIndex
-
test('Underscore methods: basics', function() {
strictEqual(shard.first(), a, 'first() works');
strictEqual(shard.last(), c, 'last() works');
@@ -98,9 +96,10 @@
}, ''), 'cba', 'reduceRight() works');
});
-test('Underscore methods: method aliases (working in Backbone.Collection since 0.9.9)', function() {
+test('Underscore methods: method aliases', function() {
strictEqual(shard.head(), a, 'head() works');
deepEqual(shard.tail(), [b, c], 'tail() works');
+ deepEqual(shard.drop(), [b, c], 'drop() works');
deepEqual(shard.countBy('data'), {a: 1, b: 1, c: 1}, 'countBy() works');
deepEqual(shard.select(function(model) {