/
resolve.ts
45 lines (40 loc) · 1.84 KB
/
resolve.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/** @module hooks */
/** for typedoc */
import { noop } from '../common/common';
import { Transition } from '../transition/transition';
import { ResolveContext } from '../resolve/resolveContext';
import { TransitionStateHookFn, TransitionHookFn } from '../transition/interface';
import { TransitionService } from '../transition/transitionService';
import { val } from '../common/hof';
import { StateDeclaration } from '../state/interface';
/**
* A [[TransitionHookFn]] which resolves all EAGER Resolvables in the To Path
*
* Registered using `transitionService.onStart({}, eagerResolvePath);`
*
* When a Transition starts, this hook resolves all the EAGER Resolvables, which the transition then waits for.
*
* See [[StateDeclaration.resolve]]
*/
const eagerResolvePath: TransitionHookFn = (trans: Transition) =>
new ResolveContext(trans.treeChanges().to)
.resolvePath("EAGER", trans)
.then(noop);
export const registerEagerResolvePath = (transitionService: TransitionService) =>
transitionService.onStart({}, eagerResolvePath, {priority: 1000});
/**
* A [[TransitionHookFn]] which resolves all LAZY Resolvables for the state (and all its ancestors) in the To Path
*
* Registered using `transitionService.onEnter({ entering: () => true }, lazyResolveState);`
*
* When a State is being entered, this hook resolves all the Resolvables for this state, which the transition then waits for.
*
* See [[StateDeclaration.resolve]]
*/
const lazyResolveState: TransitionStateHookFn = (trans: Transition, state: StateDeclaration) =>
new ResolveContext(trans.treeChanges().to)
.subContext(state.$$state())
.resolvePath("LAZY", trans)
.then(noop);
export const registerLazyResolveState = (transitionService: TransitionService) =>
transitionService.onEnter({ entering: val(true) }, lazyResolveState, {priority: 1000});