如何在redux的reducer中将ES5转换为ES6

时间:2017-10-29 05:47:21

标签: redux

如何将以下代码转换为ES6 :(尤其是case ActionTypes.GetInviteFulfilled: { const { host, agenda, guests } = action.invite; const newState = Object.assign({}, state, { inProgress: false, success: 'Got invite.', host, agenda }); newState.guests = []; if (guests) { newState.guests = Object.keys(guests).map(k => guests[k]); } return newState; }

之后的部分
{{1}}

1 个答案:

答案 0 :(得分:1)

这可能对您有用:

case ActionTypes.GetInviteFulfilled: {
  const { host, agenda, guests } = action.invite;
  return {
    ...state,
    inProgress: false,
    success: 'Got invite.',
    host,
    agenda,
    guests: guests ? Object.keys(guests).map(k => guests[k]) : [],
  };
}