Waiting For App Stability
import { ApplicationConfig, inject, ExperimentalPendingTasks } from '@angular/core';
import { ActionStatus, Actions, provideStore, withNgxsPreboot } from '@ngxs/store';
export const appConfig: ApplicationConfig = {
providers: [
provideStore(
[],
withNgxsPreboot(() => {
const pendingTasks = inject(ExperimentalPendingTasks);
const actions$ = inject(Actions);
const actionToRemoveTaskFnMap = new Map<any, () => void>();
// Note that you don't have to unsubscribe from the actions stream in
// this specific case, as we complete the actions subject when the root
// view is destroyed. In server-side rendering, the root view is destroyed
// immediately once the app stabilizes and its HTML is serialized.
actions$.subscribe(ctx => {
if (ctx.status === ActionStatus.Dispatched) {
const removeTaskFn = pendingTasks.add();
actionToRemoveTaskFnMap.set(ctx.action, removeTaskFn);
} else {
const removeTaskFn = actionToRemoveTaskFnMap.get(ctx.action);
if (typeof removeTaskFn === 'function') {
removeTaskFn();
actionToRemoveTaskFnMap.delete(ctx.action);
}
}
});
})
)
]
};Last updated

