UNPKG

4.11 kBTypeScriptView Raw
1import { IHookRegistry } from './interface';
2import { HookRegOptions, HookMatchCriteria, TreeChanges, HookMatchCriterion, IMatchingNodes, HookFn } from './interface';
3import { Transition } from './transition';
4import { StateObject } from '../state/stateObject';
5import { TransitionEventType } from './transitionEventType';
6import { TransitionService } from './transitionService';
7/**
8 * Determines if the given state matches the matchCriteria
9 *
10 * @internal
11 *
12 * @param state a State Object to test against
13 * @param criterion
14 * - If a string, matchState uses the string as a glob-matcher against the state name
15 * - If an array (of strings), matchState uses each string in the array as a glob-matchers against the state name
16 * and returns a positive match if any of the globs match.
17 * - If a function, matchState calls the function with the state and returns true if the function's result is truthy.
18 * @returns {boolean}
19 */
20export declare function matchState(state: StateObject, criterion: HookMatchCriterion, transition: Transition): boolean;
21/**
22 * The registration data for a registered transition hook
23 */
24export declare class RegisteredHook {
25 tranSvc: TransitionService;
26 eventType: TransitionEventType;
27 callback: HookFn;
28 matchCriteria: HookMatchCriteria;
29 removeHookFromRegistry: (hook: RegisteredHook) => void;
30 priority: number;
31 bind: any;
32 invokeCount: number;
33 invokeLimit: number;
34 _deregistered: boolean;
35 constructor(tranSvc: TransitionService, eventType: TransitionEventType, callback: HookFn, matchCriteria: HookMatchCriteria, removeHookFromRegistry: (hook: RegisteredHook) => void, options?: HookRegOptions);
36 /**
37 * Gets the matching [[PathNode]]s
38 *
39 * Given an array of [[PathNode]]s, and a [[HookMatchCriterion]], returns an array containing
40 * the [[PathNode]]s that the criteria matches, or `null` if there were no matching nodes.
41 *
42 * Returning `null` is significant to distinguish between the default
43 * "match-all criterion value" of `true` compared to a `() => true` function,
44 * when the nodes is an empty array.
45 *
46 * This is useful to allow a transition match criteria of `entering: true`
47 * to still match a transition, even when `entering === []`. Contrast that
48 * with `entering: (state) => true` which only matches when a state is actually
49 * being entered.
50 */
51 private _matchingNodes;
52 /**
53 * Gets the default match criteria (all `true`)
54 *
55 * Returns an object which has all the criteria match paths as keys and `true` as values, i.e.:
56 *
57 * ```js
58 * {
59 * to: true,
60 * from: true,
61 * entering: true,
62 * exiting: true,
63 * retained: true,
64 * }
65 */
66 private _getDefaultMatchCriteria;
67 /**
68 * Gets matching nodes as [[IMatchingNodes]]
69 *
70 * Create a IMatchingNodes object from the TransitionHookTypes that is roughly equivalent to:
71 *
72 * ```js
73 * let matches: IMatchingNodes = {
74 * to: _matchingNodes([tail(treeChanges.to)], mc.to),
75 * from: _matchingNodes([tail(treeChanges.from)], mc.from),
76 * exiting: _matchingNodes(treeChanges.exiting, mc.exiting),
77 * retained: _matchingNodes(treeChanges.retained, mc.retained),
78 * entering: _matchingNodes(treeChanges.entering, mc.entering),
79 * };
80 * ```
81 */
82 private _getMatchingNodes;
83 /**
84 * Determines if this hook's [[matchCriteria]] match the given [[TreeChanges]]
85 *
86 * @returns an IMatchingNodes object, or null. If an IMatchingNodes object is returned, its values
87 * are the matching [[PathNode]]s for each [[HookMatchCriterion]] (to, from, exiting, retained, entering)
88 */
89 matches(treeChanges: TreeChanges, transition: Transition): IMatchingNodes;
90 deregister(): void;
91}
92/** Return a registration function of the requested type. */
93export declare function makeEvent(registry: IHookRegistry, transitionService: TransitionService, eventType: TransitionEventType): (matchObject: any, callback: any, options?: {}) => any;