dai-shi / proxy-memoize

Intuitive magical memoization library with Proxy and WeakMap

Home Page:http://proxy-memoize.js.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible incorrect memoization?

mq2thez opened this issue · comments

Sample codebox here: https://codesandbox.io/s/pedantic-rubin-2g8i1?file=/src/proxy-memoize.test.ts

Essentially, I was trying to confirm via a test that I could pass to memoize an object that looked like { state, orderId } and have re-calculations work correctly.

In this case, the goal was to demonstrate that I could make changes to an unrelated "receipt" without triggering re-calculations, but that triggering a change to a receipt whose value was memoized would cause an update.

This worked correctly in my first version, which tested that I could update receipt 7 without needing a recalculation for receipt 5.

However, when I started also getting the value for receipt 6, I the final re-calculation was not performed correctly.

That is:

  • receipt 5's memoized value updated correctly if I had not calculated a value for receipt 6
  • receipt 5's memoized value does not seem to update correctly if I had calculated a value for receipt 6

This looks,,, unexpected. I need to sit back and investigate more in deep.
Thanks for reporting. Meanwhile, if you find anything further, please let me know.
(I didn't do tests with size > 1 much, but that seems unrelated for this...)

@dai-shi Interestingly enough, if I take out the memoization of the orderId: 6 case, it works fine.

Ooookay, there was a bug.

(I didn't do tests with size > 1 much

This is it. Will create a PR.