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

Commit 5d58be7

Browse files
committed
Merge remote-tracking branch 'upstream/master' into utils-node-resolver
Conflicts: src/FirebaseAuth.js
2 parents 57330cc + 38c509f commit 5d58be7

File tree

8 files changed

+289
-65
lines changed

8 files changed

+289
-65
lines changed

.jshintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"forin": true,
1010
"indent": 2,
1111
"latedef": true,
12+
"node": true,
1213
"noempty": true,
1314
"nonbsp": true,
1415
"strict": true,

changelog.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
deprecated - Passing in credentials to the user management methods of `$firebaseAuth` as individual arguments has been deprecated in favor of a single credentials argument.
2+
deprecated - Deprecated `$firebaseAuth.$sendPasswordResetEmail()` in favor of the functionally equivalent `$firebaseAuth.$resetPassword()`.

src/FirebaseAuth.js

Lines changed: 203 additions & 45 deletions
Large diffs are not rendered by default.

src/firebase.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,33 +72,36 @@
7272
},
7373

7474
$remove: function (key) {
75-
var ref = this._ref, self = this, promise;
75+
var ref = this._ref, self = this;
7676
var def = $firebaseUtils.defer();
7777
if (arguments.length > 0) {
7878
ref = ref.ref().child(key);
7979
}
8080
if( angular.isFunction(ref.remove) ) {
8181
// self is not a query, just do a flat remove
8282
ref.remove(self._handle(def, ref));
83-
promise = def.promise;
8483
}
8584
else {
86-
var promises = [];
8785
// self is a query so let's only remove the
8886
// items in the query and not the entire path
8987
ref.once('value', function(snap) {
88+
var promises = [];
9089
snap.forEach(function(ss) {
9190
var d = $firebaseUtils.defer();
92-
promises.push(d);
93-
ss.ref().remove(self._handle(d, ss.ref()));
91+
promises.push(d.promise);
92+
ss.ref().remove(self._handle(d));
9493
}, self);
94+
$firebaseUtils.allPromises(promises)
95+
.then(function() {
96+
def.resolve(ref);
97+
},
98+
function(err){
99+
def.reject(err);
100+
}
101+
);
95102
});
96-
promise = $firebaseUtils.allPromises(promises)
97-
.then(function() {
98-
return ref;
99-
});
100103
}
101-
return promise;
104+
return def.promise;
102105
},
103106

104107
$update: function (key, data) {

src/utils.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
var queue = [];
6363
var start;
6464
var cancelTimer;
65+
var runScheduledForNextTick;
6566

6667
// returns `fn` wrapped in a function that queues up each call event to be
6768
// invoked later inside fo runNow()
@@ -77,14 +78,17 @@
7778
}
7879

