[Pkg-javascript-commits] [backbone] 39/101: defaulting Backbone.Collection#model to be Backbone.Model

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:58:27 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.1.0
in repository backbone.

commit b1277b92580cc08cd7d99212202dd0e42c8dc5e6
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Wed Oct 6 13:41:37 2010 -0400

    defaulting Backbone.Collection#model to be Backbone.Model
---
 backbone.js        | 7 +++++--
 test/collection.js | 8 ++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/backbone.js b/backbone.js
index c775e4e..9206dfc 100644
--- a/backbone.js
+++ b/backbone.js
@@ -276,7 +276,8 @@
   // or unordered. If a `comparator` is specified, the Collection will maintain
   // its models in sort order, as they're added and removed.
   Backbone.Collection = function(models, options) {
-    if (options && options.comparator) {
+    options || (options = {});
+    if (options.comparator) {
       this.comparator = options.comparator;
       delete options.comparator;
     }
@@ -288,9 +289,11 @@
   // Define the Collection's inheritable methods.
   _.extend(Backbone.Collection.prototype, Backbone.Bindable, {
 
+    model : Backbone.Model,
+
     // Initialize or re-initialize all internal state. Called when the
     // collection is refreshed.
-    _initialize : function() {
+    _initialize : function(options) {
       this.length = 0;
       this.models = [];
       this._byId = {};
diff --git a/test/collection.js b/test/collection.js
index 96ddd04..58e7030 100644
--- a/test/collection.js
+++ b/test/collection.js
@@ -79,4 +79,12 @@ $(document).ready(function() {
     equals(lastRequest[1], col);
   });
 
+  test("collections: create", function() {
+    var model = col.create({label: 'f'});
+    equals(lastRequest[0], 'POST');
+    equals(lastRequest[1], model);
+    equals(model.get('label'), 'f');
+    equals(model.collection, col);
+  });
+
 });

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list