【发布时间】:2018-12-15 22:03:54
【问题描述】:
我尝试为 React 应用编写 2 个操作。
export const changeFilter = (newFilter) => {
return (dispatch) => {
dispatch({type:types.GET_EVENTS_BY_FILTER});
axios.get( 'http://localhost:8762/event/events?') // + eventsSelector.getEventsFilter()
.then( response => {
dispatch({type:types.GET_EVENTS_BY_FILTER_SUCCESS,payload:response});
} )
.catch( error => {
dispatch({type:types.GET_EVENTS_BY_FILTER_FAIL,error:error});
} );
}
};
和
export const getEventsByFilter = () => {
return (dispatch) => {
dispatch({type:types.GET_EVENTS_BY_FILTER});
axios.get( 'http://localhost:8762/event/events?') // + eventsSelector.getEventsFilter()
.then( response => {
dispatch({type:types.GET_EVENTS_BY_FILTER_SUCCESS,payload:response});
} )
.catch( error => {
dispatch({type:types.GET_EVENTS_BY_FILTER_FAIL,error:error});
} );
}
};
当我点击 getEventsByFilter 中的 return(dispatch) 行并按 F10 进行调试(在 Chrome 开发人员工具中)时,我转到下一行(这是预期的行为)。不幸的是,当我尝试调用 changeFilter 方法并点击 line return(dispatch) 并点击 F10 转到下一行时,调试器将我引导到下一行的 return 语句的封闭括号。我还检查了日志,因为我安装了 redux 记录器,并且仅为 getEventsByFilter 方法调度了操作。
【问题讨论】:
标签: javascript reactjs redux react-redux