sc0ttj / component

A tiny library for isomorphic JavaScript components
MIT License
2 stars 1 forks source link

Feature: add memoization (caching) #31

Open sc0ttj opened 3 years ago

sc0ttj commented 3 years ago

memoization built-in to Component

I could update Component to (optionally) memoize some of the following functions by default:

Ideally, this would be achieved simply by doing:

myComponent.memoize(true);

or for more control:

myComponent.memoize({
    eq: true,
    setState: true,
    view: true,
    css: true,
    domDiff: true,
    html: true,
    htmel: true,
  })

Possible sources:

Notes:

Component.eq - Component already includes a very fast, React-compatible object equality thing.. It could be shoe horned into any of the above solutions that use shallow object comparison, to make them even smaller.

And maybe it could be memoized itself, so as not to always have to perform the comparisons..


a memoization addon module

Also see any lightweight and standalone implementations of the useMemo() React hook..

This can be used by users to add memoization to any functions they create or define, such as:


manually adding caching here & there

Use patterns like this: https://flaviocopes.com/javascript-memoization/