UNPKG

4 kBTypeScriptView Raw
1import { StateDeclaration, StateOrName, TargetStateDef } from './interface';
2import { TransitionOptions } from '../transition/interface';
3import { StateObject } from './stateObject';
4import { StateRegistry } from './stateRegistry';
5import { RawParams } from '../params';
6/**
7 * Encapsulate the target (destination) state/params/options of a [[Transition]].
8 *
9 * This class is frequently used to redirect a transition to a new destination.
10 *
11 * See:
12 *
13 * - [[HookResult]]
14 * - [[TransitionHookFn]]
15 * - [[TransitionService.onStart]]
16 *
17 * To create a `TargetState`, use [[StateService.target]].
18 *
19 * ---
20 *
21 * This class wraps:
22 *
23 * 1) an identifier for a state
24 * 2) a set of parameters
25 * 3) and transition options
26 * 4) the registered state object (the [[StateDeclaration]])
27 *
28 * Many UI-Router APIs such as [[StateService.go]] take a [[StateOrName]] argument which can
29 * either be a *state object* (a [[StateDeclaration]] or [[StateObject]]) or a *state name* (a string).
30 * The `TargetState` class normalizes those options.
31 *
32 * A `TargetState` may be valid (the state being targeted exists in the registry)
33 * or invalid (the state being targeted is not registered).
34 */
35export declare class TargetState {
36 private _stateRegistry;
37 private _identifier;
38 private _definition;
39 private _params;
40 private _options;
41 /** Returns true if the object has a state property that might be a state or state name */
42 static isDef: (obj: any) => obj is TargetStateDef;
43 /**
44 * The TargetState constructor
45 *
46 * Note: Do not construct a `TargetState` manually.
47 * To create a `TargetState`, use the [[StateService.target]] factory method.
48 *
49 * @param _stateRegistry The StateRegistry to use to look up the _definition
50 * @param _identifier An identifier for a state.
51 * Either a fully-qualified state name, or the object used to define the state.
52 * @param _params Parameters for the target state
53 * @param _options Transition options.
54 *
55 * @internal
56 */
57 constructor(_stateRegistry: StateRegistry, _identifier: StateOrName, _params?: RawParams, _options?: TransitionOptions);
58 /** The name of the state this object targets */
59 name(): string;
60 /** The identifier used when creating this TargetState */
61 identifier(): StateOrName;
62 /** The target parameter values */
63 params(): RawParams;
64 /** The internal state object (if it was found) */
65 $state(): StateObject;
66 /** The internal state declaration (if it was found) */
67 state(): StateDeclaration;
68 /** The target options */
69 options(): TransitionOptions;
70 /** True if the target state was found */
71 exists(): boolean;
72 /** True if the object is valid */
73 valid(): boolean;
74 /** If the object is invalid, returns the reason why */
75 error(): string;
76 toString(): string;
77 /**
78 * Returns a copy of this TargetState which targets a different state.
79 * The new TargetState has the same parameter values and transition options.
80 *
81 * @param state The new state that should be targeted
82 */
83 withState(state: StateOrName): TargetState;
84 /**
85 * Returns a copy of this TargetState, using the specified parameter values.
86 *
87 * @param params the new parameter values to use
88 * @param replace When false (default) the new parameter values will be merged with the current values.
89 * When true the parameter values will be used instead of the current values.
90 */
91 withParams(params: RawParams, replace?: boolean): TargetState;
92 /**
93 * Returns a copy of this TargetState, using the specified Transition Options.
94 *
95 * @param options the new options to use
96 * @param replace When false (default) the new options will be merged with the current options.
97 * When true the options will be used instead of the current options.
98 */
99 withOptions(options: TransitionOptions, replace?: boolean): TargetState;
100}