UNPKG

@uirouter/core

Version:

UI-Router Core: Framework agnostic, State-based routing for JavaScript Single Page Apps

47 lines 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.registerActivateViews = exports.registerLoadEnteringViews = void 0; var common_1 = require("../common/common"); var coreservices_1 = require("../common/coreservices"); /** * A [[TransitionHookFn]] which waits for the views to load * * Registered using `transitionService.onStart({}, loadEnteringViews);` * * Allows the views to do async work in [[ViewConfig.load]] before the transition continues. * In angular 1, this includes loading the templates. */ var loadEnteringViews = function (transition) { var $q = coreservices_1.services.$q; var enteringViews = transition.views('entering'); if (!enteringViews.length) return; return $q.all(enteringViews.map(function (view) { return $q.when(view.load()); })).then(common_1.noop); }; exports.registerLoadEnteringViews = function (transitionService) { return transitionService.onFinish({}, loadEnteringViews); }; /** * A [[TransitionHookFn]] which activates the new views when a transition is successful. * * Registered using `transitionService.onSuccess({}, activateViews);` * * After a transition is complete, this hook deactivates the old views from the previous state, * and activates the new views from the destination state. * * See [[ViewService]] */ var activateViews = function (transition) { var enteringViews = transition.views('entering'); var exitingViews = transition.views('exiting'); if (!enteringViews.length && !exitingViews.length) return; var $view = transition.router.viewService; exitingViews.forEach(function (vc) { return $view.deactivateViewConfig(vc); }); enteringViews.forEach(function (vc) { return $view.activateViewConfig(vc); }); $view.sync(); }; exports.registerActivateViews = function (transitionService) { return transitionService.onSuccess({}, activateViews); }; //# sourceMappingURL=views.js.map