UNPKG

2.2 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.registerOnEnterHook = exports.registerOnRetainHook = exports.registerOnExitHook = void 0;
4/**
5 * A factory which creates an onEnter, onExit or onRetain transition hook function
6 *
7 * The returned function invokes the (for instance) state.onEnter hook when the
8 * state is being entered.
9 */
10function makeEnterExitRetainHook(hookName) {
11 return function (transition, state) {
12 var _state = state.$$state();
13 var hookFn = _state[hookName];
14 return hookFn(transition, state);
15 };
16}
17/**
18 * The [[TransitionStateHookFn]] for onExit
19 *
20 * When the state is being exited, the state's .onExit function is invoked.
21 *
22 * Registered using `transitionService.onExit({ exiting: (state) => !!state.onExit }, onExitHook);`
23 *
24 * See: [[IHookRegistry.onExit]]
25 */
26var onExitHook = makeEnterExitRetainHook('onExit');
27exports.registerOnExitHook = function (transitionService) {
28 return transitionService.onExit({ exiting: function (state) { return !!state.onExit; } }, onExitHook);
29};
30/**
31 * The [[TransitionStateHookFn]] for onRetain
32 *
33 * When the state was already entered, and is not being exited or re-entered, the state's .onRetain function is invoked.
34 *
35 * Registered using `transitionService.onRetain({ retained: (state) => !!state.onRetain }, onRetainHook);`
36 *
37 * See: [[IHookRegistry.onRetain]]
38 */
39var onRetainHook = makeEnterExitRetainHook('onRetain');
40exports.registerOnRetainHook = function (transitionService) {
41 return transitionService.onRetain({ retained: function (state) { return !!state.onRetain; } }, onRetainHook);
42};
43/**
44 * The [[TransitionStateHookFn]] for onEnter
45 *
46 * When the state is being entered, the state's .onEnter function is invoked.
47 *
48 * Registered using `transitionService.onEnter({ entering: (state) => !!state.onEnter }, onEnterHook);`
49 *
50 * See: [[IHookRegistry.onEnter]]
51 */
52var onEnterHook = makeEnterExitRetainHook('onEnter');
53exports.registerOnEnterHook = function (transitionService) {
54 return transitionService.onEnter({ entering: function (state) { return !!state.onEnter; } }, onEnterHook);
55};
56//# sourceMappingURL=onEnterExitRetain.js.map
\No newline at end of file