Open user753 opened 5 years ago
This is not only "when" question, but also "why". You might find some answers in my article How I wrote the world’s fastest memoization library, and in the series of articles and "usage-tracking" packages @dai-shi have created.
In short - proxyEqual
is not shallowEqual
. Even if they have similar signatures and doing almost the same job - they are different. proxyEqual
requires one more argument, which contains all keys you are going to compare, and that list is generated by a factual usage, ie usage tracking.
But anyway there are 3 function to use - proxyEqual
, proxyShallow
, proxyShallowEqual
, and dont forget about proxyState
. And what is the difference.
proxyEqual
- the first comparison functions. Given state a
, b
and usage c
- find all "end" values in c
and perform the comparison. That is "end values" - in short that's a leafs.
Having used keys as a
, a.b
, a.b.c
, a.b.d
it would return only a.b.c
and a.b.d
, and thus values of a
and a.b
would be ignored.proxyShallow
- this is comparison optimisation function. Let's imagine you have a big state, with big, or deep tracked usage. proxyEqual
would compare the "end" values, but what if state is not changed at all? proxyShallow
is comparing everything except end values. It uses trie structure to find all keys with deeper reads inside, and thus you could make a faster comparison. And I am going to delete this function.proxyShallowEqual
is the best of two worlds, and I encourage you to use it. It performs shallow and "end" comparison simultaneously, making the whole process much faster.proxyCompare
, which is low level comparison, and from some point of view is shallowEqual
, but there are nuances.And proxyState
is providing the right memoization orchestration to make it even faster.
And look like it's time to update documentation :)
And look like it's time to update documentation :)
It would be great. d.ts file doesn't even have proxyShallowEqual
.
Also, there is a typo in package.json
"types": "proxyqual.d.ts",
If I understand correctly it's just a slightly better version of
shallowEqual
but with the cost of proxy usage. With consideration of the proxy cost can I assume that it always works faster thanshallowEqual
? Why would I want to useproxyShalloow
instead ofproxyEqual
?