UNPKG

1.96 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.treeChangesCleanup = exports.registerAddCoreResolvables = void 0;
4var transition_1 = require("../transition/transition");
5var router_1 = require("../router");
6var resolve_1 = require("../resolve");
7var common_1 = require("../common");
8function addCoreResolvables(trans) {
9 trans.addResolvable(resolve_1.Resolvable.fromData(router_1.UIRouter, trans.router), '');
10 trans.addResolvable(resolve_1.Resolvable.fromData(transition_1.Transition, trans), '');
11 trans.addResolvable(resolve_1.Resolvable.fromData('$transition$', trans), '');
12 trans.addResolvable(resolve_1.Resolvable.fromData('$stateParams', trans.params()), '');
13 trans.entering().forEach(function (state) {
14 trans.addResolvable(resolve_1.Resolvable.fromData('$state$', state), state);
15 });
16}
17exports.registerAddCoreResolvables = function (transitionService) {
18 return transitionService.onCreate({}, addCoreResolvables);
19};
20var TRANSITION_TOKENS = ['$transition$', transition_1.Transition];
21var isTransition = common_1.inArray(TRANSITION_TOKENS);
22// References to Transition in the treeChanges pathnodes makes all
23// previous Transitions reachable in memory, causing a memory leak
24// This function removes resolves for '$transition$' and `Transition` from the treeChanges.
25// Do not use this on current transitions, only on old ones.
26exports.treeChangesCleanup = function (trans) {
27 var nodes = common_1.values(trans.treeChanges()).reduce(common_1.unnestR, []).reduce(common_1.uniqR, []);
28 // If the resolvable is a Transition, return a new resolvable with null data
29 var replaceTransitionWithNull = function (r) {
30 return isTransition(r.token) ? resolve_1.Resolvable.fromData(r.token, null) : r;
31 };
32 nodes.forEach(function (node) {
33 node.resolvables = node.resolvables.map(replaceTransitionWithNull);
34 });
35};
36//# sourceMappingURL=coreResolvables.js.map
\No newline at end of file