ngrx Angular app not working unless Redux Devtools is installed
ngrx Angular app not working unless Redux Devtools is installed
Our ngrx Angular app works great until we uninstall Redux Devtools at which point we get errors:
You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
Store setup looks like this in app.module.ts:
StoreModule.forRoot(reducers, metaReducers),
!environment.production ? StoreDevtoolsModule.instrument() : ,
EffectsModule.forRoot([SimsEffects, FiltersEffects, OmnipresentEffects, UserEffects, InitEffects]),
StoreRouterConnectingModule.forRoot(stateKey: 'router')
and our ngrx reducers/index.ts file looks like this:
export interface AppState
router: any,
omnipresent: OmnipresentState,
user: UserState
export const reducers: ActionReducerMap<AppState> =
router: routerReducer,
omnipresent: omnipresentReducer,
user: userReducer
export function resetStore(reducer)
return (state, action) =>
return reducer(action.type === InitActionTypes.ResetStore ? undefined : state, action)
// storeFreeze throws an error early if state is mutated, avoiding hard to debug state mutation issues
export const metaReducers: MetaReducer<AppState> = !environment.production ? [resetStore, storeFreeze] : [resetStore] // tslint:disable-line array-type
Anyone experienced this before or knows the fix? The issue exists both in dev and prod environments.
We are running Node v8.11.3
EDIT: If I comment out this line, the error goes away, but obviously the store fails to init:
@Effect()
init$: Observable<any> = defer(() =>
return of(new InitAction())
)
Where InitAction is simply an action that does nothing with no effect attached (for the purpose of helping to debug this).
Actions
ofType
that sounds right, but not for the init effect - see docs - github.com/ngrx/platform/blob/master/docs/effects/…
– danday74
Aug 21 at 12:49
1 Answer
1
Changing this solved it:
import defer, of from 'rxjs/index' // as per my IDE suggestions
to:
import defer, of from 'rxjs' // as per ngrx docs
Also, replaced all references to 'rxjs/index' with 'rxjs'
Glad you found the problem, that's a weird suggestion from your IDE.
– enf0rcer
Aug 21 at 14:21
yah, even weirder that it worked with DevTools on! anyway looks like I might not get sacked after all ;)
– danday74
Aug 21 at 14:29
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Just out of curiousity, where did you learn to use effects like that? To me this pattern seems completely off. As far as I know you always have to import
Actions
and then use theofType
method to listen to particular actions to determine the to be executed effect.– enf0rcer
Aug 21 at 12:06