2017-10-29 60 views
0

如何轉換下面的代碼ES6:(尤其是後newState.guests = []如何ES5轉換器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

的一部分,這可能爲你工作:

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]) : [], 
    }; 
}