您能解释一下,在一个点击处理程序中对不同的操作执行多个调度是不是一个好主意?每个分派都有一个函数,该函数从一个JSON文件中获取数据,并根据参数中的值输出过滤后的array.
const handleBtnClick = () => {
dispatch({
type: ACTIONS_CITY.CONVERT_CITY_NAME,
payload: convertCityNameToCoordinates(value) //finds a city name and returns coordinates of the city
})
dispatch({
type: ACTIONS_CITY.CHANGE_REGION,
payload: getRegion(value) //finds a city name and return its region
})
dispatch({
type: ACTIONS_CITY.CHANGE_POPULATION,
payload: getPopulation(value) //return a population of provided city
})
}
100
export const cityReducer = (state, action) => {
switch (action.type) {
case (ACTIONS_CITY.CONVERT_CITY_NAME): {
return {
...state,
[state.cityCoordinates]: action.payload
}
}
case (ACTIONS_CITY.CHANGE_POPULATION): {
return {
...state,
[state.population]: action.payload
}
}
case (ACTIONS_CITY.CHANGE_REGION): {
return {
...state,
[state.region]: action.payload
}
}
default:
return state
}
}