UNPKG

1.31 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.getStateHookBuilder = void 0;
4/** @publicapi @module ng1 */ /** */
5var core_1 = require("@uirouter/core");
6var services_1 = require("../services");
7/**
8 * This is a [[StateBuilder.builder]] function for angular1 `onEnter`, `onExit`,
9 * `onRetain` callback hooks on a [[Ng1StateDeclaration]].
10 *
11 * When the [[StateBuilder]] builds a [[StateObject]] object from a raw [[StateDeclaration]], this builder
12 * ensures that those hooks are injectable for @uirouter/angularjs (ng1).
13 *
14 * @internalapi
15 */
16exports.getStateHookBuilder = function (hookName) {
17 return function stateHookBuilder(stateObject) {
18 var hook = stateObject[hookName];
19 var pathname = hookName === 'onExit' ? 'from' : 'to';
20 function decoratedNg1Hook(trans, state) {
21 var resolveContext = new core_1.ResolveContext(trans.treeChanges(pathname));
22 var subContext = resolveContext.subContext(state.$$state());
23 var locals = core_1.extend(services_1.getLocals(subContext), { $state$: state, $transition$: trans });
24 return core_1.services.$injector.invoke(hook, this, locals);
25 }
26 return hook ? decoratedNg1Hook : undefined;
27 };
28};
29//# sourceMappingURL=onEnterExitRetain.js.map
\No newline at end of file