gpt4 book ai didi

javascript - 获取快速内存的结果

转载 作者:行者123 更新时间:2023-11-30 06:21:25 25 4
gpt4 key购买 nike

我正在使用 fast-memoize使用 Immutable 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…

如何访问存储的对象?

最佳答案

库将函数作为参数,而不是值。它返回一个新函数,如果传递给它的参数相同,则该函数返回缓存的值。所以你会做这样的事情,

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

关于javascript - 获取快速内存的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52816223/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com