UNPKG

1.95 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.registerActivateViews = exports.registerLoadEnteringViews = void 0;
4var common_1 = require("../common/common");
5var coreservices_1 = require("../common/coreservices");
6/**
7 * A [[TransitionHookFn]] which waits for the views to load
8 *
9 * Registered using `transitionService.onStart({}, loadEnteringViews);`
10 *
11 * Allows the views to do async work in [[ViewConfig.load]] before the transition continues.
12 * In angular 1, this includes loading the templates.
13 */
14var loadEnteringViews = function (transition) {
15 var $q = coreservices_1.services.$q;
16 var enteringViews = transition.views('entering');
17 if (!enteringViews.length)
18 return;
19 return $q.all(enteringViews.map(function (view) { return $q.when(view.load()); })).then(common_1.noop);
20};
21exports.registerLoadEnteringViews = function (transitionService) {
22 return transitionService.onFinish({}, loadEnteringViews);
23};
24/**
25 * A [[TransitionHookFn]] which activates the new views when a transition is successful.
26 *
27 * Registered using `transitionService.onSuccess({}, activateViews);`
28 *
29 * After a transition is complete, this hook deactivates the old views from the previous state,
30 * and activates the new views from the destination state.
31 *
32 * See [[ViewService]]
33 */
34var activateViews = function (transition) {
35 var enteringViews = transition.views('entering');
36 var exitingViews = transition.views('exiting');
37 if (!enteringViews.length && !exitingViews.length)
38 return;
39 var $view = transition.router.viewService;
40 exitingViews.forEach(function (vc) { return $view.deactivateViewConfig(vc); });
41 enteringViews.forEach(function (vc) { return $view.activateViewConfig(vc); });
42 $view.sync();
43};
44exports.registerActivateViews = function (transitionService) {
45 return transitionService.onSuccess({}, activateViews);
46};
47//# sourceMappingURL=views.js.map
\No newline at end of file