-
-
Save katowulf/e8f35702a79eb9524e48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.factory('JoinedUser', function($firebaseObject) { | |
return $firebaseObject.$extend({ | |
$$updated: function(snapshot) { | |
if( !this.profile ) { | |
// back up and get a reference to the profile path | |
var ref = snapshot.ref().parent().child('profile/' + snapshot.key()); | |
this.profile = $firebaseObject(ref); | |
} | |
}, | |
/* | |
* If we want to automatically save the profile when saving the user object, we could uncomment this | |
$save: function() { | |
if( this.profile ) { | |
// we save this blindly and don't handle errors or wait for results here | |
this.profile.$save(); | |
} | |
return $firebaseObject.prototype.$save.call(this); | |
}, | |
*/ | |
$destroy: function() { | |
if( this.profile ) { | |
// stop listening for changes to the profile | |
this.profile.$destroy(); | |
} | |
$firebaseObject.prototype.$destroy.call(this); | |
} | |
toJSON: function() { | |
// don't returt the profile when saving this object | |
var json = $firebaseObject.prototype.toJSON.apply(this, arguments); | |
delete json.profile; | |
return json; | |
} | |
}); | |
}); | |
// usage | |
app.controller('UseTheService', function($scope, JoinedUser) { | |
var ref = new Firebase("https://<YOUR-FIREBASE-APP>.firebaseio.com/").child('users/kato'); | |
$scope.user = new JoinedUser(ref); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yea dude, thanks so much for taking the time out of your day to educate me; I'm very appreciative of that, catch you tomorrow! ^_^