Last active
January 30, 2017 16:41
-
-
Save katowulf/1924bab5795a56effc19 to your computer and use it in GitHub Desktop.
Modifying toJSON for $firebaseArray and $firebaseObject in AngularFire
This file contains hidden or 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('$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; | |
} | |
} | |
}); | |
}); |
This file contains hidden or 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('$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; | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.