dai-shi/proxy-compare

Nested comparison

joelmoss opened this issue · 3 comments

Apologies if I'm missing something here, but shouldn't the following test pass?

const s1 = { a: { b: 'b', c: 'c' } }
const a1 = new WeakMap()
const p1 = createDeepProxy(s1, a1)
p1.a
expect(isDeepChanged(s1, { a: { b: 'b', c: 'c' } }, a1)).toBe(false)

s1 and the given objects are identical, so isDeepChanged should be false, and from my understanding, this is not a referential comparison.

Hopefully you can clear this up for me. thx

It's based on immutable (and shared?) state model, so it doesn't pass and it's intentional.
It checks Object.is at the leaf node of affectted, which is .a in this case.
Also, if it finds equal node at the intermediate node, we stop traversing even if it's not the leaf of affected. This principal improves performance.

(One regret: I shouldn't have named "Deep" which misleads deep-equal.)

One regret: I shouldn't have named "Deep" which misleads deep-equal.

Ah well that is definately where I got confused. thx for the explanation.

I would definitely rename them when I had a chance. (maybe when we introduce breaking changes in v2. no such plan yet.)
Elaborating more in README would be helpful, if we got more attention to this library.
Closing this issue, but suggestions are always welcome.