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

Commit a7c767c

Browse files
committed
Use new es6 style promises internally.
There is more code that could be refactored to use it as well. Waiting to see what the community thinks before proceeding.
1 parent ef27fce commit a7c767c

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

src/FirebaseAuth.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -222,24 +222,23 @@
222222
*/
223223
_routerMethodOnAuthPromise: function(rejectIfAuthDataIsNull) {
224224
var ref = this._ref;
225-
var deferred = this._q.defer();
226225

227-
function callback(authData) {
228-
if (authData !== null) {
229-
deferred.resolve(authData);
230-
} else if (rejectIfAuthDataIsNull) {
231-
deferred.reject("AUTH_REQUIRED");
232-
} else {
233-
deferred.resolve(null);
226+
return this._utils.promise(function(resolve,reject){
227+
function callback(authData) {
228+
if (authData !== null) {
229+
resolve(authData);
230+
} else if (rejectIfAuthDataIsNull) {
231+
reject("AUTH_REQUIRED");
232+
} else {
233+
resolve(null);
234+
}
235+
236+
// Turn off this onAuth() callback since we just needed to get the authentication data once.
237+
ref.offAuth(callback);
234238
}
235239

236-
// Turn off this onAuth() callback since we just needed to get the authentication data once.
237-
ref.offAuth(callback);
238-
}
239-
240-
ref.onAuth(callback);
241-
242-
return deferred.promise;
240+
ref.onAuth(callback);
241+
});
243242
},
244243

245244
/**

src/firebase.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,16 @@
128128
}
129129
applyLocally = !!applyLocally;
130130

131-
var def = $firebaseUtils.defer();
132-
ref.transaction(valueFn, function(err, committed, snap) {
133-
if( err ) {
134-
def.reject(err);
135-
}
136-
else {
137-
def.resolve(committed? snap : null);
138-
}
139-
}, applyLocally);
140-
return def.promise;
131+
return new $firebaseUtils.promise(function(resolve,reject){
132+
ref.transaction(valueFn, function(err, committed, snap) {
133+
if( err ) {
134+
reject(err);
135+
}
136+
else {
137+
resolve(committed? snap : null);
138+
}
139+
}, applyLocally);
140+
});
141141
},
142142

143143
$asObject: function () {

0 commit comments

Comments
 (0)