我有一个连接到商店的容器,它每秒更新一次:
return ({ match, ui }, { matchId }) => ({
value: match.getIn([matchId, 'masterCurrentTime'], 0), // about every second
min: ui.get('seekStart'),
max: ui.get('seekEnd'),
highlightList: selectHighlights(matchId) // i only want to do this on first render
});
然而,其中一个属性 (highlightList) 做了以下两件事之一:
1) 从 sessionStorage 返回一个值
或者
2) 下载一个文件,保存到 sessionStorage 然后返回
当然,我不想每秒都这样做,只是第一次。
我创建了一个这样的选择器
const selectHighlights = createSelector(
matchId => matchId,
matchId => {
if (matchId !== null) {
getTimelineWithFilter(matchId, ['round_start'])
.then(timeline => {
console.log(timeline);
return timeline;
})
.catch(error => {
throw new Error('failed to load highlights', error);
});
}
return null;
}
);
但它不起作用,它没有被渲染。但是,如果我做一个替代版本,我将结果存储在一个变量中,然后查询它,事情就会起作用。它只运行一次并按我喜欢的方式执行
// highlightList: currentTimeline === undefined ? loadHighlights(matchId) : currentTimeline,
我只是想学习如何以正确的方式做到这一点,有这方面知识的人可以给我一些最佳实践技巧吗?