Hello I am trying to optimize my data/app performance using app shell strategy with route resolvers and storing data to fetch existing results. My questions is should i be using route resolvers on say a Notifications page where I need to pull in the latest results every x minutes? should I use BehaviorSubject instead to store the data? what do experts recommend?
My example resolver:
async resolve(route: ActivatedRouteSnapshot): Promise<DataStore<NotificationsModel>> {
const dataSource: Observable<NotificationsModel> = this.notificationsService.getNotificationsDataSource(
parseInt(route.paramMap.get('userid'), 10)
);
const dataStore: DataStore<NotificationsModel> = this.notificationsService.getNotificationsStore(dataSource);
return dataStore;
}
I fetch data like so:
ngOnInit(): void {
this.fetchRouteData();
}
fetchRouteData(): void {
const routeData$ = this.route.data.pipe(
take(1),
switchMap((resolvedRouteData: IResolvedRouteData<NotificationsModel>) => {
return ResolverHelper.extractData<NotificationsModel>(resolvedRouteData.data, NotificationsModel);
}),
catchError(err => throwError(err))
);
routeData$.subscribe((state) => {
if (state && !state.isShell) {
this.notificationsState = state;
this.notifications = this.notificationsState.notifications;
this.unread = state.unread;
this.total_notifications = state.total;
}
}, (err) => { console.log(err); });
}