michaelkrone / ngrx-normalizr

Managing normalized state in ngrx applications - transparently
https://michaelkrone.github.io/ngrx-normalizr/
MIT License
50 stars 17 forks source link

State stays empty #22

Closed tommueller closed 6 years ago

tommueller commented 6 years ago

Thanks for the great library! Looks super useful. I do have one issue though. I set everything up as in the README, but I am not using Effects() to pass in data, because the data is generated on the client side. So I use myStore.dispatch(new AddData<Data>() to add data.

Looking in ngrx-devconsole I can see that the action is going to the store with the correct payload, but my state does not change. It is always empty ...

I just have this as reducer and state: export interface TemplateState extends NormalizedState { } export const templateReducer: ActionReducerMap<NormalizedState> = { normalized };

Am I missing anything?

Thanks! Tom

michaelkrone commented 6 years ago

Hello @tommueller Basically that's all, register the dispatching the action. What are your action constructor arguments? Can you post the data and schema you pass to the action?

tommueller commented 6 years ago

Thanks for the reply. Will post this on Monday, I'm not in office tomorrow. Thanks!

michaelkrone commented 6 years ago

Sorry, closed incidentally. Did you register the reducer to the store? And remember: data needs to be an array.

tommueller commented 6 years ago

data is an array, when I look at the payload of the dispatched action, it looks fine.

how do I register the reducer to the store? Maybe I missed that part ...

michaelkrone commented 6 years ago

In you module definition:

@NgModule({
    imports: [
                ...
        StoreModule.forRoot(reducers) // or StoreModule.forFeature(...)
    ],
        ...
})
export class AppModule ...
tommueller commented 6 years ago

@michaelkrone thanks I got it running! In my module definition I had the import like this: StoreModule.forRoot({ templateState: templateReducer }) Changed it to StoreModule.forRoot(templateReducer)

and now it is working fine.

Cheers!