我将fast-memoize与Immutable JS
和React
一起使用。
目前,我正在记忆这样的变量
function stateToProps(state) {
const memoMe = memoize(state.getIn(...);
console.log(memoMe);
return {
headline: state.getIn(...),
memoMe: memoMe,
};
}
但是,memoMe
的日志给了我
ƒ monadic (fn, cache, serializer, arg) {
var cacheKey = isPrimitive(arg) ? arg : serializer(arg)
var computedValue = cache.get(cacheKey)
if (typeof computedValue === 'undefined') {
computedV…
如何访问存储的对象?
答案 0 :(得分:0)
库将函数作为参数而不是值。它返回一个新函数,如果将相同的参数传递给该函数,则该函数将返回缓存的值。所以你会做这样的事情,
function stateToProps(state) {
const memoizeFn = memoize(state.getIn);
//memoizeFn is a function which will return cached result if arguments are repeated
return {
//first call to memoizeFn, memoizeFn will compute result using state.getIn
headline: memoizeFn([a,b]),
//second call with same arguments, memoizeFn will return cached results
memoMe: memoizeFn([a, b]),
};
}