Skip to content

Commit c319e28

Browse files
docs(params): Finish docs of ParamDeclaration
1 parent b1fb874 commit c319e28

File tree

2 files changed

+140
-39
lines changed

2 files changed

+140
-39
lines changed

src/params/interface.ts

Lines changed: 138 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,23 @@ export interface RawParams {
88
export type ParamsOrArray = (RawParams|RawParams[]);
99

1010
/**
11-
* Inside the [[StateDeclaration.params]] object of a [[StateDeclaration]]:
12-
* A ParamDeclaration object defines how a single State Parameter should work.
11+
Inside a [[StateDeclaration.params]]:
1312
*
14-
* @example ---
13+
* A ParamDeclaration object defines how a single State Parameter should work.
1514
*
15+
* @example
1616
* ```
17+
*
1718
* var mystate = {
1819
* template: '<div ui-view/>',
1920
* controller: function() {}
2021
* url: '/mystate/:param1',
2122
* params: {
22-
* param1: "index", // Default value for 'param1'
23+
* param1: "index", // <-- Default value for 'param1'
24+
* // (shorthand ParamDeclaration)
2325
*
24-
* nonUrlParam: { // ParamDeclaration for 'nonUrlParam' starts
25-
* type: "int", // non
26+
* nonUrlParam: { // <-- ParamDeclaration for 'nonUrlParam'
27+
* type: "int",
2628
* array: true,
2729
* value: []
2830
* }
@@ -32,6 +34,8 @@ export type ParamsOrArray = (RawParams|RawParams[]);
3234
*/
3335
export interface ParamDeclaration {
3436
/**
37+
* A property of [[ParamDeclaration]]:
38+
*
3539
* Specifies the default value for this parameter. This implicitly sets this parameter as optional.
3640
*
3741
* When UI-Router routes to a state and no value is specified for this parameter in the URL or transition,
@@ -53,7 +57,8 @@ export interface ParamDeclaration {
5357
* }
5458
*```
5559
*
56-
* Shorthand: If you only need to configure the default value of the parameter, you may use a shorthand syntax.
60+
* ### Shorthand Declaration
61+
* If you only want to set the default value of the parameter, you may use a shorthand syntax.
5762
* In the params map, instead mapping the param name to a full parameter configuration object, simply set map it
5863
* to the default parameter value, e.g.:
5964
* ```
@@ -79,33 +84,138 @@ export interface ParamDeclaration {
7984
value?: any;
8085

8186
/**
82-
* Specifies the parameter type.
87+
* A property of [[ParamDeclaration]]:
8388
*
84-
* Supplying a parameter type
89+
* Specifies the [[Type]] of the parameter.
90+
*
91+
* Set this property to the name of parameter's type. The type may be either one of the
92+
* built in types, or a custom type that has been registered with the [[$urlMatcherFactory]]
8593
*/
8694
type: (string|Type);
95+
96+
/**
97+
* A property of [[ParamDeclaration]]:
98+
*
99+
* Explicitly specifies the array mode of a URL parameter
100+
*
101+
* - If `false`, the parameter value will be treated (encoded/decoded) as a single value
102+
* - If `true`, the parameter value will be treated (encoded/decoded) as an array of values.
103+
* - If `auto` (for query parameters only), if multiple values for a single parameter are present
104+
* in the URL (e.g.: /foo?bar=1&bar=2&bar=3) then the values are mapped to an array (e.g.:
105+
* `{ foo: [ '1', '2', '3' ] }`). However, if only one value is present (e.g.: /foo?bar=1)
106+
* then the value is treated as single value (e.g.: { foo: '1' }).
107+
*
108+
109+
* If you specified a [[type]] for the parameter, the value will be treated as an array
110+
* of the specified Type.
111+
*
112+
* @example
113+
* ```
114+
*
115+
* {
116+
* name: 'foo',
117+
* url: '/foo/{arrayParam:int}`,
118+
* params: {
119+
* arrayParam: { array: true }
120+
* }
121+
* }
122+
*
123+
* // After the transition, URL should be '/foo/1-2-3'
124+
* $state.go("foo", { arrayParam: [ 1, 2, 3 ] });
125+
* ```
126+
*
127+
* @default `false` for path parameters, such as `url: '/foo/:pathParam'`
128+
* @default `auto` for query parameters, such as `url: '/foo?queryParam'`
129+
* @default `true` if the parameter name ends in `[]`, such as `url: '/foo/{implicitArrayParam:int[]}'`
130+
*/
87131
array: boolean;
132+
/**
133+
* A property of [[ParamDeclaration]]:
134+
*
135+
* Configures how a default parameter value is represented in the URL when the current parameter value
136+
* is the same as the default value.
137+
*
138+
* There are three squash settings:
139+
*
140+
* - `false`: The parameter's default value is not squashed. It is encoded and included in the URL
141+
* - `true`: The parameter's default value is omitted from the URL. If the parameter is preceeded
142+
* and followed by slashes in the state's url declaration, then one of those slashes are omitted.
143+
* This can allow for cleaner looking URLs.
144+
* - `"&lt;arbitrary string&gt;"`: The parameter's default value is replaced with an arbitrary
145+
* placeholder of your choice.
146+
*
147+
* @example
148+
* ```
149+
*
150+
* {
151+
* name: 'mystate',
152+
* url: '/mystate/:myparam',
153+
* params: {
154+
* myparam: 'defaultParamValue'
155+
* squash: true
156+
* }
157+
* }
158+
*
159+
* // URL will be `/mystate/`
160+
* $state.go('mystate', { myparam: 'defaultParamValue' });
161+
*
162+
* // URL will be `/mystate/someOtherValue`
163+
* $state.go('mystate', { myparam: 'someOtherValue' });
164+
* ```
165+
*
166+
* @example
167+
* ```
168+
*
169+
* {
170+
* name: 'mystate2',
171+
* url: '/mystate2/:myparam2',
172+
* params: {
173+
* myparam2: 'defaultParamValue'
174+
* squash: "~"
175+
* }
176+
* }
177+
*
178+
* // URL will be `/mystate/~`
179+
* $state.go('mystate', { myparam2: 'defaultParamValue' });
180+
*
181+
* // URL will be `/mystate/someOtherValue`
182+
* $state.go('mystate', { myparam2: 'someOtherValue' });
183+
* ```
184+
*
185+
* If squash is not set, it uses the configured default squash policy. (See [[defaultSquashPolicy]]())
186+
*/
88187
squash: (boolean|string);
89-
replace: any;
90-
/** @internal */
188+
/**
189+
* @hidden
190+
* @internalapi
191+
*
192+
* An array of [[Replace]] objects.
193+
*
194+
* When creating a Transition, defines how to handle certain special values, such as `undefined`, `null`,
195+
* or empty string `""`. If the transition is started, and the parameter value is equal to one of the "to"
196+
* values, then the parameter value is replaced with the "from" value.
197+
*
198+
* @example
199+
* ```
200+
*
201+
* replace: [
202+
* { from: undefined, to: null },
203+
* { from: "", to: null }
204+
* ]
205+
*/
206+
replace: Replace[];
207+
/**
208+
* @hidden
209+
* @internalapi
210+
*
211+
* This is not part of the declaration; it is a calculated value depending on if a default value was specified or not.
212+
*/
91213
isOptional: boolean;
214+
/** @todo document this one too */
92215
dynamic: boolean;
93216
}
94217

95-
/**
96-
* Inside a state definition:
97-
* A nested object named `params` which defines state parameter customizations.
98-
*
99-
* The ParamDeclaration contains configuration for state parameter declarations.
100-
* Keys should be the name of the parameter and values are treated as [[ParamDeclaration]] objects.
101-
*
102-
* #### example:
103-
* ```
104-
* params: {
105-
* folder: {
106-
* value: "index",
107-
* squash: true
108-
* }
109-
* }```
110-
*/
111-
export interface ParamsConfig { [key: string]: ParamDeclaration }
218+
interface Replace {
219+
from: string,
220+
to:string
221+
}

src/state/interface.ts

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {IPromise} from "angular";
33

44
import {UrlMatcher} from "../url/urlMatcher";
55

6-
import {RawParams, ParamsOrArray} from "../params/interface";
6+
import {ParamDeclaration, RawParams, ParamsOrArray} from "../params/interface";
77
import {Param} from "../params/param";
88

99
import {ViewContext} from "../view/interface";
@@ -17,7 +17,7 @@ import {Transition} from "../transition/transition";
1717
export type StateOrName = (string|StateDeclaration|State);
1818

1919
/**
20-
* @internal
20+
* @hidden
2121
* Internal Context obj, State-view definition, transition params
2222
*/
2323
export interface StateViewConfig {
@@ -141,15 +141,6 @@ export interface ViewDeclaration {
141141
templateProvider?: Function;
142142
}
143143

144-
/**
145-
* Configuration for a single state parameter
146-
*/
147-
interface ParamDeclaration {
148-
value: any;
149-
squash: (boolean|string);
150-
array: boolean;
151-
}
152-
153144
/**
154145
* The StateDeclaration object is used to define a state or nested state.
155146
* It should be registered with the [[$stateProvider]].

0 commit comments

Comments
 (0)