es6 代码片段理解

代码片段理解:

 [INCREMENT]: (state, action) => {
const { payload: { id } } = action //because payload contains the id and we already know that we are about
//to increment the value of that id, we modify only that value by one return {
...state,
counters: {
...state.counters,
[id]: state.counters[id] + 1
}
}
},

line 2:

const { payload: { id } } = action
相当于: id = action.payload.id

line 8 - 10:

{
8 ...state,
9 counters: {
10 ...state.counters,
11 [id]: state.counters[id] + 1
12 }
13 }

是表达:state.counter[id] =  state.counters[id] + 1

上一篇:I2C controller core之Bit controller(03)


下一篇:同“窗”的较量:部署在 Windows 上的 .NET Core 版博客站点发布上线