ngrx-store-router icon indicating copy to clipboard operation
ngrx-store-router copied to clipboard

state$.do() is not defined.

Open mildful opened this issue 10 years ago • 6 comments

Hi and thanks for this really usefull lib !

I have a little problem with ngrx-store-router. I'm working on a project using Angular2, TS and SystemJS. Here is how a use your connector :

import { routerReducer, routerMiddleware } from 'ngrx-store-router';

const reducers = ModuleLoader.mergeReducers({ env, router: routerReducer });
const baseState = ModuleLoader.buildInitialState(initialState);

bootstrap(MainComponent, [
    ROUTER_PROVIDERS,
    provideStore(reducers, baseState),
    instrumentStore(),
    routerMiddleware
]).catch(console.error);

ModuleLoader.mergeReducers is a function that I wrote. It performs annoying stuff, reducers is an object like this one :

{
    env: function(state, _a),
    router: function(state, action),
    // ... other things that works well
}

I don't know why but an error is throwed when my app starts (and crashes) :

EXCEPTION: Error during instantiation of Store! (MainComponent -> Store).

Uncaught (in promise): EXCEPTION: Error during instantiation of Store! (MainComponent -> Store). ORIGINAL EXCEPTION: TypeError: state$.do is not a function

I've console.loged state$ and it's a function.

Any idea ?

mildful avatar Apr 14 '16 12:04 mildful

My guess is that what you're doing with your merge reducers is doing something with the state before it reaches the middleware. Are you modifying the router reducer there?

brandonroberts avatar Apr 14 '16 16:04 brandonroberts

No I'm not. ModuleLoader do some basics things : I can register modules with reducers and mergeReducers merge reducers from modules and those passed as argument.

I wrote this code 2 months ago and I can't check what I'm saying right now but I'm prety sure that ModuleLoader.mergeReducers() doesn't do anything else.

mildful avatar Apr 14 '16 17:04 mildful

Seems like the operators aren't being applied before use. What version of rxjs do you have installed?

brandonroberts avatar Apr 14 '16 17:04 brandonroberts

I'm using version 5.0.0-beta.2

mildful avatar Apr 14 '16 18:04 mildful

Okay so the issue solved. I don't really get why :

[shorter version] First I've tried to update rxjs to beta.6. Doing this produced a lot of conflicts/bugs so I've decided to came back to beta.2, remove my node_modules, make a clean install and it works.

Maybe I had some residues. Anyway, thanks for your help :-).

mildful avatar Apr 15 '16 08:04 mildful

Cool, glad you got it sorted out.

brandonroberts avatar Apr 15 '16 11:04 brandonroberts