Skip to content
This repository has been archived by the owner on Aug 25, 2018. It is now read-only.

Commit

Permalink
Merge pull request #98 from firebase/upgrade-2.0
Browse files Browse the repository at this point in the history
Upgraded to 2.0
  • Loading branch information
Jacob Wenger committed Nov 7, 2014
2 parents 72faa4f + d5d6633 commit 15544d6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"index.html"
],
"dependencies": {
"firebase": "1.1.x",
"firebase": "2.0.x",
"backbone": "<=1.1.0",
"underscore": "~1.5.2"
},
Expand Down
2 changes: 1 addition & 1 deletion changelog.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
feature - Upgraded Firebase dependency to 1.1.x.
feature - Upgraded Firebase dependency to 2.0.x.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"package.json"
],
"dependencies": {
"firebase": "1.1.x"
"firebase": "2.0.x"
},
"devDependencies": {
"chai-backbone": "~0.9.2",
Expand Down
26 changes: 19 additions & 7 deletions src/backfire.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 BackFire, 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;
Expand All @@ -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;
});
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
Expand Down

0 comments on commit 15544d6

Please sign in to comment.