7980
// clears the current wait timer and creates a new one
80-
// however, if maxWait is exceeded, calls runNow() immediately
81+
// however, if maxWait is exceeded, calls runNow() on the next tick.
8182
function resetTimer() {
8283
if( cancelTimer ) {
8384
cancelTimer();
8485
cancelTimer = null;
8586
}
8687
if( start && Date.now() - start > maxWait ) {
87-
utils.compile(runNow);
88+
if(!runScheduledForNextTick){
89+
runScheduledForNextTick = true;
90+
utils.compile(runNow);
91+
}
8892
}
8993
else {
9094
if( !start ) { start = Date.now(); }
@@ -96,6 +100,7 @@
96100
function runNow() {
97101
cancelTimer = null;
98102
start = null;
103+
runScheduledForNextTick = false;
99104
var copyList = queue.slice(0);
100105
queue = [];
101106
angular.forEach(copyList, function(parts) {
@@ -114,7 +119,7 @@
114119
* @param {int} [maxWait] max milliseconds to wait before sending out, defaults to wait * 10 or 100
115120
*/
116121
debounce: function(fn, ctx, wait, maxWait) {
117-
var start, cancelTimer, args;
122+
var start, cancelTimer, args, runScheduledForNextTick;
118123
if( typeof(ctx) === 'number' ) {
119124
maxWait = wait;
120125
wait = ctx;
@@ -130,25 +135,29 @@
130135
if( !maxWait ) { maxWait = wait*10 || 100; }
131136

132137
// clears the current wait timer and creates a new one
133-
// however, if maxWait is exceeded, calls runNow() immediately
138+
// however, if maxWait is exceeded, calls runNow() on the next tick.
134139
function resetTimer() {
135140
if( cancelTimer ) {
136141
cancelTimer();
137142
cancelTimer = null;
138143
}
139144
if( start && Date.now() - start > maxWait ) {
140-
utils.compile(runNow);
145+
if(!runScheduledForNextTick){
146+
runScheduledForNextTick = true;
147+
utils.compile(runNow);
148+
}
141149
}
142150
else {
143151
if( !start ) { start = Date.now(); }
144152
cancelTimer = utils.wait(runNow, wait);
145153
}
146154
}
147155

148-
// Clears the queue and invokes all of the functions awaiting notification
156+
// Clears the queue and invokes the debounced function with the most recent arguments
149157
function runNow() {
150158
cancelTimer = null;
151159
start = null;
160+
runScheduledForNextTick = false;
152161
fn.apply(ctx, args);
153162
}
154163

tests/travis.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
grunt build
22
grunt test:unit
3-
if [ $SAUCE_ACCESS_KEY ]; then
4-
grunt sauce:unit
3+
#if [ $SAUCE_ACCESS_KEY ]; then
4+
#grunt sauce:unit
55
#grunt sauce:e2e
6-
fi
6+
#fi

tests/unit/firebase.spec.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ describe('$firebase', function () {
239239
var ref = new Firebase('Mock://').child('ordered').limit(2);
240240
var $fb = $firebase(ref);
241241
$fb.$remove().then(spy);
242-
flushAll();
242+
flushAll(ref);
243+
flushAll(ref);
243244
expect(spy).toHaveBeenCalledWith(ref);
244245
});
245246

@@ -305,6 +306,20 @@ describe('$firebase', function () {
305306
}
306307
});
307308
});
309+
310+
it('should wait to resolve promise until data is actually deleted',function(){
311+
var ref = new Firebase('Mock://').child('ordered').limit(2);
312+
var $fb = $firebase(ref);
313+
var resolved = false;
314+
$fb.$remove().then(function(){
315+
resolved = true;
316+
});
317+
try {$timeout.flush();} catch(e){} //this may actually throw an error
318+
expect(resolved).toBe(false);
319+
flushAll(ref);
320+
flushAll(ref);
321+
expect(resolved).toBe(true);
322+
});
308323
});
309324

310325
describe('$update', function() {

tests/unit/utils.spec.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,42 @@ describe('$firebaseUtils', function () {
5151
});
5252
});
5353

54+
describe('#debounce', function(){
55+
it('should trigger function with arguments',function(){
56+
var spy = jasmine.createSpy();
57+
$utils.debounce(spy,10)('foo', 'bar');
58+
$timeout.flush();
59+
expect(spy).toHaveBeenCalledWith('foo', 'bar');
60+
});
61+
62+
it('should only trigger once, with most recent arguments',function(){
63+
var spy = jasmine.createSpy();
64+
var fn = $utils.debounce(spy,10);
65+
fn('foo', 'bar');
66+
fn('baz', 'biz');
67+
$timeout.flush();
68+
expect(spy.calls.count()).toBe(1);
69+
expect(spy).toHaveBeenCalledWith('baz', 'biz');
70+
});
71+
72+
it('should only trigger once (timing corner case)',function(){
73+
var spy = jasmine.createSpy();
74+
var fn = $utils.debounce(spy, null, 1, 2);
75+
fn('foo', 'bar');
76+
var start = Date.now();
77+
78+
// block for 3ms without releasing
79+
while(Date.now() - start < 3){ }
80+
81+
fn('bar', 'baz');
82+
fn('baz', 'biz');
83+
expect(spy).not.toHaveBeenCalled();
84+
$timeout.flush();
85+
expect(spy.calls.count()).toBe(1);
86+
expect(spy).toHaveBeenCalledWith('baz', 'biz');
87+
});
88+
});
89+
5490
describe('#updateRec', function() {
5591
it('should return true if changes applied', function() {
5692
var rec = {};

0 commit comments

Comments
 (0)