Download:
child 34:1d7126490f46
parent 32:9895c11d92e8
33:9dfe8668e7fe
Anton Shestakov <engored@ya.ru>, Thu, 21 Mar 2013 16:04:47 +0900
Update Underscore (1.4.3), Backbone (1.0.0) and Shard.

3 файлов изменено, 28 вставок(+), 15 удалений(-) [+]
static/js/backbone.shard.js file | annotate | diff | comparison | revisions
static/js/ui.js file | annotate | diff | comparison | revisions
templates/index.html file | annotate | diff | comparison | revisions
--- a/static/js/backbone.shard.js Sat Feb 09 18:06:31 2013 +0900
+++ b/static/js/backbone.shard.js Thu Mar 21 16:04:47 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,23 +57,36 @@
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', 'reduce', 'reduceRight', 'find',
- 'detect', 'filter', 'select', 'reject', 'every', 'all', 'some', 'any',
- 'include', 'contains', 'invoke', 'max', 'min', 'sortBy', 'sortedIndex',
- 'toArray', 'size', 'first', 'initial', 'rest', 'last', 'without', 'indexOf',
- 'shuffle', 'lastIndexOf', 'isEmpty', 'groupBy'];
+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', '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) {
Backbone.Shard.prototype[method] = function() {
- return _[method].apply(_, [this.models].concat(_.toArray(arguments)));
+ var args = Array.prototype.slice.call(arguments);
+ args.unshift(this.models);
+ return _[method].apply(_, args);
};
});
+
+// Underscore methods that take a property name as an argument.
+var attributeMethods = ['groupBy', 'countBy', 'sortBy'];
+
+// Use attributes instead of properties.
+_.each(attributeMethods, function(method) {
+ Backbone.Shard.prototype[method] = function(value, context) {
+ var iterator = _.isFunction(value) ? value : function(model) {
+ return model.get(value);
+ };
+ return _[method](this.models, iterator, context);
+ };
+});
+
--- a/static/js/ui.js Sat Feb 09 18:06:31 2013 +0900
+++ b/static/js/ui.js Thu Mar 21 16:04:47 2013 +0900
@@ -24,8 +24,8 @@
type: 'GET',
dataType: 'json'
}).done(function(data) {
- fruitbar.projects.update(data['projects']);
- fruitbar.tasks.update(data['tasks']);
+ fruitbar.projects.set(data['projects']);
+ fruitbar.tasks.set(data['tasks']);
});
};
--- a/templates/index.html Sat Feb 09 18:06:31 2013 +0900
+++ b/templates/index.html Thu Mar 21 16:04:47 2013 +0900
@@ -8,8 +8,8 @@
<link type="text/css" href="{{ url_for('static', filename='css/custom.css') }}" rel="stylesheet">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
- <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.3/underscore-min.js"></script>
- <script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.9/backbone-min.js"></script>
+ <script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
+ <script src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.0.0/backbone-min.js"></script>
<script src="//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/js/bootstrap.min.js"></script>
<script src="{{ url_for('static', filename='js/backbone.shard.js') }}"></script>
<script src="{{ url_for('static', filename='js/framework/models.js') }}"></script>