我试图弄清楚为什么Redux-Devtools不显示状态变化,因为它显示action={
type: 'GET_LOCATION_SUCCESS',
payload: {}
}
,而debugger
和console.log()
显示action.payload
为n。
我正在使用
redux-observable
rxjs
typesafe-actions
这是我的动作创建者:
import { createAsyncAction } from 'typesafe-actions';
import { GET_LOCATION_BEGIN, GET_LOCATION_FAILURE, GET_LOCATION_SUCCESS } from './constants';
export const getMyLocation = createAsyncAction(
GET_LOCATION_BEGIN,
GET_LOCATION_SUCCESS,
GET_LOCATION_FAILURE
)<undefined, Position, string>();
这是我的减速器
import { RootAction } from 'MyTypes';
import { combineReducers } from 'redux';
import { getType } from 'typesafe-actions';
import {getMyLocation} from '../actions/locationActions';
export type locationState = {
position: Position;
error: boolean;
};
export const locationReducer = combineReducers<locationState, RootAction>({
position: (state = {} as Position, action) => {
switch(action.type){
case getType(getMyLocation.success):
return action.payload;
default:
return state;
}
},
error: (state = false, action) => {
switch(action.type){
case getType(getMyLocation.failure):
return true;
default:
return state;
}
}
})
这是我的史诗:[编辑v.1]
export const getMyLocationEpic: Epic<RootAction, RootAction, RootState, Services> = (action$, state$, {geoLocation}) =>
action$.pipe(
filter(isActionOf(getMyLocation.request)),
switchMap( () => geoLocation.getGeoLocation(options).pipe(
take(1),
mergeMap( (data : Position) => of(
// Dispatch action with my location data and then dispatch action to request weather from API. It runs fetchWeatherEpic
getMyLocation.success(data),
fetchWeather.request(data)
)
),
catchError(err => of(getMyLocation.failure(err)))
)
)
);
我想知道不显示状态更新的原因可能是什么,它在console.log()
中应有的作用,但在devtools中不起作用。