UNPKG

1.62 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.registerUpdateGlobalState = void 0;
4var common_1 = require("../common/common");
5/**
6 * A [[TransitionHookFn]] which updates global UI-Router state
7 *
8 * Registered using `transitionService.onBefore({}, updateGlobalState);`
9 *
10 * Before a [[Transition]] starts, updates the global value of "the current transition" ([[Globals.transition]]).
11 * After a successful [[Transition]], updates the global values of "the current state"
12 * ([[Globals.current]] and [[Globals.$current]]) and "the current param values" ([[Globals.params]]).
13 *
14 * See also the deprecated properties:
15 * [[StateService.transition]], [[StateService.current]], [[StateService.params]]
16 */
17var updateGlobalState = function (trans) {
18 var globals = trans.router.globals;
19 var transitionSuccessful = function () {
20 globals.successfulTransitions.enqueue(trans);
21 globals.$current = trans.$to();
22 globals.current = globals.$current.self;
23 common_1.copy(trans.params(), globals.params);
24 };
25 var clearCurrentTransition = function () {
26 // Do not clear globals.transition if a different transition has started in the meantime
27 if (globals.transition === trans)
28 globals.transition = null;
29 };
30 trans.onSuccess({}, transitionSuccessful, { priority: 10000 });
31 trans.promise.then(clearCurrentTransition, clearCurrentTransition);
32};
33exports.registerUpdateGlobalState = function (transitionService) {
34 return transitionService.onCreate({}, updateGlobalState);
35};
36//# sourceMappingURL=updateGlobals.js.map
\No newline at end of file