Bird
0
0

Examine this Effect code:

medium📝 Debug Q6 of 15
Angular - Signals
Examine this Effect code:
updateUser$ = createEffect(() => this.actions$.pipe(
  ofType(updateUser),
  map(() => this.api.updateUser()),
  map(() => updateUserSuccess())
));

What is the issue with this Effect?
AMissing <code>ofType</code> operator to filter actions
BUsing <code>map</code> to call an async API without flattening operator causes incorrect behavior
CEffect is missing <code>{ dispatch: false }</code> option
DUsing <code>tap</code> instead of <code>map</code> for dispatching actions
Step-by-Step Solution
Solution:
  1. Step 1: Identify async call handling

    The API call returns an Observable, so map is not suitable to flatten it.
  2. Step 2: Correct operator usage

    Operators like switchMap or mergeMap should be used to flatten the inner Observable.
  3. Final Answer:

    Using map to call an async API without flattening operator causes incorrect behavior -> Option B
  4. Quick Check:

    Async calls require flattening operators [OK]
Quick Trick: Use switchMap or mergeMap for async API calls [OK]
Common Mistakes:
  • Using map instead of switchMap for Observables
  • Forgetting to flatten inner Observables
  • Assuming map automatically unwraps Observables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes