1 | import { StateObject } from './stateObject';
|
2 | import { StateMatcher } from './stateMatcher';
|
3 | import { StateQueueManager } from './stateQueueManager';
|
4 | import { StateDeclaration, _StateDeclaration } from './interface';
|
5 | import { BuilderFunction } from './stateBuilder';
|
6 | import { StateOrName } from './interface';
|
7 | import { UIRouter } from '../router';
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | export type StateRegistryListener = (event: 'registered' | 'deregistered', states: StateDeclaration[]) => void;
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | export declare class StateRegistry {
|
23 | private router;
|
24 | private _root;
|
25 | private states;
|
26 |
|
27 | matcher: StateMatcher;
|
28 | private builder;
|
29 |
|
30 | stateQueue: StateQueueManager;
|
31 |
|
32 | listeners: StateRegistryListener[];
|
33 |
|
34 | constructor(router: UIRouter);
|
35 | /** @internal */
|
36 | private _registerRoot;
|
37 | /** @internal */
|
38 | dispose(): void;
|
39 | /**
|
40 | * Listen for a State Registry events
|
41 | *
|
42 | * Adds a callback that is invoked when states are registered or deregistered with the StateRegistry.
|
43 | *
|
44 | * #### Example:
|
45 | * ```js
|
46 | * let allStates = registry.get();
|
47 | *
|
48 | * // Later, invoke deregisterFn() to remove the listener
|
49 | * let deregisterFn = registry.onStatesChanged((event, states) => {
|
50 | * switch(event) {
|
51 | * case: 'registered':
|
52 | * states.forEach(state => allStates.push(state));
|
53 | * break;
|
54 | * case: 'deregistered':
|
55 | * states.forEach(state => {
|
56 | * let idx = allStates.indexOf(state);
|
57 | * if (idx !== -1) allStates.splice(idx, 1);
|
58 | * });
|
59 | * break;
|
60 | * }
|
61 | * });
|
62 | * ```
|
63 | *
|
64 | * @param listener a callback function invoked when the registered states changes.
|
65 | * The function receives two parameters, `event` and `state`.
|
66 | * See [[StateRegistryListener]]
|
67 | * @return a function that deregisters the listener
|
68 | */
|
69 | onStatesChanged(listener: StateRegistryListener): () => void;
|
70 | /**
|
71 | * Gets the implicit root state
|
72 | *
|
73 | * Gets the root of the state tree.
|
74 | * The root state is implicitly created by UI-Router.
|
75 | * Note: this returns the internal [[StateObject]] representation, not a [[StateDeclaration]]
|
76 | *
|
77 | * @return the root [[StateObject]]
|
78 | */
|
79 | root(): StateObject;
|
80 | /**
|
81 | * Adds a state to the registry
|
82 | *
|
83 | * Registers a [[StateDeclaration]] or queues it for registration.
|
84 | *
|
85 | * Note: a state will be queued if the state's parent isn't yet registered.
|
86 | *
|
87 | * @param stateDefinition the definition of the state to register.
|
88 | * @returns the internal [[StateObject]] object.
|
89 | * If the state was successfully registered, then the object is fully built (See: [[StateBuilder]]).
|
90 | * If the state was only queued, then the object is not fully built.
|
91 | */
|
92 | register(stateDefinition: _StateDeclaration): StateObject;
|
93 | /** @internal */
|
94 | private _deregisterTree;
|
95 | /**
|
96 | * Removes a state from the registry
|
97 | *
|
98 | * This removes a state from the registry.
|
99 | * If the state has children, they are are also removed from the registry.
|
100 | *
|
101 | * @param stateOrName the state's name or object representation
|
102 | * @returns {StateObject[]} a list of removed states
|
103 | */
|
104 | deregister(stateOrName: StateOrName): StateObject[];
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 | get(): StateDeclaration[];
|
114 | |
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 | get(stateOrName: StateOrName, base?: StateOrName): StateDeclaration;
|
125 | |
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 | decorator(property: string, builderFunction: BuilderFunction): Function;
|
136 | }
|