-1

Currently i am working on migration from angular 5 to 6. While updating to redux 4 i am getting error as store.getState() is not a funtion

export interface IAppState {
    source1: IEmployee[],
    source2: IEmployee[],
}    
export type FSAction = FluxStandardAction<any, MetaData | null | number>;

this is the code for epic middleware. Here i am facing issue as store.getState() is not a function while updating to redux 4

employeeValues_Epic: Epic<FSAction, IAppState> = (action$, store) => action$
.ofType(APP_Actions.ActionTypes.APP_EMPLOYEE_VALUES).pipe(
  switchMap(data => {  
       let state1: IEmployee[] = [];
       try {
            console.log("in All domain  iteration");
            state1 = store.getState().source1.state;        
       } catch (error) {
           console.error(error);
    }
    return observableFrom(state1);
  }));`

Currently i am working on migration from angular 5 to 6. While updating to redux 4 i am getting error as store.getState() is not a funtion

vikas biradar
  • 238
  • 1
  • 3
  • 12

2 Answers2

1

Read the migration doc https://redux-observable.js.org/MIGRATION.html#accessing-state

Presuming redux-observable v1 and rxjs v6.

  • Instead of store$.getState() it have updated to store$.value.
  • Replace Observablefrom to from. (rxjs 5 to 6)
  • ofType should be in the pipe.
const employeeValues_Epic: Epic<FSAction, IAppState> = (action$, store$) => action$
.pipe(
  ofType(APP_Actions.ActionTypes.APP_EMPLOYEE_VALUES),
  switchMap(data => {  
       let state1: IEmployee[] = [];
       try {
            console.log("in All domain  iteration");
            state1 = store$.value.source1.state;        
       } catch (error) {
           console.error(error);
       }
       return from(state1);
  }));

johnson lai
  • 996
  • 1
  • 11
  • 15
0

Here after updating to redux 4 and rxjs 6 syntax has been changed as below and getState() function has been changed to value property.

`employeeValues_Epic: Epic<FSAction, FSAction, IAppState, any> = (action$, store) => action$
.ofType(APP_Actions.ActionTypes.APP_EMPLOYEE_VALUES).pipe(
  switchMap(data => {  
       let state1: IEmployee[] = [];
       try {
            console.log("in All domain  iteration");
            state1 = store.value.source1.state;        
       } catch (error) {
           console.error(error);
    }
    return observableFrom(state1);
  }));`
vikas biradar
  • 238
  • 1
  • 3
  • 12