From b0cdce582e8cf1027edb913d30575ee7356b40e6 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 7 Nov 2014 13:46:41 -0800 Subject: [PATCH 1/2] Upgraded to 2.0 --- bower.json | 2 +- changelog.txt | 1 + package.json | 2 +- src/backfire.js | 26 +++++++++++++++++++------- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/bower.json b/bower.json index ec8565e..171121d 100644 --- a/bower.json +++ b/bower.json @@ -32,7 +32,7 @@ "index.html" ], "dependencies": { - "firebase": "1.0.x", + "firebase": "2.0.x", "backbone": "<=1.1.0", "underscore": "~1.5.2" }, diff --git a/changelog.txt b/changelog.txt index e69de29..e6f1d52 100644 --- a/changelog.txt +++ b/changelog.txt @@ -0,0 +1 @@ +feature - Upgraded Firebase dependency to 2.0.x. \ No newline at end of file diff --git a/package.json b/package.json index 8ab6f0e..098ab1b 100644 --- a/package.json +++ b/package.json @@ -30,7 +30,7 @@ "package.json" ], "dependencies": { - "firebase": "1.0.x" + "firebase": "2.0.x" }, "devDependencies": { "chai-backbone": "~0.9.2", diff --git a/src/backfire.js b/src/backfire.js index ed72848..beec925 100644 --- a/src/backfire.js +++ b/src/backfire.js @@ -30,9 +30,21 @@ }; _.extend(Backbone.Firebase.prototype, { + + /** + * A utility for retrieving the key name of a Firebase ref or + * DataSnapshot. This is backwards-compatible with `name()` + * from Firebase 1.x.x and `key()` from Firebase 2.0.0+. Once + * support for Firebase 1.x.x is dropped in EmberFire, this + * helper can be removed. + */ + _getKey: function(refOrSnapshot) { + return (typeof refOrSnapshot.key === 'function') ? refOrSnapshot.key() : refOrSnapshot.name(); + }, + _childAdded: function(childSnap, prevChild) { var model = childSnap.val(); - model.id = childSnap.name(); + model.id = this._getKey(childSnap); if (prevChild) { var item = _.find(this._children, function(child) { return child.id == prevChild; @@ -53,7 +65,7 @@ _childChanged: function(childSnap) { var model = childSnap.val(); - model.id = childSnap.name(); + model.id = this._getKey(childSnap); var item = _.find(this._children, function(child) { return child.id == model.id; }); @@ -69,7 +81,7 @@ create: function(model, cb) { if (!model.id) { - model.id = this._fbref.ref().push().name(); + model.id = this._getKey(this._fbref.ref().push()); } var val = model.toJSON(); @@ -306,7 +318,7 @@ model = model.toJSON(); } if (!model.id) { - model.id = this.firebase.ref().push().name(); + model.id = Backbone.Firebase.prototype._getKey(this.firebase.ref().push()); } ret.push(model); } @@ -319,7 +331,7 @@ if (!_.isObject(model)) { model = {}; } - model.id = snap.name(); + model.id = Backbone.Firebase.prototype._getKey(snap); } if (this._suppressEvent === true) { this._suppressEvent = false; @@ -338,7 +350,7 @@ _childChanged: function(snap) { var model = snap.val(); if (!model.id) { - model.id = snap.name(); + model.id = Backbone.Firebase.prototype._getKey(snap); } var item = _.find(this.models, function(child) { @@ -365,7 +377,7 @@ _childRemoved: function(snap) { var model = snap.val(); if (!model.id) { - model.id = snap.name(); + model.id = Backbone.Firebase.prototype._getKey(snap); } if (this._suppressEvent === true) { this._suppressEvent = false; From 90f1876b3fa22d9f9b2f8a23f01e14960cf99fe9 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 7 Nov 2014 14:43:32 -0800 Subject: [PATCH 2/2] Wrong lib --- src/backfire.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backfire.js b/src/backfire.js index beec925..ad78c4f 100644 --- a/src/backfire.js +++ b/src/backfire.js @@ -35,7 +35,7 @@ * A utility for retrieving the key name of a Firebase ref or * DataSnapshot. This is backwards-compatible with `name()` * from Firebase 1.x.x and `key()` from Firebase 2.0.0+. Once - * support for Firebase 1.x.x is dropped in EmberFire, this + * support for Firebase 1.x.x is dropped in BackFire, this * helper can be removed. */ _getKey: function(refOrSnapshot) {