获得快速记忆的结果

时间:2018-10-15 11:55:36

标签: javascript reactjs redux

我将fast-memoizeImmutable JSReact一起使用。 目前,我正在记忆这样的变量

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…

如何访问存储的对象?

1 个答案:

答案 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]),
    };
}