Z
Z
zlodiak2021-05-22 02:31:03
Angular
zlodiak, 2021-05-22 02:31:03

Does a resolver live without a subscription block?

There is such a resolver:

export class SuperResolver implements Resolve<any> {
  constructor(private superService: SuperService, private store: Store<any>) {}
  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<any> {
    return this.superService.getSuper().pipe(
      tap(super) => {
        this.store.dispatch(superAction({ super }));
      })
    );
  }
}


It fires before the user navigates to a particular page. As a result, the data is received via http and placed in the store.

Please tell me whether such a resolver will work every time if the data arrives at the service after a certain time interval. It is confusing that there is no subscription here, that is, there is no subscribe () block. Therefore, no one is listening to the flow.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shvets, 2021-05-22
@zlodiak

There is generally a rather complicated process, but briefly - all resolvers are launched simultaneously, in the process of work they add their results to data, and the router waits through concatMap (and the subscription that you did not find inside it) when the whole bundle is completed to continue routing.
Those. any resolver must terminate. It will not work here to start the interval, the routing will simply hang.
It is better to place this in OnInit and stop when destroying.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question