Skip to content

Instantly share code, notes, and snippets.

@greypants
Created August 16, 2016 16:06
Show Gist options
  • Save greypants/8b0aa81003e0915859d53c203a93583e to your computer and use it in GitHub Desktop.
Save greypants/8b0aa81003e0915859d53c203a93583e to your computer and use it in GitHub Desktop.
Object compare
function jsonEqual (a, b) {
return JSON.stringify(a) === JSON.stringify(b)
}
function originalIfUnchanged(state, nextState) {
if(state === nextState) {
return state
}
return jsonEqual(state, nextState) ? state : nextState
}
function test() {
const a = []
let count = 9999
while(count > 0) {
count--
a.push({
x: 902,
y: -200,
label: 'Some node name',
id: '82044-2984-2vuy20-34820yhv',
meta: 'foobar'
})
}
const b = [].concat(a)
console.time()
originalIfUnchanged(a, b)
console.timeEnd()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment