Reputation: 321
Granted, I just started with AngularFire and Firebase, but, it seems quite transparent, and well documented. Yet, there's one thing that doesn't make sense to me;
AngularFire has a $set function you can use to set values in the backend storage. From what I've read, in version 1.0.0 they deprecated this function, and it is now just "set" (without the $ sign). Difference seems to me that $set used to return a promise object, so one could chain functions, where as the new set function returns nothing it seems...
For instance, when I have this code:
function createprofile(authData, user){
return fbutil.ref('profiles/'+authData.uid).set({
firstname: user.firstname,
lastname: user.lastname
});
};
And my fbutil.ref function is as follows:
function firebaseRef(path) {
var ref = new $window.Firebase(FB_BASEURL);
var args = Array.prototype.slice.call(arguments);
if( args.length ) {
ref = ref.child(pathRef(args));
}
return ref;
}
How can I do something with the "createprofile"'s return value? At the moment, it's always "undefined". I was hoping I could just chain after a "set" function to make sure it actually worked before doing something else...
Upvotes: 1
Views: 587
Reputation: 40582
You haven't called AngularFire set (there is no method by this name in any AngularFire service, as you've noted). You've called set() using the Firebase SDK, which does not return a promise, but expects you to pass in a callback. Brushing up on fundamentals of writing data would help here.
function createprofile(authData, user){
var def = $q.defer();
fbutil.ref('profiles/'+authData.uid).set({
firstname: user.firstname,
lastname: user.lastname
}, function(err) {
if( err ) { def.reject(err); }
else { def.resolve(); }
});
return def.promise;
};
Internally, AngularFire uses a makeNodeResolver() utility to convert callbacks to promises. You could use that as an example of the above approach.
Upvotes: 1