I'd like to confirm behavior I am observing when I have an Effects class implementing ngrxOnInitEffects, since I hope to rely on the observed behavior.
I have two features A and B in the same app. A has Effects, Reducers, and Selectors. B has Effects.
AEffects is registered via EffectsModule first. It will do some synchronous work in response to the action dispatched by its ngrxOnInitEffects() implementation. The action subsequently dispatched by the effect will be handled by A's reducers to modify AState. It is effectively attempting to initialize AState.
const aEffectsInitialized = createAction('[A] Effects Init');
class AEffects {
ngrxOnInitEffects(): Action {
return aEffectsInitialized();
}
readonly aInitEffect$ = createEffect(() =>
this.actions$.pipe(
ofType(aEffectsInitialized),
map(() => {
// Do some synchronous calculation and dispatch action. The action is
// handled by the A feature's reducers to modify AState.
return someActionThatModifiesAState({someValue});
})
)
);
}
The BEffects class is registered via EffectsModule later. It listens to actions from various features and selects from AState.
class BEffects {
/** @export */
readonly someBEffect$ = createEffect(() =>
this.actions$.pipe(
ofType(someAction),
withLatestFrom(this.store.select(getSomethingFromAState)),
map(([, aState]) => {
// Do something with AState. Is it guaranteed to have already been updated
// by aInitEffect$?
})
)
);
}
Given that AEffects is registered via EffectsModule before BEffects and that aInitEffect$ does synchronous calculations, is it guaranteed that aInitEffect$ and its side effects on AState will have completed before any BEffects are triggered and select from AState?