Skip to content

The way to fire an effect after effects are settled up #246

@ValeryVS

Description

@ValeryVS

I'm submitting a...


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

What is the current behavior?

There is no action, no function which fired when all effects are settled up. Where we can dispatch actions to fire other effects.

Expected behavior:

    this.onInit$ = this.actions$
      .ofType('@ngrx/effects/up')
      .switchMap((isAuthorized) => {
        return this.isAuthorized$;
      })
      .map((isAuthorized) => {
        if (isAuthorized) {
          this.store.dispatch({ type: '[posts] getAll' })
        }
      });

    @Effect()
    this.onGetPosts$ = this.actions$
      .ofType('[posts] getAll')
      .map(() => ... )

or, may be

  public ngrxOnRunEffects(resolvedEffects$: Observable<EffectNotification>): Observable<EffectNotification> {
    this.isAuthorized$
      .take(1)
      .subscribe({
        next: (isAuthorized) => {
          if (isAuthorized) {
            this.store.dispatch({ type: '[posts] getAll' })
          }
        },
      });
    return resolvedEffects$;
  }

Minimal reproduction of the problem with instructions:

There a few issues, of @ngrx/store/init action. Seems, that this action is not useful for described purpose anymore. So, we probably need another.
#103
#152

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

ngrx v4

Other information:

Possible workaround:

dispatch action, somewhere after application start.
In the AppComponent for example.

this.store.dispatch({ type: '[app] init' });

And use it to dispatch other actions, that must be dispatched after all effects are settled up.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions