Closed
Description
I was curious if you had any ideas about some type of utility to help with composing multiple ref functions that could possibly be added to this library? I'm thinking it would be similar to the composeEvents
function we talked about in #32.
I'm wondering if there is any way to memoize all the function calls so we can avoid this caveat when composing multiple refs? It would be really cool if this could be baked into composeEvents
as well.
This is my idea:
function memoize(fn) {
memoize.cache = {}
return function() {
var key = JSON.stringify(arguments)
if (memoize.cache[key]) {
return memoize.cache[key]
} else {
var val = fn.apply(this, arguments)
memoize.cache[key] = val
return val
}
}
}
function memoizeRefs(...fns) {
return node => {
fns.forEach(fn => memoize(fn))
}
}