UNPKG

6.62 kBTypeScriptView Raw
1import { StateDeclaration, _ViewDeclaration, _StateDeclaration, LazyLoadResult } from './interface';
2import { Param } from '../params/param';
3import { UrlMatcher } from '../url/urlMatcher';
4import { Resolvable } from '../resolve/resolvable';
5import { TransitionStateHookFn } from '../transition/interface';
6import { TargetState } from './targetState';
7import { Transition } from '../transition/transition';
8import { Glob } from '../common/glob';
9/**
10 * Internal representation of a UI-Router state.
11 *
12 * Instances of this class are created when a [[StateDeclaration]] is registered with the [[StateRegistry]].
13 *
14 * A registered [[StateDeclaration]] is augmented with a getter ([[StateDeclaration.$$state]]) which returns the corresponding [[StateObject]] object.
15 *
16 * This class prototypally inherits from the corresponding [[StateDeclaration]].
17 * Each of its own properties (i.e., `hasOwnProperty`) are built using builders from the [[StateBuilder]].
18 */
19export declare class StateObject {
20 /** The parent [[StateObject]] */
21 parent: StateObject;
22 /** The name used to register the state */
23 name: string;
24 /** Prototypally inherits from [[StateDeclaration.abstract]] */
25 abstract: boolean;
26 /** Prototypally inherits from [[StateDeclaration.resolve]] */
27 resolve: {
28 [key: string]: string | any[] | Function;
29 } | any[];
30 /** A list of [[Resolvable]] objects. The internal representation of [[resolve]]. */
31 resolvables: Resolvable[];
32 /** Prototypally inherits from [[StateDeclaration.resolvePolicy]] */
33 resolvePolicy: any;
34 /** A compiled URLMatcher which detects when the state's URL is matched */
35 url: UrlMatcher;
36 /** The parameters for the state, built from the URL and [[StateDeclaration.params]] */
37 params: {
38 [key: string]: Param;
39 };
40 /**
41 * The views for the state.
42 * Note: `@uirouter/core` does not register a builder for views.
43 * The framework specific code should register a `views` builder.
44 */
45 views: {
46 [key: string]: _ViewDeclaration;
47 };
48 /**
49 * The original [[StateDeclaration]] used to build this [[StateObject]].
50 * Note: `this` object also prototypally inherits from the `self` declaration object.
51 */
52 self: StateDeclaration;
53 /** The nearest parent [[StateObject]] which has a URL */
54 navigable: StateObject;
55 /** The parent [[StateObject]] objects from this state up to the root */
56 path: StateObject[];
57 /**
58 * Prototypally inherits from [[StateDeclaration.data]]
59 * Note: This is the only field on the [[StateDeclaration]] which is mutated.
60 * The definition object's `data` field is replaced with a new object
61 * which prototypally inherits from the parent state definition's `data` field.
62 */
63 data: any;
64 /**
65 * An object containing the parent States' names as keys and
66 * true as their values.
67 */
68 includes: {
69 [name: string]: boolean;
70 };
71 /** Prototypally inherits from [[StateDeclaration.onExit]] */
72 onExit: TransitionStateHookFn;
73 /** Prototypally inherits from [[StateDeclaration.onRetain]] */
74 onRetain: TransitionStateHookFn;
75 /** Prototypally inherits from [[StateDeclaration.onEnter]] */
76 onEnter: TransitionStateHookFn;
77 /** Prototypally inherits from [[StateDeclaration.lazyLoad]] */
78 lazyLoad: (transition: Transition, state: StateDeclaration) => Promise<LazyLoadResult>;
79 /** Prototypally inherits from [[StateDeclaration.redirectTo]] */
80 redirectTo: string | (($transition$: Transition) => TargetState) | {
81 state: string | StateDeclaration;
82 params: {
83 [key: string]: any;
84 };
85 };
86 /** @internal */
87 __stateObjectCache: {
88 /** Might be null */
89 nameGlob?: Glob;
90 };
91 /**
92 * Create a state object to put the private/internal implementation details onto.
93 * The object's prototype chain looks like:
94 * (Internal State Object) -> (Copy of State.prototype) -> (State Declaration object) -> (State Declaration's prototype...)
95 *
96 * @param stateDecl the user-supplied State Declaration
97 * @returns {StateObject} an internal State object
98 */
99 static create(stateDecl: _StateDeclaration): StateObject;
100 /** Predicate which returns true if the object is an class with @State() decorator */
101 static isStateClass: (stateDecl: _StateDeclaration) => stateDecl is new () => StateDeclaration;
102 /** Predicate which returns true if the object is a [[StateDeclaration]] object */
103 static isStateDeclaration: (obj: any) => obj is StateDeclaration;
104 /** Predicate which returns true if the object is an internal [[StateObject]] object */
105 static isState: (obj: any) => obj is StateObject;
106 /** @deprecated use State.create() */
107 constructor(config?: StateDeclaration);
108 /**
109 * Returns true if the provided parameter is the same state.
110 *
111 * Compares the identity of the state against the passed value, which is either an object
112 * reference to the actual `State` instance, the original definition object passed to
113 * `$stateProvider.state()`, or the fully-qualified name.
114 *
115 * @param ref Can be one of (a) a `State` instance, (b) an object that was passed
116 * into `$stateProvider.state()`, (c) the fully-qualified name of a state as a string.
117 * @returns Returns `true` if `ref` matches the current `State` instance.
118 */
119 is(ref: StateObject | StateDeclaration | string): boolean;
120 /**
121 * @deprecated this does not properly handle dot notation
122 * @returns Returns a dot-separated name of the state.
123 */
124 fqn(): string;
125 /**
126 * Returns the root node of this state's tree.
127 *
128 * @returns The root of this state's tree.
129 */
130 root(): StateObject;
131 /**
132 * Gets the state's `Param` objects
133 *
134 * Gets the list of [[Param]] objects owned by the state.
135 * If `opts.inherit` is true, it also includes the ancestor states' [[Param]] objects.
136 * If `opts.matchingKeys` exists, returns only `Param`s whose `id` is a key on the `matchingKeys` object
137 *
138 * @param opts options
139 */
140 parameters(opts?: {
141 inherit?: boolean;
142 matchingKeys?: any;
143 }): Param[];
144 /**
145 * Returns a single [[Param]] that is owned by the state
146 *
147 * If `opts.inherit` is true, it also searches the ancestor states` [[Param]]s.
148 * @param id the name of the [[Param]] to return
149 * @param opts options
150 */
151 parameter(id: string, opts?: {
152 inherit?: boolean;
153 }): Param;
154 toString(): string;
155}