UNPKG

8.45 kBTypeScriptView Raw
1import { IHookRegistry, TransitionOptions, TransitionHookScope, TransitionHookPhase, TransitionCreateHookFn, HookMatchCriteria, HookRegOptions, PathTypes, PathType, RegisteredHooks, TransitionHookFn, TransitionStateHookFn } from './interface';
2import { Transition } from './transition';
3import { RegisteredHook } from './hookRegistry';
4import { TargetState } from '../state/targetState';
5import { PathNode } from '../path/pathNode';
6import { ViewService } from '../view/view';
7import { UIRouter } from '../router';
8import { TransitionEventType } from './transitionEventType';
9import { GetResultHandler, GetErrorHandler } from './transitionHook';
10import { Disposable } from '../interface';
11/**
12 * The default [[Transition]] options.
13 *
14 * Include this object when applying custom defaults:
15 * let reloadOpts = { reload: true, notify: true }
16 * let options = defaults(theirOpts, customDefaults, defaultOptions);
17 */
18export declare let defaultTransOpts: TransitionOptions;
19/**
20 * Plugin API for Transition Service
21 */
22export interface TransitionServicePluginAPI {
23 /**
24 * Adds a Path to be used as a criterion against a TreeChanges path
25 *
26 * For example: the `exiting` path in [[HookMatchCriteria]] is a STATE scoped path.
27 * It was defined by calling `defineTreeChangesCriterion('exiting', TransitionHookScope.STATE)`
28 * Each state in the exiting path is checked against the criteria and returned as part of the match.
29 *
30 * Another example: the `to` path in [[HookMatchCriteria]] is a TRANSITION scoped path.
31 * It was defined by calling `defineTreeChangesCriterion('to', TransitionHookScope.TRANSITION)`
32 * Only the tail of the `to` path is checked against the criteria and returned as part of the match.
33 */
34 _definePathType(name: string, hookScope: TransitionHookScope): any;
35 /**
36 * Gets a Path definition used as a criterion against a TreeChanges path
37 */
38 _getPathTypes(): PathTypes;
39 /**
40 * Defines a transition hook type and returns a transition hook registration
41 * function (which can then be used to register hooks of this type).
42 */
43 _defineEvent(name: string, hookPhase: TransitionHookPhase, hookOrder: number, criteriaMatchPath: PathType, reverseSort?: boolean, getResultHandler?: GetResultHandler, getErrorHandler?: GetErrorHandler, rejectIfSuperseded?: boolean): any;
44 /**
45 * Returns the known event types, such as `onBefore`
46 * If a phase argument is provided, returns only events for the given phase.
47 */
48 _getEvents(phase?: TransitionHookPhase): TransitionEventType[];
49 /** Returns the hooks registered for the given hook name */
50 getHooks(hookName: string): RegisteredHook[];
51}
52/**
53 * This class provides services related to Transitions.
54 *
55 * - Most importantly, it allows global Transition Hooks to be registered.
56 * - It allows the default transition error handler to be set.
57 * - It also has a factory function for creating new [[Transition]] objects, (used internally by the [[StateService]]).
58 *
59 * At bootstrap, [[UIRouter]] creates a single instance (singleton) of this class.
60 *
61 * This API is located at `router.transitionService` ([[UIRouter.transitionService]])
62 */
63export declare class TransitionService implements IHookRegistry, Disposable {
64 /** @internal */
65 _transitionCount: number;
66 /** @internal */
67 $view: ViewService;
68 /** The transition hook types, such as `onEnter`, `onStart`, etc */
69 private _eventTypes;
70 /** @internal The registered transition hooks */
71 _registeredHooks: RegisteredHooks;
72 /** The paths on a criteria object */
73 private _criteriaPaths;
74 private _router;
75 /** @internal */
76 _pluginapi: TransitionServicePluginAPI;
77 /**
78 * This object has hook de-registration functions for the built-in hooks.
79 * This can be used by third parties libraries that wish to customize the behaviors
80 *
81 * @internal
82 */
83 _deregisterHookFns: {
84 addCoreResolves: Function;
85 ignored: Function;
86 invalid: Function;
87 redirectTo: Function;
88 onExit: Function;
89 onRetain: Function;
90 onEnter: Function;
91 eagerResolve: Function;
92 lazyResolve: Function;
93 resolveAll: Function;
94 loadViews: Function;
95 activateViews: Function;
96 updateGlobals: Function;
97 updateUrl: Function;
98 lazyLoad: Function;
99 };
100 /** @internal */
101 constructor(_router: UIRouter);
102 /**
103 * Registers a [[TransitionHookFn]], called *while a transition is being constructed*.
104 *
105 * Registers a transition lifecycle hook, which is invoked during transition construction.
106 *
107 * This low level hook should only be used by plugins.
108 * This can be a useful time for plugins to add resolves or mutate the transition as needed.
109 * The Sticky States plugin uses this hook to modify the treechanges.
110 *
111 * ### Lifecycle
112 *
113 * `onCreate` hooks are invoked *while a transition is being constructed*.
114 *
115 * ### Return value
116 *
117 * The hook's return value is ignored
118 *
119 * @internal
120 * @param criteria defines which Transitions the Hook should be invoked for.
121 * @param callback the hook function which will be invoked.
122 * @param options the registration options
123 * @returns a function which deregisters the hook.
124 */
125 onCreate(criteria: HookMatchCriteria, callback: TransitionCreateHookFn, options?: HookRegOptions): Function;
126 /** @inheritdoc */
127 onBefore(criteria: HookMatchCriteria, callback: TransitionHookFn, options?: HookRegOptions): Function;
128 /** @inheritdoc */
129 onStart(criteria: HookMatchCriteria, callback: TransitionHookFn, options?: HookRegOptions): Function;
130 /** @inheritdoc */
131 onExit(criteria: HookMatchCriteria, callback: TransitionStateHookFn, options?: HookRegOptions): Function;
132 /** @inheritdoc */
133 onRetain(criteria: HookMatchCriteria, callback: TransitionStateHookFn, options?: HookRegOptions): Function;
134 /** @inheritdoc */
135 onEnter(criteria: HookMatchCriteria, callback: TransitionStateHookFn, options?: HookRegOptions): Function;
136 /** @inheritdoc */
137 onFinish(criteria: HookMatchCriteria, callback: TransitionHookFn, options?: HookRegOptions): Function;
138 /** @inheritdoc */
139 onSuccess(criteria: HookMatchCriteria, callback: TransitionHookFn, options?: HookRegOptions): Function;
140 /** @inheritdoc */
141 onError(criteria: HookMatchCriteria, callback: TransitionHookFn, options?: HookRegOptions): Function;
142 /**
143 * dispose
144 * @internal
145 */
146 dispose(router: UIRouter): void;
147 /**
148 * Creates a new [[Transition]] object
149 *
150 * This is a factory function for creating new Transition objects.
151 * It is used internally by the [[StateService]] and should generally not be called by application code.
152 *
153 * @internal
154 * @param fromPath the path to the current state (the from state)
155 * @param targetState the target state (destination)
156 * @returns a Transition
157 */
158 create(fromPath: PathNode[], targetState: TargetState): Transition;
159 /** @internal */
160 private _defineCoreEvents;
161 /** @internal */
162 private _defineCorePaths;
163 /** @internal */
164 _defineEvent(name: string, hookPhase: TransitionHookPhase, hookOrder: number, criteriaMatchPath: PathType, reverseSort?: boolean, getResultHandler?: GetResultHandler, getErrorHandler?: GetErrorHandler, synchronous?: boolean): void;
165 /** @internal */
166 private _getEvents;
167 /**
168 * Adds a Path to be used as a criterion against a TreeChanges path
169 *
170 * For example: the `exiting` path in [[HookMatchCriteria]] is a STATE scoped path.
171 * It was defined by calling `defineTreeChangesCriterion('exiting', TransitionHookScope.STATE)`
172 * Each state in the exiting path is checked against the criteria and returned as part of the match.
173 *
174 * Another example: the `to` path in [[HookMatchCriteria]] is a TRANSITION scoped path.
175 * It was defined by calling `defineTreeChangesCriterion('to', TransitionHookScope.TRANSITION)`
176 * Only the tail of the `to` path is checked against the criteria and returned as part of the match.
177 *
178 * @internal
179 */
180 private _definePathType;
181 /** @internal */
182 private _getPathTypes;
183 /** @internal */
184 getHooks(hookName: string): RegisteredHook[];
185 /** @internal */
186 private _registerCoreTransitionHooks;
187}