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

Commit 3cb6742

Browse files
committed
Merge branch 'master' into kato-indexfor
Conflicts: src/FirebaseArray.js
2 parents 75a3f96 + 046d872 commit 3cb6742

File tree

9 files changed

+31
-27
lines changed

9 files changed

+31
-27
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@
3636
"devDependencies": {
3737
"lodash": "~2.4.1",
3838
"angular-mocks": "~1.2.18",
39-
"mockfirebase": "~0.4.0"
39+
"mockfirebase": "0.5.0"
4040
}
4141
}

src/FirebaseArray.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* manually invoked. Instead, one should create a $firebase object and call $asArray
66
* on it: <code>$firebase( firebaseRef ).$asArray()</code>;
77
*
8-
* Internally, the $firebase object depends on this class to provide 5 methods, which it invokes
8+
* Internally, the $firebase object depends on this class to provide 5 $$ methods, which it invokes
99
* to notify the array whenever a change has been made at the server:
1010
* $$added - called whenever a child_added event occurs
1111
* $$updated - called whenever a child_changed event occurs
@@ -15,8 +15,9 @@
1515
* $$process - called immediately after $$added/$$updated/$$moved/$$removed
1616
* to splice/manipulate the array and invokes $$notify
1717
*
18-
* Additionally, there is one more method of interest to devs extending this class:
18+
* Additionally, these methods may be of interest to devs extending this class:
1919
* $$notify - triggers notifications to any $watch listeners, called by $$process
20+
* $$getKey - determines how to look up a record's key (returns $id by default)
2021
*
2122
* Instead of directly modifying this class, one should generally use the $extendFactory
2223
* method to add or change how methods behave. $extendFactory modifies the prototype of
@@ -34,7 +35,7 @@
3435
*
3536
* // change how records are updated
3637
* $$updated: function(snap) {
37-
* return this.$getRecord(snap.name()).update(snap);
38+
* return this.$getRecord(snap.key()).update(snap);
3839
* }
3940
* });
4041
* </code></pre>
@@ -169,7 +170,7 @@
169170
*/
170171
$keyAt: function(indexOrItem) {
171172
var item = this._resolveItem(indexOrItem);
172-
return this._getKey(item);
173+
return this.$$getKey(item);
173174
},
174175

175176
/**
@@ -186,7 +187,7 @@
186187
// evaluate whether our key is cached and, if so, whether it is up to date
187188
if( !cache.hasOwnProperty(key) || self.$keyAt(cache[key]) !== key ) {
188189
// update the hashmap
189-
var pos = self.$list.findIndex(function(rec) { return self._getKey(rec) === key; });
190+
var pos = self.$list.findIndex(function(rec) { return self.$$getKey(rec) === key; });
190191
if( pos !== -1 ) {
191192
cache[key] = pos;
192193
}
@@ -364,22 +365,22 @@
364365
* @returns {string||null}
365366
* @private
366367
*/
367-
_getKey: function(rec) { //todo rename this to $$getId
368+
$$getKey: function(rec) {
368369
return angular.isObject(rec)? rec.$id : null;
369370
},
370371

371372
/**
372373
* Handles placement of recs in the array, sending notifications,
373374
* and other internals. Called by the $firebase synchronization process
374-
* after $$added, $$updated, $$moved, and $$removed
375+
* after $$added, $$updated, $$moved, and $$removed.
375376
*
376377
* @param {string} event one of child_added, child_removed, child_moved, or child_changed
377378
* @param {object} rec
378379
* @param {string} [prevChild]
379380
* @private
380381
*/
381382
$$process: function(event, rec, prevChild) {
382-
var key = this._getKey(rec);
383+
var key = this.$$getKey(rec);
383384
var changed = false;
384385
var curPos;
385386
switch(event) {
@@ -398,7 +399,7 @@
398399
changed = true;
399400
break;
400401
default:
401-
throw new Error('Invalid event type ' + event);
402+
throw new Error('Invalid event type: ' + event);
402403
}
403404
if( angular.isDefined(curPos) ) {
404405
// add it to the array
@@ -448,7 +449,7 @@
448449
if( i === 0 ) { i = this.$list.length; }
449450
}
450451
this.$list.splice(i, 0, rec);
451-
this._indexCache[this._getKey(rec)] = i;
452+
this._indexCache[this.$$getKey(rec)] = i;
452453
return i;
453454
},
454455

@@ -487,7 +488,7 @@
487488
// a $id or even a $id that is in the array, it must be an actual record
488489
// the fastest way to determine this is to use $getRecord (to avoid iterating all recs)
489490
// and compare the two
490-
var key = this._getKey(indexOrItem);
491+
var key = this.$$getKey(indexOrItem);
491492
var rec = this.$getRecord(key);
492493
return rec === indexOrItem? rec : null;
493494
}
@@ -548,4 +549,4 @@
548549
return FirebaseArray;
549550
}
550551
]);
551-
})();
552+
})();

