dai-shi / proxy-memoize

Intuitive magical memoization library with Proxy and WeakMap
http://proxy-memoize.js.org/
MIT License
719 stars 16 forks source link

Nested calls doesn't work as expected... #61

Closed groyee closed 1 year ago

groyee commented 1 year ago

Not sure if this is a bug or expected behavior:

I have the following selectors:

export const GetSelectorA = memoize(({ state, props }: { state: RootState; props: any }) => {
   return getSelectorA({
        itemA: state.itemA,
        itemB: GetSelectorB({state, props})
    });
}

// This selector doesn't have direct use of state.itemA
export const GetSelectorB = memoize(({ state, props }: { state: RootState; props: any }) => {
   return getSelectorB({
        itemC: GetSelectorC({state, props})
    });
}

// This selector depends on state.itemA
export const GetSelectorC = memoize(({ state, props }: { state: RootState; props: any }) => {
   return getSelectorC({
        itemA: state.itemA,
    });
}

When state.itemA is changed, GetSelectorA is being called which is good. But it doesn't call GetSelectorB (It takes the memoized version) because I guess GetSelectorB doesn't have direct use of state.itemA? But GetSelectorB depends on GetSelectorC which should be updated when state.itemA is changed...

Is it a bug or am I missing something here?

dai-shi commented 1 year ago

Hi, I just opened #62, which has the test. It's currently passing. Can you make it to fail?

groyee commented 1 year ago

I tried to make it fail but I couldn't. I went back to my code to find the difference with the test you wrote and I realized that the problem is on my side. My live reload wasn't working properly and the changes I was making didn't take affect.

Apologies for that. My bad. I will close this issue.