Created
August 16, 2016 16:06
-
-
Save greypants/8b0aa81003e0915859d53c203a93583e to your computer and use it in GitHub Desktop.
Object compare
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
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