src/firebase.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
}
228228
});
229229
var updated = batch(function(snap) {
230-
var rec = array.$getRecord(snap.name());
230+
var rec = array.$getRecord($firebaseUtils.getKey(snap));
231231
if( rec ) {
232232
var changed = array.$$updated(snap);
233233
if( changed ) {
@@ -236,7 +236,7 @@
236236
}
237237
});
238238
var moved = batch(function(snap, prevChild) {
239-
var rec = array.$getRecord(snap.name());
239+
var rec = array.$getRecord($firebaseUtils.getKey(snap));
240240
if( rec ) {
241241
var confirmed = array.$$moved(snap, prevChild);
242242
if( confirmed ) {
@@ -245,7 +245,7 @@
245245
}
246246
});
247247
var removed = batch(function(snap) {
248-
var rec = array.$getRecord(snap.name());
248+
var rec = array.$getRecord($firebaseUtils.getKey(snap));
249249
if( rec ) {
250250
var confirmed = array.$$removed(snap);
251251
if( confirmed ) {

tests/lib/module.testutils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ angular.module('testutils', ['firebase'])
3535
getPriority: function () {
3636
return angular.isDefined(pri) ? pri : null;
3737
},
38+
key: function() {
39+
return ref.ref().key();
40+
},
3841
name: function () {
39-
return ref.ref().name();
42+
return ref.ref().key();
4043
},
4144
child: function (key) {
4245
var childData = angular.isObject(data) && data.hasOwnProperty(key) ? data[key] : null;

tests/mocks/mocks.firebase.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
angular.module('mock.firebase', [])
33
.run(function($window) {
4-
MockFirebase.override();
5-
$window.Firebase = MockFirebase;
4+
$window.mockfirebase.override();
5+
$window.Firebase = $window.MockFirebase;
66
})
7-
.factory('Firebase', function() {
8-
return MockFirebase;
7+
.factory('Firebase', function($window) {
8+
return $window.MockFirebase;
99
});

tests/protractor/priority/priority.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ describe('Priority App', function () {
127127
data.makeItChange = true;
128128
snap.ref().setWithPriority(data, pri, function(err) {
129129
if( err ) { def.reject(err); }
130-
else { def.fulfill(snap.name()); }
130+
else { def.fulfill(snap.key()); }
131131
})
132132
}, def.reject);
133133
return def.promise;

tests/unit/FirebaseArray.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ describe('$FirebaseArray', function () {
235235
var resRef = whiteSpy.calls.argsFor(0)[0];
236236
expect(whiteSpy).toHaveBeenCalled();
237237
expect(resRef).toBeAFirebaseRef();
238-
expect(resRef.name()).toBe(expName);
238+
expect(resRef.key()).toBe(expName);
239239
expect(blackSpy).not.toHaveBeenCalled();
240240
});
241241

tests/unit/FirebaseObject.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('$FirebaseObject', function() {
3131

3232
describe('constructor', function() {
3333
it('should set the record id', function() {
34-
expect(obj.$id).toEqual($fb.$ref().name());
34+
expect(obj.$id).toEqual($fb.$ref().key());
3535
});
3636

3737
it('should accept a query', function() {

tests/unit/firebase.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('$firebase', function () {
112112
expect(whiteSpy).toHaveBeenCalled();
113113
expect(blackSpy).not.toHaveBeenCalled();
114114
var ref = whiteSpy.calls.argsFor(0)[0];
115-
expect(ref.name()).toBe(newId);
115+
expect(ref.key()).toBe(newId);
116116
});
117117

118118
it('should reject if fails', function() {
@@ -127,7 +127,7 @@ describe('$firebase', function () {
127127

128128
it('should save correct data into Firebase', function() {
129129
var spy = jasmine.createSpy('push callback').and.callFake(function(ref) {
130-
expect($fb.$ref().getData()[ref.name()]).toEqual({foo: 'pushtest'});
130+
expect($fb.$ref().getData()[ref.key()]).toEqual({foo: 'pushtest'});
131131
});
132132
$fb.$push({foo: 'pushtest'}).then(spy);
133133
flushAll();
@@ -324,7 +324,7 @@ describe('$firebase', function () {
324324
flushAll();
325325
var arg = spy.calls.argsFor(0)[0];
326326
expect(arg).toBeAFirebaseRef();
327-
expect(arg.name()).toBe('index');
327+
expect(arg.key()).toBe('index');
328328
});
329329

330330
it('should reject if failed', function() {

0 commit comments

Comments
 (0)