Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 55fa523

Browse files
committed
Merge pull request #454 from firebase/jw-getKey-rename
Renamed utils.getSnapshotKey() to utils.getKey()
2 parents cd4ef13 + f75c0e3 commit 55fa523

File tree

5 files changed

+15
-15
lines changed

5 files changed

+15
-15
lines changed

src/FirebaseArray.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,14 +256,14 @@
256256
*/
257257
$$added: function(snap, prevChild) {
258258
// check to make sure record does not exist
259-
var i = this.$indexFor($firebaseUtils.getSnapshotKey(snap));
259+
var i = this.$indexFor($firebaseUtils.getKey(snap));
260260
if( i === -1 ) {
261261
// parse data and create record
262262
var rec = snap.val();
263263
if( !angular.isObject(rec) ) {
264264
rec = { $value: rec };
265265
}
266-
rec.$id = $firebaseUtils.getSnapshotKey(snap);
266+
rec.$id = $firebaseUtils.getKey(snap);
267267
rec.$priority = snap.getPriority();
268268
$firebaseUtils.applyDefaults(rec, this.$$defaults);
269269

@@ -279,7 +279,7 @@
279279
* @param snap
280280
*/
281281
$$removed: function(snap) {
282-
var rec = this.$getRecord($firebaseUtils.getSnapshotKey(snap));
282+
var rec = this.$getRecord($firebaseUtils.getKey(snap));
283283
if( angular.isObject(rec) ) {
284284
this._process('child_removed', rec);
285285
}
@@ -292,7 +292,7 @@
292292
* @param snap
293293
*/
294294
$$updated: function(snap) {
295-
var rec = this.$getRecord($firebaseUtils.getSnapshotKey(snap));
295+
var rec = this.$getRecord($firebaseUtils.getKey(snap));
296296
if( angular.isObject(rec) ) {
297297
// apply changes to the record
298298
var changed = $firebaseUtils.updateRec(rec, snap);
@@ -311,7 +311,7 @@
311311
* @param {string} prevChild
312312
*/
313313
$$moved: function(snap, prevChild) {
314-
var rec = this.$getRecord($firebaseUtils.getSnapshotKey(snap));
314+
var rec = this.$getRecord($firebaseUtils.getKey(snap));
315315
if( angular.isObject(rec) ) {
316316
rec.$priority = snap.getPriority();
317317
this._process('child_moved', rec, prevChild);

src/FirebaseObject.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
value: this.$$conf
5656
});
5757

58-
this.$id = $firebaseUtils.getSnapshotKey($firebase.$ref().ref());
58+
this.$id = $firebaseUtils.getKey($firebase.$ref().ref());
5959
this.$priority = null;
6060

6161
$firebaseUtils.applyDefaults(this, this.$$defaults);

src/firebase.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
// the entire Firebase path
6262
ref.once('value', function(snap) {
6363
snap.forEach(function(ss) {
64-
if( !dataCopy.hasOwnProperty($firebaseUtils.getSnapshotKey(ss)) ) {
65-
dataCopy[$firebaseUtils.getSnapshotKey(ss)] = null;
64+
if( !dataCopy.hasOwnProperty($firebaseUtils.getKey(ss)) ) {
65+
dataCopy[$firebaseUtils.getKey(ss)] = null;
6666
}
6767
});
6868
ref.ref().update(dataCopy, this._handle(def, ref));

src/utils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,13 @@
342342
},
343343

344344
/**
345-
* A utility for retrieving a DataSnapshot's key name. This
346-
* is backwards-compatible with `name()` from Firebase 1.x.x
347-
* and `key()` from Firebase 2.0.0+. Once support for Firebase
345+
* A utility for retrieving a Firebase reference or DataSnapshot's
346+
* key name. This is backwards-compatible with `name()` from Firebase
347+
* 1.x.x and `key()` from Firebase 2.0.0+. Once support for Firebase
348348
* 1.x.x is dropped in AngularFire, this helper can be removed.
349349
*/
350-
getSnapshotKey: function(snapshot) {
351-
return (typeof snapshot.key === 'function') ? snapshot.key() : snapshot.name();
350+
getKey: function(refOrSnapshot) {
351+
return (typeof refOrSnapshot.key === 'function') ? refOrSnapshot.key() : refOrSnapshot.name();
352352
},
353353

354354
/**

tests/unit/utils.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,10 @@ describe('$firebaseUtils', function () {
174174
});
175175
});
176176

177-
describe('#getSnapshotKey', function() {
177+
describe('#getKey', function() {
178178
it('should return the key name given a DataSnapshot', function() {
179179
var snapshot = testutils.snap('data', 'foo');
180-
expect($utils.getSnapshotKey(snapshot)).toEqual('foo');
180+
expect($utils.getKey(snapshot)).toEqual('foo');
181181
});
182182
});
183183

0 commit comments

Comments
 (0)