@@ -32,8 +32,9 @@ import {Globals} from "../globals";
32
32
import { UIInjector } from "../interface" ;
33
33
import { RawParams } from "../params/interface" ;
34
34
35
-
35
+ /** @hidden */
36
36
let transitionCount = 0 ;
37
+ /** @hidden */
37
38
const stateSelf : ( _state : State ) => StateDeclaration = prop ( "self" ) ;
38
39
39
40
/**
@@ -45,8 +46,15 @@ const stateSelf: (_state: State) => StateDeclaration = prop("self");
45
46
* It has information about all states being entered and exited as a result of the transition.
46
47
*/
47
48
export class Transition implements IHookRegistry {
49
+
50
+ /** @hidden */
48
51
static diToken = Transition ;
49
-
52
+
53
+ /**
54
+ * A unique identifier for the transition.
55
+ *
56
+ * This is an auto incrementing integer, starting from `0`.
57
+ */
50
58
$id : number ;
51
59
52
60
/**
@@ -75,8 +83,11 @@ export class Transition implements IHookRegistry {
75
83
/** @hidden */
76
84
private _error : any ;
77
85
86
+ /** @hidden */
78
87
private _options : TransitionOptions ;
88
+ /** @hidden */
79
89
private _treeChanges : TreeChanges ;
90
+ /** @hidden */
80
91
private _targetState : TargetState ;
81
92
82
93
/** @inheritdoc */
@@ -103,6 +114,8 @@ export class Transition implements IHookRegistry {
103
114
*
104
115
* If the target state is not valid, an error is thrown.
105
116
*
117
+ * @internalapi
118
+ *
106
119
* @param fromPath The path of [[PathNode]]s from which the transition is leaving. The last node in the `fromPath`
107
120
* encapsulates the "from state".
108
121
* @param targetState The target state and parameters being transitioned to (also, the transition options)
@@ -139,18 +152,30 @@ export class Transition implements IHookRegistry {
139
152
context . addResolvables ( rootResolvables , rootNode . state ) ;
140
153
}
141
154
155
+ /**
156
+ * @internalapi
157
+ *
158
+ * @returns the internal from [State] object
159
+ */
142
160
$from ( ) {
143
161
return tail ( this . _treeChanges . from ) . state ;
144
162
}
145
163
164
+ /**
165
+ * @internalapi
166
+ *
167
+ * @returns the internal to [State] object
168
+ */
146
169
$to ( ) {
147
170
return tail ( this . _treeChanges . to ) . state ;
148
171
}
149
172
150
173
/**
151
174
* Returns the "from state"
152
175
*
153
- * @returns The state object for the Transition's "from state".
176
+ * Returns the state that the transition is coming *from*.
177
+ *
178
+ * @returns The state declaration object for the Transition's ("from state").
154
179
*/
155
180
from ( ) : StateDeclaration {
156
181
return this . $from ( ) . self ;
@@ -159,7 +184,9 @@ export class Transition implements IHookRegistry {
159
184
/**
160
185
* Returns the "to state"
161
186
*
162
- * @returns The state object for the Transition's target state ("to state").
187
+ * Returns the state that the transition is going *from*.
188
+ *
189
+ * @returns The state declaration object for the Transition's target state ("to state").
163
190
*/
164
191
to ( ) {
165
192
return this . $to ( ) . self ;
@@ -168,7 +195,7 @@ export class Transition implements IHookRegistry {
168
195
/**
169
196
* Gets the Target State
170
197
*
171
- * A transition's [[TargetState]] encapsulates the [[to]] state, the [[params]], and the [[options]].
198
+ * A transition's [[TargetState]] encapsulates the [[to]] state, the [[params]], and the [[options]] as a single object .
172
199
*
173
200
* @returns the [[TargetState]] of this Transition
174
201
*/
@@ -193,8 +220,14 @@ export class Transition implements IHookRegistry {
193
220
/**
194
221
* Gets transition parameter values
195
222
*
196
- * @param pathname Pick which treeChanges path to get parameters for:
223
+ * Returns the parameter values for a transition as key/value pairs.
224
+ *
225
+ * By default, returns the new parameter values (for the "to state").
226
+ * To return the previous parameter values, supply `'from'` as the `pathname` argument.
227
+ *
228
+ * @param pathname the name of the treeChanges path to get parameter values for:
197
229
* (`'to'`, `'from'`, `'entering'`, `'exiting'`, `'retained'`)
230
+ *
198
231
* @returns transition parameter values for the desired path.
199
232
*/
200
233
params ( pathname : string = "to" ) : { [ key : string ] : any } {
@@ -216,7 +249,7 @@ export class Transition implements IHookRegistry {
216
249
* @returns a [[UIInjector]]
217
250
*/
218
251
injector ( state ?: StateOrName ) : UIInjector {
219
- let path : PathNode [ ] = this . treeChanges ( ) . to ;
252
+ let path : PathNode [ ] = this . _treeChanges . to ;
220
253
if ( state ) path = PathFactory . subPath ( path , node => node . state === state || node . state . name === state ) ;
221
254
return new ResolveContext ( path ) . injector ( ) ;
222
255
}
@@ -230,10 +263,12 @@ export class Transition implements IHookRegistry {
230
263
* The returned tokens include those defined on [[StateDeclaration.resolve]] blocks, for the states
231
264
* in the Transition's [[TreeChanges.to]] path.
232
265
*
266
+ * @param pathname resolve context's path name (e.g., `to` or `from`)
267
+ *
233
268
* @returns an array of resolve tokens (keys)
234
269
*/
235
- getResolveTokens ( ) : any [ ] {
236
- return new ResolveContext ( this . _treeChanges . to ) . getTokens ( ) ;
270
+ getResolveTokens ( pathname : string = "to" ) : any [ ] {
271
+ return new ResolveContext ( this . _treeChanges [ pathname ] ) . getTokens ( ) ;
237
272
}
238
273
239
274
@@ -250,11 +285,14 @@ export class Transition implements IHookRegistry {
250
285
* If a resolvable doesn't exist for the token, throws an error.
251
286
*
252
287
* @param token the token (or array of tokens)
288
+ * @param pathname resolve context's path name (e.g., `to` or `from`)
253
289
*
254
290
* @returns an array of resolve tokens (keys)
255
291
*/
256
- getResolveValue ( token : ( any | any [ ] ) ) : ( any | any [ ] ) {
257
- let resolveContext = new ResolveContext ( this . _treeChanges . to ) ;
292
+ getResolveValue ( token : any [ ] , pathname ?: string ) : any [ ] ;
293
+ getResolveValue ( token : any , pathname ?: string ) : any ;
294
+ getResolveValue ( token : ( any | any [ ] ) , pathname : string = "to" ) : ( any | any [ ] ) {
295
+ let resolveContext = new ResolveContext ( this . _treeChanges [ pathname ] ) ;
258
296
const getData = ( token : any ) => {
259
297
var resolvable = resolveContext . getResolvable ( token ) ;
260
298
if ( resolvable === undefined ) {
@@ -276,11 +314,12 @@ export class Transition implements IHookRegistry {
276
314
* This is a lower level API that returns a [[Resolvable]] from the Transition for a given token.
277
315
*
278
316
* @param token the DI token
317
+ * @param pathname resolve context's path name (e.g., `to` or `from`)
279
318
*
280
319
* @returns the [[Resolvable]] in the transition's to path, or undefined
281
320
*/
282
- getResolvable ( token : any ) : Resolvable {
283
- return new ResolveContext ( this . _treeChanges . to ) . getResolvable ( token ) ;
321
+ getResolvable ( token : any , pathname = "to" ) : Resolvable {
322
+ return new ResolveContext ( this . _treeChanges [ pathname ] ) . getResolvable ( token ) ;
284
323
}
285
324
286
325
/**
@@ -374,23 +413,41 @@ export class Transition implements IHookRegistry {
374
413
return path . map ( prop ( "views" ) ) . filter ( identity ) . reduce ( unnestR , [ ] ) ;
375
414
}
376
415
377
- treeChanges = ( ) => this . _treeChanges ;
416
+ /**
417
+ * Return the transition's tree changes
418
+ *
419
+ * A transition goes from one state/parameters to another state/parameters.
420
+ * During a transition, states are entered and/or exited.
421
+ *
422
+ * This function returns various branches (paths) which represent the changes to the
423
+ * active state tree that are caused by the transition.
424
+ *
425
+ * @param pathname The name of the tree changes path to get:
426
+ * (`'to'`, `'from'`, `'entering'`, `'exiting'`, `'retained'`)
427
+ */
428
+ treeChanges ( pathname : string ) : PathNode [ ] ;
429
+ treeChanges ( ) : TreeChanges ;
430
+ treeChanges ( pathname ?: string ) {
431
+ return pathname ? this . _treeChanges [ pathname ] : this . _treeChanges ;
432
+ }
378
433
379
434
/**
380
435
* Creates a new transition that is a redirection of the current one.
381
436
*
382
437
* This transition can be returned from a [[TransitionService]] hook to
383
438
* redirect a transition to a new state and/or set of parameters.
384
439
*
440
+ * @internalapi
441
+ *
385
442
* @returns Returns a new [[Transition]] instance.
386
443
*/
387
444
redirect ( targetState : TargetState ) : Transition {
388
445
let newOptions = extend ( { } , this . options ( ) , targetState . options ( ) , { redirectedFrom : this , source : "redirect" } ) ;
389
446
targetState = new TargetState ( targetState . identifier ( ) , targetState . $state ( ) , targetState . params ( ) , newOptions ) ;
390
447
391
448
let newTransition = this . router . transitionService . create ( this . _treeChanges . from , targetState ) ;
392
- let originalEnteringNodes = this . treeChanges ( ) . entering ;
393
- let redirectEnteringNodes = newTransition . treeChanges ( ) . entering ;
449
+ let originalEnteringNodes = this . _treeChanges . entering ;
450
+ let redirectEnteringNodes = newTransition . _treeChanges . entering ;
394
451
395
452
// --- Re-use resolve data from original transition ---
396
453
// When redirecting from a parent state to a child state where the parent parameter values haven't changed
@@ -469,6 +526,8 @@ export class Transition implements IHookRegistry {
469
526
*
470
527
* This method is generally called from the [[StateService.transitionTo]]
471
528
*
529
+ * @internalapi
530
+ *
472
531
* @returns a promise for a successful transition.
473
532
*/
474
533
run ( ) : Promise < any > {
@@ -529,6 +588,9 @@ export class Transition implements IHookRegistry {
529
588
return this . promise ;
530
589
}
531
590
591
+ /**
592
+ * Checks if this transition is currently active/running.
593
+ */
532
594
isActive = ( ) => this === this . _options . current ( ) ;
533
595
534
596
/**
0 commit comments