Skip to content

Commit

Permalink
Renamed utils.getSnapshotKey() to utils.getKey()
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobawenger committed Nov 11, 2014
1 parent cd4ef13 commit f75c0e3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/FirebaseArray.js
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,14 @@
*/
$$added: function(snap, prevChild) {
// check to make sure record does not exist
var i = this.$indexFor($firebaseUtils.getSnapshotKey(snap));
var i = this.$indexFor($firebaseUtils.getKey(snap));
if( i === -1 ) {
// parse data and create record
var rec = snap.val();
if( !angular.isObject(rec) ) {
rec = { $value: rec };
}
rec.$id = $firebaseUtils.getSnapshotKey(snap);
rec.$id = $firebaseUtils.getKey(snap);
rec.$priority = snap.getPriority();
$firebaseUtils.applyDefaults(rec, this.$$defaults);

Expand All @@ -279,7 +279,7 @@
* @param snap
*/
$$removed: function(snap) {
var rec = this.$getRecord($firebaseUtils.getSnapshotKey(snap));
var rec = this.$getRecord($firebaseUtils.getKey(snap));
if( angular.isObject(rec) ) {
this._process('child_removed', rec);
}
Expand All @@ -292,7 +292,7 @@
* @param snap
*/
$$updated: function(snap) {
var rec = this.$getRecord($firebaseUtils.getSnapshotKey(snap));
var rec = this.$getRecord($firebaseUtils.getKey(snap));
if( angular.isObject(rec) ) {
// apply changes to the record
var changed = $firebaseUtils.updateRec(rec, snap);
Expand All @@ -311,7 +311,7 @@
* @param {string} prevChild
*/
$$moved: function(snap, prevChild) {
var rec = this.$getRecord($firebaseUtils.getSnapshotKey(snap));
var rec = this.$getRecord($firebaseUtils.getKey(snap));
if( angular.isObject(rec) ) {
rec.$priority = snap.getPriority();
this._process('child_moved', rec, prevChild);
Expand Down
2 changes: 1 addition & 1 deletion src/FirebaseObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
value: this.$$conf
});

this.$id = $firebaseUtils.getSnapshotKey($firebase.$ref().ref());
this.$id = $firebaseUtils.getKey($firebase.$ref().ref());
this.$priority = null;

$firebaseUtils.applyDefaults(this, this.$$defaults);
Expand Down
4 changes: 2 additions & 2 deletions src/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@
// the entire Firebase path
ref.once('value', function(snap) {
snap.forEach(function(ss) {
if( !dataCopy.hasOwnProperty($firebaseUtils.getSnapshotKey(ss)) ) {
dataCopy[$firebaseUtils.getSnapshotKey(ss)] = null;
if( !dataCopy.hasOwnProperty($firebaseUtils.getKey(ss)) ) {
dataCopy[$firebaseUtils.getKey(ss)] = null;
}
});
ref.ref().update(dataCopy, this._handle(def, ref));
Expand Down
10 changes: 5 additions & 5 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,13 @@
},

/**
* A utility for retrieving a DataSnapshot's key name. This
* is backwards-compatible with `name()` from Firebase 1.x.x
* and `key()` from Firebase 2.0.0+. Once support for Firebase
* A utility for retrieving a Firebase reference or DataSnapshot's
* key name. 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 AngularFire, this helper can be removed.
*/
getSnapshotKey: function(snapshot) {
return (typeof snapshot.key === 'function') ? snapshot.key() : snapshot.name();
getKey: function(refOrSnapshot) {
return (typeof refOrSnapshot.key === 'function') ? refOrSnapshot.key() : refOrSnapshot.name();

This comment has been minimized.

Copy link
@katowulf

katowulf Nov 12, 2014

Contributor

FYI - Angular has an isFunction: angular.isFunction(refOrSnapshot.key)

},

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ describe('$firebaseUtils', function () {
});
});

describe('#getSnapshotKey', function() {
describe('#getKey', function() {
it('should return the key name given a DataSnapshot', function() {
var snapshot = testutils.snap('data', 'foo');
expect($utils.getSnapshotKey(snapshot)).toEqual('foo');
expect($utils.getKey(snapshot)).toEqual('foo');
});
});

Expand Down

0 comments on commit f75c0e3

Please sign in to comment.