Skip to content

Commit

Permalink
fix(eslint): fix avoid-dispatching-multiple-actions-sequentially rule…
Browse files Browse the repository at this point in the history
… to detect inject (ngrx#3943)
  • Loading branch information
va-stefanek committed Jul 7, 2023
1 parent ee00ed4 commit 243fabd
Showing 1 changed file with 141 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ ngOnInit() {
`
import { Store } from '@ngrx/store'
class Ok {
class Ok4 {
constructor(private store: Store) {}
ngOnInit() {
Expand All @@ -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());
Expand Down Expand Up @@ -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}]
Expand Down

0 comments on commit 243fabd

Please sign in to comment.