diff --git a/modules/eslint-plugin/spec/rules/avoid-dispatching-multiple-actions-sequentially.spec.ts b/modules/eslint-plugin/spec/rules/avoid-dispatching-multiple-actions-sequentially.spec.ts index be228407e3..c5de416372 100644 --- a/modules/eslint-plugin/spec/rules/avoid-dispatching-multiple-actions-sequentially.spec.ts +++ b/modules/eslint-plugin/spec/rules/avoid-dispatching-multiple-actions-sequentially.spec.ts @@ -67,7 +67,7 @@ ngOnInit() { ` import { Store } from '@ngrx/store' -class Ok { +class Ok4 { constructor(private store: Store) {} ngOnInit() { @@ -82,9 +82,84 @@ ngOnInit() { ` import { Store } from '@ngrx/store' -class Ok { +class Ok5 { constructor(private store: Store) {} +ngOnInit() { + this.store.dispatch(anotherOne()); + + this.store.subscribe(() => { + this.store.dispatch(one()); + }); +} +}`, + ` +import { Store } from '@ngrx/store' +import { inject } from '@angular/core' + +class Ok6 { +private readonly store = inject(Store) + +ping() { + this.store.dispatch(GameActions.ping()) +} +}`, + ` +import { Store } from '@ngrx/store' +import { inject } from '@angular/core' + +class Ok7 { +private readonly store = inject(Store) + +pingPong() { + if (condition) { + this.store.dispatch(GameActions.ping()) + } else { + this.store.dispatch(GameActions.pong()) + } +} +}`, + // https://github.com/timdeschryver/eslint-plugin-ngrx/issues/86 + ` +import { Store } from '@ngrx/store' +import { inject } from '@angular/core' + +class Ok8 { +private readonly store = inject(Store) + +ngOnInit() { + this.store.subscribe(() => { + this.store.dispatch(one()); + }); + this.store.subscribe(() => { + this.store.dispatch(anotherOne()); + }); +} +}`, + // https://github.com/ngrx/platform/issues/3513 + ` +import { Store } from '@ngrx/store' +import { inject } from '@angular/core' + +class Ok9 { +private readonly store = inject(Store) + +ngOnInit() { + this.store.dispatch(one()); + + this.store.subscribe(() => { + this.store.dispatch(anotherOne()); + }); +} +}`, + // https://github.com/ngrx/platform/issues/3513 + ` +import { Store } from '@ngrx/store' +import { inject } from '@angular/core' + +class Ok10 { +private readonly store = inject(Store) + ngOnInit() { this.store.dispatch(anotherOne()); @@ -148,6 +223,70 @@ ngOnInit() { customName.dispatch() } +pingPong() { + this.customName.dispatch(GameActions.ping()) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}] + this.customName.dispatch(GameActions.pong()) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}] +} +}`), + fromFixture(` +import { Store } from '@ngrx/store' +import { inject } from '@angular/core' + +class NotOk4 { +private readonly store = inject(Store) + +pingPong() { + this.store.dispatch(GameActions.ping()) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}] + this.store.dispatch(GameActions.pong()) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}] +} +}`), + fromFixture(` +import { Store } from '@ngrx/store' +import { inject } from '@angular/core' + +class NotOk5 { +private readonly store = inject(Store) +private readonly store$ = inject(Store) +constructor() { + store.dispatch(GameActions.ping()) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}] + this.ping(); + this.name = 'Bob' + this.store$.dispatch(GameActions.pong()) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}] +} +}`), + fromFixture(` +import { Store } from '@ngrx/store' +import { inject } from '@angular/core' + +class NotOk6 { +private readonly store = inject(Store) + +pingPongPong() { + this.store.dispatch(GameActions.ping()) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}] + this.store.dispatch(GameActions.pong()) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}] + this.store.dispatch(GameActions.pong()) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}] +} +}`), + fromFixture(` +import { Store } from '@ngrx/store' +import { inject } from '@angular/core' + +class NotOk7 { +private readonly customName = inject(Store) + +ngOnInit() { + customName.dispatch() +} + pingPong() { this.customName.dispatch(GameActions.ping()) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [${messageId}]