我有这段代码。:
const OnLoadStatisticsTypes = loadOnMount('statisticsTypes', fetchStatisticsTypes, 'root')(StatisticBalloons)
export default loadOnMount('appsStatistics', fetchAppsStatistics, 'root')(OnLoadStatisticsTypes)
但我不知道如何做得更好。我试过了。:
export default compose(
loadOnMount('appsStatistics', fetchAppsStatistics, 'root'),
loadOnMount('statisticsTypes', fetchStatisticsTypes, 'root'),
StatisticBalloons
)
但也不行。
如何改进此脚本?
答案 0 :(得分:1)
这是Redux的compose
函数吗?
export default compose(
loadOnMount('appsStatistics', fetchAppsStatistics, 'root'),
loadOnMount('statisticsTypes', fetchStatisticsTypes, 'root')
)(StatisticBalloons)
答案 1 :(得分:0)
如果您编写此方法返回承诺,则可以使用Promise.all
撰写所有内容。参见示例:
const loadOnMount = (param1, param2, param3) => {
return new Promise((resolve, reject) => {
//Your logical here
})
}
然后你可以这样写:
Promise.all([
loadOnMount('appsStatistics', fetchAppsStatistics, 'root'),
loadOnMount('appsStatistics2', fetchAppsStatistics, 'root'),
loadOnMount('appsStatistics3', fetchAppsStatistics, 'root')
])
.then(function(result){
//Handle the array with all resolved promises
})