@@ -70,6 +70,47 @@ const valid: () => RunTests['valid'] = () => [
70
70
)
71
71
constructor(private readonly actions$: Actions) {}
72
72
}` ,
73
+ `
74
+ import { Actions } from '@ngrx/effects'
75
+ import { of, withLatestFrom } from 'rxjs'
76
+ import { inject } from '@angular/core'
77
+ class Ok3 {
78
+ readonly effect: CreateEffectMetadata
79
+ readonly actions$ = inject(Actions)
80
+ constructor() {
81
+ this.effect = createEffect(() => ({ scheduler = asyncScheduler } = {}) => {
82
+ return actions$.pipe(
83
+ ofType(ProductDetailPage.loaded),
84
+ concatMap((action) =>
85
+ of(action).pipe(withLatestFrom(this.store.select(selectProducts))),
86
+ ),
87
+ mergeMapTo(of({ type: 'noop' })),
88
+ )
89
+ }, { dispatch: false })
90
+ }
91
+ }` ,
92
+ `
93
+ import { Actions } from '@ngrx/effects'
94
+ import { of, withLatestFrom } from 'rxjs'
95
+ import { inject } from '@angular/core'
96
+ class Ok4 {
97
+ private readonly actions$ = inject(Actions)
98
+ effect = createEffect(() =>
99
+ condition
100
+ ? this.actions$.pipe(
101
+ ofType(ProductDetailPage.loaded),
102
+ concatMap((action) =>
103
+ of(action).pipe(
104
+ withLatestFrom(this.store.select$(something), (one, other) =>
105
+ somethingElse(),
106
+ ),
107
+ ),
108
+ ),
109
+ mergeMap(([action, products]) => of(products)),
110
+ )
111
+ : this.actions$.pipe(),
112
+ )
113
+ }` ,
73
114
] ;
74
115
75
116
const invalid : ( ) => RunTests [ 'invalid' ] = ( ) => [
@@ -265,6 +306,104 @@ class NotOk3 {
265
306
)
266
307
: this.actions$.pipe()
267
308
})
309
+ }` ,
310
+ }
311
+ ) ,
312
+ fromFixture (
313
+ `
314
+ import { Actions } from '@ngrx/effects'
315
+ import { of, withLatestFrom } from 'rxjs'
316
+ import { inject } from '@angular/core'
317
+
318
+ class NotOk4 {
319
+ private readonly actions$ = inject(Actions);
320
+ effect = createEffect(() =>
321
+ this.actions$.pipe(
322
+ ofType(CollectionApiActions.addBookSuccess),
323
+ withLatestFrom((action) =>
324
+ ~~~~~~~~~~~~~~ [${ messageId } ]
325
+ this.store.select(fromBooks.selectCollectionBookIds),
326
+ ),
327
+ switchMap(([action, bookCollection]) => {
328
+ return of({ type: 'noop' })
329
+ }),
330
+ ),
331
+ )
332
+ }` ,
333
+ {
334
+ output : `
335
+ import { Actions, concatLatestFrom } from '@ngrx/effects'
336
+ import { of, withLatestFrom } from 'rxjs'
337
+ import { inject } from '@angular/core'
338
+
339
+ class NotOk4 {
340
+ private readonly actions$ = inject(Actions);
341
+ effect = createEffect(() =>
342
+ this.actions$.pipe(
343
+ ofType(CollectionApiActions.addBookSuccess),
344
+ concatLatestFrom((action) =>
345
+ this.store.select(fromBooks.selectCollectionBookIds),
346
+ ),
347
+ switchMap(([action, bookCollection]) => {
348
+ return of({ type: 'noop' })
349
+ }),
350
+ ),
351
+ )
352
+ }` ,
353
+ }
354
+ ) ,
355
+ fromFixture (
356
+ `
357
+ import { Actions } from '@ngrx/effects'
358
+ import { of, withLatestFrom } from 'rxjs'
359
+ import { inject } from '@angular/core'
360
+
361
+ class NotOk5 {
362
+ readonly effect: CreateEffectMetadata
363
+ readonly actions$ = inject(Actions)
364
+
365
+ constructor() {
366
+ this.effect = createEffect(
367
+ () =>
368
+ ({ debounce = 300 } = {}) =>
369
+ condition
370
+ ? actions$.pipe()
371
+ : actions$.pipe(
372
+ ofType(CollectionApiActions.addBookSuccess),
373
+ withLatestFrom(() => this.store.select(fromBooks.selectCollectionBookIds)),
374
+ ~~~~~~~~~~~~~~ [${ messageId } ]
375
+ switchMap(([action, bookCollection]) => {
376
+ return of({ type: 'noop' })
377
+ }),
378
+ ),
379
+ )
380
+ }
381
+ }` ,
382
+ {
383
+ output : `
384
+ import { Actions, concatLatestFrom } from '@ngrx/effects'
385
+ import { of, withLatestFrom } from 'rxjs'
386
+ import { inject } from '@angular/core'
387
+
388
+ class NotOk5 {
389
+ readonly effect: CreateEffectMetadata
390
+ readonly actions$ = inject(Actions)
391
+
392
+ constructor() {
393
+ this.effect = createEffect(
394
+ () =>
395
+ ({ debounce = 300 } = {}) =>
396
+ condition
397
+ ? actions$.pipe()
398
+ : actions$.pipe(
399
+ ofType(CollectionApiActions.addBookSuccess),
400
+ concatLatestFrom(() => this.store.select(fromBooks.selectCollectionBookIds)),
401
+ switchMap(([action, bookCollection]) => {
402
+ return of({ type: 'noop' })
403
+ }),
404
+ ),
405
+ )
406
+ }
268
407
}` ,
269
408
}
270
409
) ,
0 commit comments