1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.TransitionService = exports.defaultTransOpts = void 0;
|
4 | var interface_1 = require("./interface");
|
5 | var transition_1 = require("./transition");
|
6 | var hookRegistry_1 = require("./hookRegistry");
|
7 | var coreResolvables_1 = require("../hooks/coreResolvables");
|
8 | var redirectTo_1 = require("../hooks/redirectTo");
|
9 | var onEnterExitRetain_1 = require("../hooks/onEnterExitRetain");
|
10 | var resolve_1 = require("../hooks/resolve");
|
11 | var views_1 = require("../hooks/views");
|
12 | var updateGlobals_1 = require("../hooks/updateGlobals");
|
13 | var url_1 = require("../hooks/url");
|
14 | var lazyLoad_1 = require("../hooks/lazyLoad");
|
15 | var transitionEventType_1 = require("./transitionEventType");
|
16 | var transitionHook_1 = require("./transitionHook");
|
17 | var predicates_1 = require("../common/predicates");
|
18 | var common_1 = require("../common/common");
|
19 | var hof_1 = require("../common/hof");
|
20 | var ignoredTransition_1 = require("../hooks/ignoredTransition");
|
21 | var invalidTransition_1 = require("../hooks/invalidTransition");
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 | exports.defaultTransOpts = {
|
30 | location: true,
|
31 | relative: null,
|
32 | inherit: false,
|
33 | notify: true,
|
34 | reload: false,
|
35 | supercede: true,
|
36 | custom: {},
|
37 | current: function () { return null; },
|
38 | source: 'unknown',
|
39 | };
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | var TransitionService = (function () {
|
52 |
|
53 | function TransitionService(_router) {
|
54 |
|
55 | this._transitionCount = 0;
|
56 |
|
57 | this._eventTypes = [];
|
58 |
|
59 | this._registeredHooks = {};
|
60 |
|
61 | this._criteriaPaths = {};
|
62 | this._router = _router;
|
63 | this.$view = _router.viewService;
|
64 | this._deregisterHookFns = {};
|
65 | this._pluginapi = (common_1.createProxyFunctions(hof_1.val(this), {}, hof_1.val(this), [
|
66 | '_definePathType',
|
67 | '_defineEvent',
|
68 | '_getPathTypes',
|
69 | '_getEvents',
|
70 | 'getHooks',
|
71 | ]));
|
72 | this._defineCorePaths();
|
73 | this._defineCoreEvents();
|
74 | this._registerCoreTransitionHooks();
|
75 | _router.globals.successfulTransitions.onEvict(coreResolvables_1.treeChangesCleanup);
|
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 | TransitionService.prototype.onCreate = function (criteria, callback, options) {
|
101 | return;
|
102 | };
|
103 |
|
104 | TransitionService.prototype.onBefore = function (criteria, callback, options) {
|
105 | return;
|
106 | };
|
107 |
|
108 | TransitionService.prototype.onStart = function (criteria, callback, options) {
|
109 | return;
|
110 | };
|
111 |
|
112 | TransitionService.prototype.onExit = function (criteria, callback, options) {
|
113 | return;
|
114 | };
|
115 |
|
116 | TransitionService.prototype.onRetain = function (criteria, callback, options) {
|
117 | return;
|
118 | };
|
119 |
|
120 | TransitionService.prototype.onEnter = function (criteria, callback, options) {
|
121 | return;
|
122 | };
|
123 |
|
124 | TransitionService.prototype.onFinish = function (criteria, callback, options) {
|
125 | return;
|
126 | };
|
127 |
|
128 | TransitionService.prototype.onSuccess = function (criteria, callback, options) {
|
129 | return;
|
130 | };
|
131 |
|
132 | TransitionService.prototype.onError = function (criteria, callback, options) {
|
133 | return;
|
134 | };
|
135 | |
136 |
|
137 |
|
138 |
|
139 | TransitionService.prototype.dispose = function (router) {
|
140 | common_1.values(this._registeredHooks).forEach(function (hooksArray) {
|
141 | return hooksArray.forEach(function (hook) {
|
142 | hook._deregistered = true;
|
143 | common_1.removeFrom(hooksArray, hook);
|
144 | });
|
145 | });
|
146 | };
|
147 | |
148 |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 | TransitionService.prototype.create = function (fromPath, targetState) {
|
159 | return new transition_1.Transition(fromPath, targetState, this._router);
|
160 | };
|
161 |
|
162 | TransitionService.prototype._defineCoreEvents = function () {
|
163 | var Phase = interface_1.TransitionHookPhase;
|
164 | var TH = transitionHook_1.TransitionHook;
|
165 | var paths = this._criteriaPaths;
|
166 | var NORMAL_SORT = false, REVERSE_SORT = true;
|
167 | var SYNCHRONOUS = true;
|
168 | this._defineEvent('onCreate', Phase.CREATE, 0, paths.to, NORMAL_SORT, TH.LOG_REJECTED_RESULT, TH.THROW_ERROR, SYNCHRONOUS);
|
169 | this._defineEvent('onBefore', Phase.BEFORE, 0, paths.to);
|
170 | this._defineEvent('onStart', Phase.RUN, 0, paths.to);
|
171 | this._defineEvent('onExit', Phase.RUN, 100, paths.exiting, REVERSE_SORT);
|
172 | this._defineEvent('onRetain', Phase.RUN, 200, paths.retained);
|
173 | this._defineEvent('onEnter', Phase.RUN, 300, paths.entering);
|
174 | this._defineEvent('onFinish', Phase.RUN, 400, paths.to);
|
175 | this._defineEvent('onSuccess', Phase.SUCCESS, 0, paths.to, NORMAL_SORT, TH.LOG_REJECTED_RESULT, TH.LOG_ERROR, SYNCHRONOUS);
|
176 | this._defineEvent('onError', Phase.ERROR, 0, paths.to, NORMAL_SORT, TH.LOG_REJECTED_RESULT, TH.LOG_ERROR, SYNCHRONOUS);
|
177 | };
|
178 |
|
179 | TransitionService.prototype._defineCorePaths = function () {
|
180 | var STATE = interface_1.TransitionHookScope.STATE, TRANSITION = interface_1.TransitionHookScope.TRANSITION;
|
181 | this._definePathType('to', TRANSITION);
|
182 | this._definePathType('from', TRANSITION);
|
183 | this._definePathType('exiting', STATE);
|
184 | this._definePathType('retained', STATE);
|
185 | this._definePathType('entering', STATE);
|
186 | };
|
187 |
|
188 | TransitionService.prototype._defineEvent = function (name, hookPhase, hookOrder, criteriaMatchPath, reverseSort, getResultHandler, getErrorHandler, synchronous) {
|
189 | if (reverseSort === void 0) { reverseSort = false; }
|
190 | if (getResultHandler === void 0) { getResultHandler = transitionHook_1.TransitionHook.HANDLE_RESULT; }
|
191 | if (getErrorHandler === void 0) { getErrorHandler = transitionHook_1.TransitionHook.REJECT_ERROR; }
|
192 | if (synchronous === void 0) { synchronous = false; }
|
193 | var eventType = new transitionEventType_1.TransitionEventType(name, hookPhase, hookOrder, criteriaMatchPath, reverseSort, getResultHandler, getErrorHandler, synchronous);
|
194 | this._eventTypes.push(eventType);
|
195 | hookRegistry_1.makeEvent(this, this, eventType);
|
196 | };
|
197 |
|
198 | TransitionService.prototype._getEvents = function (phase) {
|
199 | var transitionHookTypes = predicates_1.isDefined(phase)
|
200 | ? this._eventTypes.filter(function (type) { return type.hookPhase === phase; })
|
201 | : this._eventTypes.slice();
|
202 | return transitionHookTypes.sort(function (l, r) {
|
203 | var cmpByPhase = l.hookPhase - r.hookPhase;
|
204 | return cmpByPhase === 0 ? l.hookOrder - r.hookOrder : cmpByPhase;
|
205 | });
|
206 | };
|
207 | |
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 |
|
217 |
|
218 |
|
219 |
|
220 | TransitionService.prototype._definePathType = function (name, hookScope) {
|
221 | this._criteriaPaths[name] = { name: name, scope: hookScope };
|
222 | };
|
223 |
|
224 |
|
225 | TransitionService.prototype._getPathTypes = function () {
|
226 | return this._criteriaPaths;
|
227 | };
|
228 |
|
229 | TransitionService.prototype.getHooks = function (hookName) {
|
230 | return this._registeredHooks[hookName];
|
231 | };
|
232 |
|
233 | TransitionService.prototype._registerCoreTransitionHooks = function () {
|
234 | var fns = this._deregisterHookFns;
|
235 | fns.addCoreResolves = coreResolvables_1.registerAddCoreResolvables(this);
|
236 | fns.ignored = ignoredTransition_1.registerIgnoredTransitionHook(this);
|
237 | fns.invalid = invalidTransition_1.registerInvalidTransitionHook(this);
|
238 |
|
239 | fns.redirectTo = redirectTo_1.registerRedirectToHook(this);
|
240 |
|
241 | fns.onExit = onEnterExitRetain_1.registerOnExitHook(this);
|
242 | fns.onRetain = onEnterExitRetain_1.registerOnRetainHook(this);
|
243 | fns.onEnter = onEnterExitRetain_1.registerOnEnterHook(this);
|
244 |
|
245 | fns.eagerResolve = resolve_1.registerEagerResolvePath(this);
|
246 | fns.lazyResolve = resolve_1.registerLazyResolveState(this);
|
247 | fns.resolveAll = resolve_1.registerResolveRemaining(this);
|
248 |
|
249 | fns.loadViews = views_1.registerLoadEnteringViews(this);
|
250 | fns.activateViews = views_1.registerActivateViews(this);
|
251 |
|
252 | fns.updateGlobals = updateGlobals_1.registerUpdateGlobalState(this);
|
253 |
|
254 | fns.updateUrl = url_1.registerUpdateUrl(this);
|
255 |
|
256 | fns.lazyLoad = lazyLoad_1.registerLazyLoadHook(this);
|
257 | };
|
258 | return TransitionService;
|
259 | }());
|
260 | exports.TransitionService = TransitionService;
|
261 |
|
\ | No newline at end of file |