【发布时间】:2018-05-15 23:34:54
【问题描述】:
给定如下的 reducer 示例
_({
expandAbility: (state, a: { which: string }) => ({
...state,
report: state.report && {
waitingForIt: false,
content: state.report.content && {
...state.report.content,
interaction: {
expandAbilities: !state.report.content.interaction.expandAbilities.contains(a.which)
? state.report.content.interaction.expandAbilities.add(a.which)
: state.report.content.interaction.expandAbilities.remove(a.which)
}
}
}
}),
})
(下面给出的状态类型仅用于问题上下文)
const initialState = {
report: undefined as
| {
waitingForIt?: boolean
content?: {
supportedFightIds: number[]
deathCut: number
reportInfo: any
deathsFull: any
deathsByPlayer: any
deathsByAbility: any
interaction: {
expandAbilities: Set<string>
}
}
}
| undefined,
error: undefined as Error | undefined
}
是否有任何技巧或“即时风味”库可以让我以更短的方式编写像expandAbility 这样的reducer 更新操作? (除了可能创建一些vars 来引用内部路径)
【问题讨论】:
标签: reactjs typescript redux