andrewplummer / Sugar

A Javascript library for working with native objects.
https://sugarjs.com/
MIT License
4.54k stars 305 forks source link

isEqual is false, JSON.stringify comparison is true... #557

Closed thomasf1 closed 8 years ago

thomasf1 commented 8 years ago

I´ve got a quite complex data structure (too much to post), where I do this:

console.log "results match?", Sugar.Object.isEqual res1, res2
console.log "results match2?", JSON.stringify(res1) is JSON.stringify(res2)

and I get that:

I20160901-21:51:57.367(1)? results match? false
I20160901-21:51:57.368(1)? results match2? true

I´m open to debug that to help with sugar.js... But maybe you´ve already got some ideas?

andrewplummer commented 8 years ago

Hi, thanks for this!

I don't have any immediate ideas. They should be equivalent. If you can simplify it to the core structure that isn't matching I can help debug.

thomasf1 commented 8 years ago

Ok, I´ve done some investigating, and it´s a special case that is probably negligible...

It´s because we create empty ReactiveDicts (a special Object type used in Meteor) which in JSON serializes to the same, but two of those compared (natively) in JS are not equal. Most likely a thing they could/should fix...

PS: It took a while, 450kb of JSON for each result seem to break both the coffeescript compiler as well as cause issues with JSON.parse :o

vendethiel commented 8 years ago

The Coffee compiler does a lot of lexing for objects, so it might get very slow, yeah. Look into CSON maybe?

thomasf1 commented 8 years ago

Thanks, just needed that for the debugging and fixed it... it just took a bit of extra time...

And again, thanks for your great Library, guys!

andrewplummer commented 8 years ago

Thanks! Feel free to reopen if the issue appears again.