Platform: Initial state not passed to meta reducers during @ngrx/store/init

Created on 13 Oct 2017  路  3Comments  路  Source: ngrx/platform

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request

What is the current behavior?


Initial state is not passed to meta reducers during @ngrx/store/init

Expected behavior:


Initial state should be passed to meta reducers during @ngrx/store/init, especially for libraries like ngrx-localstorage-sync which need to merge any supplied initial state with values saved in local storage, for example (see https://github.com/btroncone/ngrx-store-localstorage/blob/master/src/index.ts#L180).

Minimal reproduction of the problem with instructions:


https://stackblitz.com/edit/angular-c8kl8z

If you run the stackblitz, you'll see that state is undefined inside the logger metareducer during @ngrx/store/init (check the console, or debug if you want)

Version of affected browser(s),operating system(s), npm, node and ngrx:

  "@ngrx/router-store": "^4.0.4",
  "@ngrx/store": "^4.0.3",

Other information:

Most helpful comment

We are going to be releasing Entity in the next couple of days. Will probably publish everything else with it.

All 3 comments

Awesome, thanks for the fix @brandonroberts ! Any idea when this will hit npm? cc @MikeRyanDev

We are going to be releasing Entity in the next couple of days. Will probably publish everything else with it.

Does 100a8ef also cover feature modules? I'm not sure if i'm doing something wrong, but the meta-reducer spec fails if you apply this patch

diff --git a/modules/store/spec/modules.spec.ts b/modules/store/spec/modules.spec.ts
index 190c8b1..44feacb 100644
--- a/modules/store/spec/modules.spec.ts
+++ b/modules/store/spec/modules.spec.ts
@@ -129,7 +129,8 @@ describe(`Store Modules`, () => {
       beforeEach(() => {
         TestBed.configureTestingModule({
           imports: [
-            StoreModule.forRoot(reducerMap, { initialState, metaReducers }),
+            StoreModule.forRoot({}, { metaReducers: [] }),
+            StoreModule.forFeature("core", reducerMap, { initialState, metaReducers }),
           ],
         });

@@ -138,7 +139,7 @@ describe(`Store Modules`, () => {

       it('should have initial state', () => {
         store.take(1).subscribe((s: any) => {
-          expect(s).toEqual(initialState);
+          expect(s.core).toEqual(initialState);
         });
       });
     };
........................................................................................................................................................................F.............................................

Failures:
1) Store Modules : With initial state should add initial state with registered meta-reducers should have initial state
  Message:
    Expected $.fruit = 'apple' to equal 'banana'.
Was this page helpful?
0 / 5 - 0 ratings

Related issues

NathanWalker picture NathanWalker  路  3Comments

gperdomor picture gperdomor  路  3Comments

axmad22 picture axmad22  路  3Comments

ghost picture ghost  路  3Comments

bhaidar picture bhaidar  路  3Comments