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

Issues accessing 'forFeature' part of the store from 'forFeature' @Effects when there are multiple EffectsModule.forFeature in the app #642

Closed
alex-okrushko opened this issue Dec 10, 2017 · 2 comments

Comments

@alex-okrushko
Copy link
Member

alex-okrushko commented Dec 10, 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?

'forFeature' part of the Store is being used in the 'forFeature' @effects (by combining Action with withLatestFrom(this.store.select(getFeatureState))) however the store at that time hasn't been updated with feature part. It gets updated a bit later when @ngrx/store/update-reducers is triggered.

This happens when there are > 1 EffectsModule.forFeature modules.

screen shot 2017-12-10 at 2 01 46 pm

Expected behavior:

I've tried to defer(() => {...}) the whole thing, but apparently Effects are subscribed to earlier than Store is patched with feature.

Minimal reproduction of the problem with instructions:

Here is my repro: https://stackblitz.com/edit/store-forfeature-issue?embed=1&file=app/app.module.ts

Important parts:

  • OtherFeatureModule is imported before FeatureModule in the AppModule.
  • OtherFeatureModule has EffectsModule.forFeature([...])
  • FeatureModule has EffectsModule.forFeature([...]) and StoreModule.forFeature({...})
  • @Effect() that is part of FeatureModule uses this.store.select(selectorThatUsesFeaturePartOfTheStore)

workarounds:

  • this.store.select(selectorThatUsesFeaturePartOfTheStore) and only use this.store.select(selectorThatUsesRootPartOfTheStore)
  • try to push this.store.select(selectorThatUsesFeaturePartOfTheStore) into the payload of the Action

None of the workarounds look particular appealing to me.

Thank you @brandonroberts for debugging it with me.

@alex-okrushko alex-okrushko changed the title Issues accessing 'forFeature' part of the store from 'forFeature' Effects Issues accessing 'forFeature' part of the store from 'forFeature' @Effects when there are multiple EffectsModule.forFeature in the app Dec 11, 2017
@alex-okrushko
Copy link
Member Author

Brandon, thanks for getting this done! I've confirmed internally that the issue is actually fixed now.

@brandonroberts
Copy link
Member

Awesome!

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

No branches or pull requests

2 participants