Bird
0
0

Consider this effect:

medium📝 component behavior Q5 of 15
Angular - State Management
Consider this effect:
saveItem$ = createEffect(() => this.actions$.pipe(
  ofType('SAVE_ITEM'),
  exhaustMap(action => this.api.save(action.payload).pipe(
    map(() => ({ type: 'SAVE_SUCCESS' })),
    catchError(() => of({ type: 'SAVE_FAILURE' }))
  ))
))

What happens if multiple 'SAVE_ITEM' actions are dispatched quickly?
AOnly the first save runs; others are ignored until it completes
BAll saves run concurrently
COnly the last save runs, previous ones are canceled
DNo saves run due to error
Step-by-Step Solution
Solution:
  1. Step 1: Understand exhaustMap behavior

    exhaustMap ignores new source emissions while the previous inner observable is active.
  2. Step 2: Apply to multiple 'SAVE_ITEM' actions

    Only the first save call runs; subsequent actions during that time are ignored until it completes.
  3. Final Answer:

    Only the first save runs; others are ignored until it completes -> Option A
  4. Quick Check:

    exhaustMap ignores new emissions during active inner observable [OK]
Quick Trick: exhaustMap ignores new actions until current completes [OK]
Common Mistakes:
  • Confusing exhaustMap with switchMap or mergeMap
  • Expecting all saves to run concurrently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes