Skip to content

Instantly share code, notes, and snippets.

@nt1m
Last active November 18, 2016 22:59
Show Gist options
  • Save nt1m/224176496efab74bf4e1 to your computer and use it in GitHub Desktop.
Save nt1m/224176496efab74bf4e1 to your computer and use it in GitHub Desktop.
console.diff(oldObj, newObj)
// This snippet lets you watch for properties removed from an object
console.diff = (object, id) => {
let obj = Object.keys(object);
if (!id) {
id = "diff" + Date.now();
console.lastDiffId = id;
}
let listener = addEventListener("diffEnd", (e) => {
if (id && e.detail.id != id) {
return;
}
let newObj = Object.keys(object);
newObj = newObj.filter((item) => {
return !obj.contains(item);
});
console.log(newObj);
removeEventListener(listener);
});
}
console.diffEnd = (id) => {
if (!id) {
id = console.lastDiffId;
}
window.dispatchEvent(new CustomEvent("diffEnd", {
detail: {id}
}));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment