joaogranado / react-updater

Functional stateful components made easy
9 stars 1 forks source link

Update cache strategy #15

Closed joaogranado closed 7 years ago

joaogranado commented 7 years ago

This updates the cache algorithm to use WeakMap that stores the state updater instead of an hash generated by the callback and the additional parameters. Creating an hash with a string representation of the additional parameters invalidated the cache and created a new handler even thought it was not necessary.

This change adds a limitation since if we reuse the state updater with different parameters it will attach the ones passed on the last call of update()/handle(). This is a tradeoff in order to keep the referential identity of the callback handlers across multiple renders.