Resolvers are resolved in parallel. If Foo
and Bar
are supposed to be resolved in series they should be a single FooBar
resolver. If they are supposed to be used by themselves in other routes, FooBar
can wrap Foo
and Bar
resolvers:
class FooBarResolver implements Resolve<{ foo: any, bar: any }> {
constructor(
protected fooResolver: FooResolver,
protected barResolver: BarResolver
) {}
async resolve(route): Promise<{ foo: any, bar: any }> {
const foo = await this.fooResolver.resolve(route);
const bar = await this.barResolver.resolve(route);
return { foo, bar };
}
}
FooBar
should be aware of the fact if it is a promise or an observable that is returned from Foo
and Bar
in order to resolve them properly. Otherwise additional safety device should be added, like await Observable.from(this.fooResolver.resolve(route)).toPromise()
.
FooBar
and Foo
or Bar
shouldn't appear within same route because this will result in duplicate resolutions.
foo
andbar
are and why they should be resolved in this order. But generally this is achievable with FooBarResolver that resolves to an object that contains foo and bar.foo
andbar
are json objects retrieved from a database, I don't care of the order of execution, but they must be executed one after the other.bar
andbaz
depended onfoo
butbaz
was optional in some routes. Eventually I ended up withFooBarBaz
resolver that took care of optional Baz. To my knowledge, there is currently no better way.