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

Effects: Add support for effects of different instances of same class #1249

Merged
merged 1 commit into from
Aug 22, 2018

Conversation

dummdidumm
Copy link
Contributor

Fixes #1246

With this change, it is possible to add different instances of the same class to the effects and have them running:

class ConfigurableEffect {
  @Effect({ dispatch: false })
  doSth$ = timer(1000).pipe(
    tap(() => console.log(this.message))
  );

  constructor(private message: string) { }
}

@NgModule({
  imports: [BrowserModule, FormsModule, StoreModule.forRoot(() => true), EffectsModule.forRoot([])],
  declarations: [AppComponent, HelloComponent],
  bootstrap: [AppComponent]
})
export class AppModule {
  constructor(effectSources: EffectSources) {
    effectSources.addEffects(new ConfigurableEffect("configA"));
    effectSources.addEffects(new ConfigurableEffect("configB"));
    // -> this did not work before, second effects instance was never run
  }
}

EffectSources still filters out effects which are already running, so no danger of running the same effects instance multiple times.

@coveralls
Copy link

coveralls commented Aug 13, 2018

Coverage Status

Coverage increased (+0.003%) to 88.618% when pulling 994326e on dummdidumm:bugfix/effects_instances into 4223ff9 on ngrx:master.

exhaustMap(resolveEffectSource),
map(output => {
verifyOutput(output, this.errorHandler);
scan(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might be overlooking something but won't the following accomplish the same thing?

groupBy(source => source),

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are completely right, thanks for noticing! I will update the PR.

@dummdidumm dummdidumm force-pushed the bugfix/effects_instances branch from b46e1b7 to 994326e Compare August 18, 2018 14:52
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

Successfully merging this pull request may close these issues.

4 participants