[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
I have a global reducer defined as:
export const reducer: ActionReducerMap<ApplicationModel> = {
filter: filterReducer,
grid: gridReducer,
analyse: analyseReducer,
};
And an initial state defined as:
export const INITIAL_MODEL: ApplicationModel = {
filter: FILTER_INITIAL_MODEL,
grid: GRID_INITIAL_MODEL,
analyse: ANALYSE_INITIAL_MODEL,
};
And my store as:
@NgModule({
imports: [
StoreModule.forRoot(reducer, {
initialState: INITIAL_MODEL,
metaReducers: !environment.production ? [storeFreeze] : [],
}),
StoreDevtoolsModule.instrument({
maxAge: 30,
logOnly: environment.production,
}),
],
})
export class ModelModule {}
And when looking at the chromium redux dev inspector, I see that the initial state is:
{
filter: {},
grid: {
parameters: {
min: 0.2,
max: 0.7
}
}
}
So basically, half of my state is initialised (or maybe nothing is and for a reason, the grid part of the model is initialised by the reducer before the @ngrx/store/init event arrives…
I have tested injecting the initial state with an exported function. And if I log in this function the value of INITIAL_MODEL, it has non-empty objects for every properties of the initial state.
The state should be properly initialised with the value provided to the StoreModule.
The provided plunkr does not work anymore but if there is a new one for the latest version of ngrx, I can reproduce this :)
Happening with ngrx 6.0.0-beta.3 and angular 6.
I don't see immediately what the problem might be.
There is no updated plunkr (I think), but if you want you can use StackBlitz to reproduce the issue.
I've created a ngrx-seed which you can use.
@tdeschryver thanks for the seed.
So… yeah it was my fault, I realised that when trying to reproduce :) thanks again and sorry for the noise
No problem.
What was the problem tho, just out of curiosity 😄
@tdeschryver it's stupid, the reducer of the missing property had no default case for the actions, so it was returning undefined.
And for the empty object, IÂ think it is just store-devtools that hide property with undefined value.
@victornoel you are a life saver. We were having issue where state was undefined and we knew that shouldn't be the case. We double-checked our reducer and were missing the default fall through in the switch statement. We had copied from another project and accidentally left off the default case.
I love Google and Github.
@wesleygrimes glad my mistake and absence of shame to complain could be useful ^^
"... it's stupid, the reducer of the missing property had no default case for the actions, so it was returning undefined."
had the same issue, saved me a lot of headache!
Most helpful comment
@tdeschryver it's stupid, the reducer of the missing property had no default case for the actions, so it was returning undefined.
And for the empty object, IÂ think it is just store-devtools that hide property with undefined value.