Skip to content

Instantly share code, notes, and snippets.

@katowulf
Last active January 30, 2017 16:41
Show Gist options
  • Save katowulf/1924bab5795a56effc19 to your computer and use it in GitHub Desktop.
Save katowulf/1924bab5795a56effc19 to your computer and use it in GitHub Desktop.
Modifying toJSON for $firebaseArray and $firebaseObject in AngularFire
app.factory('$firebaseArrayEncrypted', function($firebaseArray, $firebaseUtils) {
return $firebaseArray.extend({
$$added: function(snap) {
var rec = $firebaseArray.prototype.$$added.apply(this, arguments);
rec.prototype.toJSON = function() {
var data = $firebaseUtils.toJSON(this);
// apply encryption or other manipulation of fields
return data;
}
}
});
});
app.factory('$firebaseObjectEncrypted', function($firebaseObject, $firebaseUtils) {
return $firebaseObject.extend({
toJSON: function() {
var data = $firebaseUtils.toJSON(this); // just a utility to deal with $value, $priority, et al
// apply encryption or other manipulation of fields
return data;
}
});
});
@benjaminsuch
Copy link

Hello kato, I don't think that this work, since $firebaseUtils.toJSON() checks for a toJSON function and then calls it, which calls $firebaseUtils.toJSON() again, causing a infinite loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment