Last active
November 18, 2016 22:59
-
-
Save nt1m/224176496efab74bf4e1 to your computer and use it in GitHub Desktop.
console.diff(oldObj, newObj)
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
// 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