Skip to content

Instantly share code, notes, and snippets.

@michael-mckenna
Created August 2, 2017 01:03
Show Gist options
  • Save michael-mckenna/312e0eea9449ef0c47700a943c1e7fc6 to your computer and use it in GitHub Desktop.
Save michael-mckenna/312e0eea9449ef0c47700a943c1e7fc6 to your computer and use it in GitHub Desktop.
Logs:
Starting function
Changes in realm at: /globalUsers
Changes in Model: GlobalUser
- object inserted at position 4 : RealmObject { username: 'test', email: '[email protected]' }
Code:
console.log("Starting function");
// add your initialization code here
module.exports = function(changeEvent) {
// event handler code goes here
console.log("Changes in realm at:", changeEvent.path);
var realm = changeEvent.realm;
for (var className in changeEvent.changes) {
var changes = changeEvent.changes[className];
var objects = realm.objects(className);
console.log("Changes in Model:", className);
var i, pos;
for (i = 0; i < changes.insertions.length; i++) {
pos = changes.insertions[i];
console.log("- object inserted at position", pos, ":", objects[pos]);
}
for (i = 0; i < changes.modifications.length; i++) {
pos = changes.modifications[i];
console.log("- object modified at position", pos, ":", objects[pos]);
}
for (i = 0; i < changes.deletions.length; i++) {
pos = changes.deletions[i];
console.log("- object deleted at position", pos);
}
}
console.log("");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment