"let x = something1 => something2 => something3"은 무엇입니까?이중 화살표 기능이란 무엇입니까?
나는이 코드를 가지고 있으며, 나는 그것이 무엇을하는지 이해하지 못하고있다.
const myReducers = {person, hoursWorked};
const combineReducers = reducers => (state = {}, action) => {
return Object.keys(reducers).reduce((nextState, key) => {
nextState[key] = reducers[key](state[key], action);
return nextState;
}, {});
};
당신 넣다 전체 코드는 필요에서
//Redux-Style Reducer
const person = (state = {}, action) => {
switch(action.type){
case 'ADD_INFO':
return Object.assign({}, state, action.payload)
default:
return state;
}
}
const infoAction = {type: 'ADD_INFO', payload: {name: 'Brian', framework: 'Angular'}}
const anotherPersonInfo = person(undefined, infoAction);
console.log('***REDUX STYLE PERSON***: ', anotherPersonInfo);
//Add another reducer
const hoursWorked = (state = 0, action) => {
switch(action.type){
case 'ADD_HOUR':
return state + 1;
case 'SUBTRACT_HOUR':
return state - 1;
default:
return state;
}
}
//Combine Reducers Refresher
****HERE****
****HERE****
****HERE****
const myReducers = {person, hoursWorked};
const combineReducers = reducers => (state = {}, action) => {
return Object.keys(reducers).reduce((nextState, key) => {
nextState[key] = reducers[key](state[key], action);
return nextState;
}, {});
};
****
****
/*
This gets us most of the way there, but really want we want is for the value of firstState and secondState to accumulate
as actions are dispatched over time. Luckily, RxJS offers the perfect operator for this scenario., to be discussed in next lesson.
*/
const rootReducer = combineReducers(myReducers);
const firstState = rootReducer(undefined, {type: 'ADD_INFO', payload: {name: 'Brian'}});
const secondState = rootReducer({hoursWorked: 10, person: {name: 'Joe'}}, {type: 'ADD_HOUR'});
console.log('***FIRST STATE***:', firstState);
console.log('***SECOND STATE***:', secondState);
: https://gist.github.com/btroncone/a6e4347326749f938510
이것은 인수로 넘겨주는 함수들입니다. 최상위 함수는 어느 시점에서 귀하의 감속기 맵과 함께 호출됩니다. –
이것을 설명하거나 더 잘 설명하는 링크를 보낼 수 있습니까? –
구체적으로 설명 하시겠습니까? 화살표 기능은 ES2015 docs/tutorials에서 설명합니다. 'reduce'는 정상적인 함수를 가지고 있습니다. Redux 부분에 대해 묻고 있습니까? –