Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Matmo10 opened this issue Oct 13, 2017 · 3 comments
Closed

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

Matmo10 opened this issue Oct 13, 2017 · 3 comments

Comments

@Matmo10
Copy link

Matmo10 commented Oct 13, 2017

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:

@Matmo10
Copy link
Author

Matmo10 commented Oct 14, 2017

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

@MikeRyanDev
Copy link
Member

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

@pedep
Copy link

pedep commented Mar 22, 2018

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'.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants