Effects & Selectors — Series 2

Preview — 3 of 10 questions

Why does this effect need it?

javascript
navigateAfterSave$ = createEffect(
  () => this.actions$.pipe(ofType(saveSuccess), tap(() => this.router.navigate(['/heroes']))),
  { dispatch: false },
);
ABecause effects with tap are not allowed to dispatch
BBecause dispatch: false disables the effect in production
CBecause navigation is asynchronous
DBecause the stream emits the incoming action, and without the flag NgRx would dispatch it again — an infinite loop

What does this filter?

javascript
this.actions$.pipe(ofType(loadHeroes, refreshHeroes))
AActions matching both types, which is impossible, so nothing
BOnly the first type listed
CEither action, with the emitted value typed as the union of the two — so the handler may safely read only the properties they share
DAll actions, filtered later by the effect body

The API returns the full list for the current page. Which method fits?

javascript
on(loadSuccess, (state, { heroes }) => adapter.setAll(heroes, state));       // authoritative list
on(pageSuccess, (state, { heroes }) => adapter.upsertMany(heroes, state));   // accumulate pages
on(patched,     (state, { change }) => adapter.updateOne(change, state));    // partial change
AaddMany — adds new entities and ignores existing ids
BupsertMany — inserts or fully replaces each entity, keeping everything already in the collection
CsetAll — replaces the entire collection with the response, dropping anything no longer present
DupdateMany — applies partial changes to existing entities only

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.