Skip to content

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

@alex-okrushko

Description

@alex-okrushko

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions