Я пытаюсь выяснить, почему 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.