You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've just discovered the source of a bug in my app caused by the loss of referential equality.
Here's the pseudo-code:
constmemoizedMap=computedFn((shape)=>newFacade(shape))constprevFacades=shapes.map(memoizedMap);// reverse to change index but not valuesshapes.reverse();// reverse back to original ordershapes.reverse();constnextFacades=shapes.map(memoizedMap);// throws, but I expected it to keep referential equality assert(prevFacades[0]===nextFacades[0])
It is because the memoised function is called with:
memoizedMap(shape,index,shapes)
So even if the shape is the same, the index is included in the cache key and requires re-computation of the value.
I've just discovered the source of a bug in my app caused by the loss of referential equality.
Here's the pseudo-code:
It is because the memoised function is called with:
So even if the shape is the same, the index is included in the cache key and requires re-computation of the value.
Now I realise it is my fault for not following that rule: Don't use functions as callbacks unless they're designed for it but I also thought having stricter type could help, so I implemented this patch to reject extra arguments:
With this
shapes.map(memoizedMap);
would be enforce passing the arguments explicitlyWould you consider adding this?
The text was updated successfully, but these errors were encountered: