forked from angular-ui/ui-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtransitionService.ts
111 lines (103 loc) · 2.99 KB
/
transitionService.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/** @module transition */ /** for typedoc */
import {IHookRegistry, ITransitionService, TransitionOptions, IHookRegistration} from "./interface";
import {Transition} from "./transition";
import {HookRegistry} from "./hookRegistry";
import {TargetState} from "../state/module";
import {Node} from "../path/module";
import {IEventHook} from "./interface";
/**
* The default transition options.
* Include this object when applying custom defaults:
* let reloadOpts = { reload: true, notify: true }
* let options = defaults(theirOpts, customDefaults, defaultOptions);
*/
export let defaultTransOpts: TransitionOptions = {
location : true,
relative : null,
inherit : false,
notify : true,
reload : false,
custom : {},
current : () => null
};
/**
* This class provides services related to Transitions.
*
* Most importantly, it allows global Transition Hooks to be registered, and has a factory function
* for creating new Transitions.
*/
export class TransitionService implements ITransitionService, IHookRegistry {
constructor() {
HookRegistry.mixin(new HookRegistry(), this);
}
/**
* Registers a callback function as an `onBefore` Transition Hook
*
* See [[IHookRegistry.onBefore]]
*/
onBefore : IHookRegistration;
/**
* Registers a callback function as an `onStart` Transition Hook
*
* See [[IHookRegistry.onStart]]
*/
onStart : IHookRegistration;
/**
* Registers a callback function as an `onEnter` Transition Hook
*
* See [[IHookRegistry.onEnter]]
*/
onEnter : IHookRegistration;
/**
* Registers a callback function as an `onRetain` Transition Hook
*
* See [[IHookRegistry.onRetain]]
*/
onRetain : IHookRegistration;
/**
* Registers a callback function as an `onExit` Transition Hook
*
* See [[IHookRegistry.onExit]]
*/
onExit : IHookRegistration;
/**
* Registers a callback function as an `onFinish` Transition Hook
*
* See [[IHookRegistry.onFinish]]
*/
onFinish : IHookRegistration;
/**
* Registers a callback function as an `onSuccess` Transition Hook
*
* See [[IHookRegistry.onSuccess]]
*/
onSuccess : IHookRegistration;
/**
* Registers a callback function as an `onError` Transition Hook
*
* See [[IHookRegistry.onError]]
*/
onError : IHookRegistration;
/** @hidden */
getHooks : (hookName: string) => IEventHook[];
private _defaultErrorHandler: ((_error) => void) = function $defaultErrorHandler($error$) {
if ($error$ instanceof Error) {
console.error($error$);
}
};
defaultErrorHandler(handler: (error) => void) {
return this._defaultErrorHandler = handler || this._defaultErrorHandler;
}
/**
* Creates a new [[Transition]] object
*
* This is a factory function for creating new Transition objects.
*
* @param fromPath
* @param targetState
* @returns {Transition}
*/
create(fromPath: Node[], targetState: TargetState) {
return new Transition(fromPath, targetState, this);
}
}