@@ -81,6 +81,10 @@ export enum Category {
81
81
RESOLVE , TRANSITION , HOOK , UIVIEW , VIEWCONFIG
82
82
}
83
83
84
+ /** @hidden */ const _tid = parse ( "$id" ) ;
85
+ /** @hidden */ const _rid = parse ( "router.$id" ) ;
86
+ /** @hidden */ const transLbl = ( trans ) => `Transition #${ _tid ( trans ) } -${ _rid ( trans ) } ` ;
87
+
84
88
/**
85
89
* Prints UI-Router Transition trace information to the console.
86
90
*/
@@ -146,77 +150,52 @@ export class Trace {
146
150
/** @internalapi called by ui-router code */
147
151
traceTransitionStart ( trans : Transition ) {
148
152
if ( ! this . enabled ( Category . TRANSITION ) ) return ;
149
- let tid = trans . $id ,
150
- digest = this . approximateDigests ,
151
- transitionStr = stringify ( trans ) ;
152
- console . log ( `Transition #${ tid } r${ trans . router . $id } : Started -> ${ transitionStr } ` ) ;
153
+ console . log ( `${ transLbl ( trans ) } : Started -> ${ stringify ( trans ) } ` ) ;
153
154
}
154
155
155
156
/** @internalapi called by ui-router code */
156
157
traceTransitionIgnored ( trans : Transition ) {
157
158
if ( ! this . enabled ( Category . TRANSITION ) ) return ;
158
- let tid = trans && trans . $id ,
159
- digest = this . approximateDigests ,
160
- transitionStr = stringify ( trans ) ;
161
- console . log ( `Transition #${ tid } r${ trans . router . $id } : Ignored <> ${ transitionStr } ` ) ;
159
+ console . log ( `${ transLbl ( trans ) } : Ignored <> ${ stringify ( trans ) } ` ) ;
162
160
}
163
161
164
162
/** @internalapi called by ui-router code */
165
163
traceHookInvocation ( step : TransitionHook , trans : Transition , options : any ) {
166
164
if ( ! this . enabled ( Category . HOOK ) ) return ;
167
- let tid = parse ( "transition.$id" ) ( options ) ,
168
- digest = this . approximateDigests ,
169
- event = parse ( "traceData.hookType" ) ( options ) || "internal" ,
165
+ let event = parse ( "traceData.hookType" ) ( options ) || "internal" ,
170
166
context = parse ( "traceData.context.state.name" ) ( options ) || parse ( "traceData.context" ) ( options ) || "unknown" ,
171
167
name = functionToString ( ( step as any ) . registeredHook . callback ) ;
172
- console . log ( `Transition # ${ tid } r ${ trans . router . $id } : Hook -> ${ event } context: ${ context } , ${ maxLength ( 200 , name ) } ` ) ;
168
+ console . log ( `${ transLbl ( trans ) } : Hook -> ${ event } context: ${ context } , ${ maxLength ( 200 , name ) } ` ) ;
173
169
}
174
170
175
171
/** @internalapi called by ui-router code */
176
172
traceHookResult ( hookResult : HookResult , trans : Transition , transitionOptions : any ) {
177
173
if ( ! this . enabled ( Category . HOOK ) ) return ;
178
- let tid = parse ( "transition.$id" ) ( transitionOptions ) ,
179
- digest = this . approximateDigests ,
180
- hookResultStr = stringify ( hookResult ) ;
181
- console . log ( `Transition #${ tid } r${ trans . router . $id } : <- Hook returned: ${ maxLength ( 200 , hookResultStr ) } ` ) ;
174
+ console . log ( `${ transLbl ( trans ) } : <- Hook returned: ${ maxLength ( 200 , stringify ( hookResult ) ) } ` ) ;
182
175
}
183
176
184
177
/** @internalapi called by ui-router code */
185
178
traceResolvePath ( path : PathNode [ ] , when : PolicyWhen , trans ?: Transition ) {
186
179
if ( ! this . enabled ( Category . RESOLVE ) ) return ;
187
- let tid = trans && trans . $id ,
188
- digest = this . approximateDigests ,
189
- pathStr = path && path . toString ( ) ;
190
- console . log ( `Transition #${ tid } r${ trans . router . $id } : Resolving ${ pathStr } (${ when } )` ) ;
180
+ console . log ( `${ transLbl ( trans ) } : Resolving ${ path } (${ when } )` ) ;
191
181
}
192
182
193
183
/** @internalapi called by ui-router code */
194
184
traceResolvableResolved ( resolvable : Resolvable , trans ?: Transition ) {
195
185
if ( ! this . enabled ( Category . RESOLVE ) ) return ;
196
- let tid = trans && trans . $id ,
197
- digest = this . approximateDigests ,
198
- resolvableStr = resolvable && resolvable . toString ( ) ,
199
- result = stringify ( resolvable . data ) ;
200
- console . log ( `Transition #${ tid } r${ trans . router . $id } : <- Resolved ${ resolvableStr } to: ${ maxLength ( 200 , result ) } ` ) ;
186
+ console . log ( `${ transLbl ( trans ) } : <- Resolved ${ resolvable } to: ${ maxLength ( 200 , stringify ( resolvable . data ) ) } ` ) ;
201
187
}
202
188
203
189
/** @internalapi called by ui-router code */
204
190
traceError ( reason : any , trans : Transition ) {
205
191
if ( ! this . enabled ( Category . TRANSITION ) ) return ;
206
- let tid = trans && trans . $id ,
207
- digest = this . approximateDigests ,
208
- transitionStr = stringify ( trans ) ;
209
- console . log ( `Transition #${ tid } r${ trans . router . $id } : <- Rejected ${ transitionStr } , reason: ${ reason } ` ) ;
192
+ console . log ( `${ transLbl ( trans ) } : <- Rejected ${ stringify ( trans ) } , reason: ${ reason } ` ) ;
210
193
}
211
194
212
195
/** @internalapi called by ui-router code */
213
196
traceSuccess ( finalState : State , trans : Transition ) {
214
197
if ( ! this . enabled ( Category . TRANSITION ) ) return ;
215
- let tid = trans && trans . $id ,
216
- digest = this . approximateDigests ,
217
- state = finalState . name ,
218
- transitionStr = stringify ( trans ) ;
219
- console . log ( `Transition #${ tid } r${ trans . router . $id } : <- Success ${ transitionStr } , final state: ${ state } ` ) ;
198
+ console . log ( `${ transLbl ( trans ) } : <- Success ${ stringify ( trans ) } , final state: ${ finalState . name } ` ) ;
220
199
}
221
200
222
201
/** @internalapi called by ui-router code */
0 commit comments