Skip to content

Commit

Permalink
Use new es6 style promises internally.
Browse files Browse the repository at this point in the history
There is more code that could be refactored to use it as well. Waiting to see what the community thinks before proceeding.
  • Loading branch information
jamestalmage committed Jan 15, 2015
1 parent ef27fce commit a7c767c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 25 deletions.
29 changes: 14 additions & 15 deletions src/FirebaseAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,24 +222,23 @@
*/
_routerMethodOnAuthPromise: function(rejectIfAuthDataIsNull) {
var ref = this._ref;
var deferred = this._q.defer();

function callback(authData) {
if (authData !== null) {
deferred.resolve(authData);
} else if (rejectIfAuthDataIsNull) {
deferred.reject("AUTH_REQUIRED");
} else {
deferred.resolve(null);
return this._utils.promise(function(resolve,reject){
function callback(authData) {
if (authData !== null) {
resolve(authData);
} else if (rejectIfAuthDataIsNull) {
reject("AUTH_REQUIRED");
} else {
resolve(null);
}

// Turn off this onAuth() callback since we just needed to get the authentication data once.
ref.offAuth(callback);
}

// Turn off this onAuth() callback since we just needed to get the authentication data once.
ref.offAuth(callback);
}

ref.onAuth(callback);

return deferred.promise;
ref.onAuth(callback);
});
},

/**
Expand Down
20 changes: 10 additions & 10 deletions src/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,16 +128,16 @@
}
applyLocally = !!applyLocally;

var def = $firebaseUtils.defer();
ref.transaction(valueFn, function(err, committed, snap) {
if( err ) {
def.reject(err);
}
else {
def.resolve(committed? snap : null);
}
}, applyLocally);
return def.promise;
return new $firebaseUtils.promise(function(resolve,reject){
ref.transaction(valueFn, function(err, committed, snap) {
if( err ) {
reject(err);
}
else {
resolve(committed? snap : null);
}
}, applyLocally);
});
},

$asObject: function () {
Expand Down

0 comments on commit a7c767c

Please sign in to comment.