Skip to content

Commit 284392d

Browse files
feat(trace): Trace view synchronization. Allow trace.enable(...string)
- Allow trace.enable(...number)
1 parent c48da4a commit 284392d

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

src/common/trace.ts

+28-12
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,18 @@ import {HookResult} from "../transition/interface";
4646
import {StateObject} from "../state/stateObject";
4747

4848
/** @hidden */
49-
function uiViewString (viewData: ActiveUIView) {
50-
if (!viewData) return 'ui-view (defunct)';
51-
return `[ui-view#${viewData.id} tag ` +
52-
`in template from '${viewData.creationContext && viewData.creationContext.name || '(root)'}' state]: ` +
53-
`fqn: '${viewData.fqn}', ` +
54-
`name: '${viewData.name}@${viewData.creationContext}')`;
49+
function uiViewString (uiview: ActiveUIView) {
50+
if (!uiview) return 'ui-view (defunct)';
51+
const state = uiview.creationContext ? uiview.creationContext.name || '(root)' : '(none)';
52+
return `[ui-view#${uiview.id} ${uiview.$type}:${uiview.fqn} (${uiview.name}@${state})]`;
5553
}
5654

5755
/** @hidden */
58-
const viewConfigString = (viewConfig: ViewConfig) =>
59-
`[ViewConfig#${viewConfig.$id} from '${viewConfig.viewDecl.$context.name || '(root)'}' state]: target ui-view: '${viewConfig.viewDecl.$uiViewName}@${viewConfig.viewDecl.$uiViewContextAnchor}'`;
56+
const viewConfigString = (viewConfig: ViewConfig) => {
57+
let view = viewConfig.viewDecl;
58+
const state = view.$context.name || '(root)';
59+
return `[View#${viewConfig.$id} from '${state}' state]: target ui-view: '${view.$uiViewName}@${view.$uiViewContextAnchor}'`;
60+
};
6061

6162
/** @hidden */
6263
function normalizedCat(input: Category|string): string {
@@ -78,7 +79,7 @@ function normalizedCat(input: Category|string): string {
7879
* `trace.enable(1)`
7980
*/
8081
export enum Category {
81-
RESOLVE, TRANSITION, HOOK, UIVIEW, VIEWCONFIG
82+
RESOLVE, TRANSITION, HOOK, UIVIEW, VIEWCONFIG,
8283
}
8384

8485
/** @hidden */ const _tid = parse("$id");
@@ -121,7 +122,8 @@ export class Trace {
121122
* @param categories categories to enable. If `categories` is omitted, all categories are enabled.
122123
* Also takes strings (category name) or ordinal (category position)
123124
*/
124-
enable(...categories: Category[]) { this._set(true, categories) }
125+
enable(...categories: (Category|string|number)[]);
126+
enable(...categories: any[]) { this._set(true, categories); }
125127
/**
126128
* Disables a trace [[Category]]
127129
*
@@ -132,7 +134,8 @@ export class Trace {
132134
* @param categories categories to disable. If `categories` is omitted, all categories are disabled.
133135
* Also takes strings (category name) or ordinal (category position)
134136
*/
135-
disable(...categories: Category[]) { this._set(false, categories) }
137+
disable(...categories: (Category|string|number)[]);
138+
disable(...categories: any[]) { this._set(false, categories); }
136139

137140
/**
138141
* Retrieves the enabled stateus of a [[Category]]
@@ -143,7 +146,7 @@ export class Trace {
143146
*
144147
* @returns boolean true if the category is enabled
145148
*/
146-
enabled(category: Category): boolean {
149+
enabled(category: (Category|string|number)): boolean {
147150
return !!this._enabled[normalizedCat(category)];
148151
}
149152

@@ -216,6 +219,19 @@ export class Trace {
216219
this.traceUIViewEvent("Fill", viewData, ` with: ${maxLength(200, html)}`);
217220
}
218221

222+
/** @internalapi called by ui-router code */
223+
traceViewSync(pairs: any[]) {
224+
if (!this.enabled(Category.VIEWCONFIG)) return;
225+
const mapping = pairs.map(([ uiViewData, config ]) => {
226+
const uiView = `${uiViewData.$type}:${uiViewData.fqn}`;
227+
const view = config && `${config.viewDecl.$context.name}: ${config.viewDecl.$name} (${config.viewDecl.$type})`;
228+
229+
return { 'ui-view fqn': uiView, 'state: view name': view };
230+
}).sort((a, b) => a['ui-view fqn'].localeCompare(b['ui-view fqn']));
231+
232+
console.table(mapping);
233+
}
234+
219235
/** @internalapi called by ui-router code */
220236
traceViewServiceEvent(event: string, viewConfig: ViewConfig) {
221237
if (!this.enabled(Category.VIEWCONFIG)) return;

src/view/view.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class ViewService {
161161
let fqnToFirstSegment = uivSegments.slice(0, negOffset).join(".");
162162
let uiViewContext = uiViewsByFqn[fqnToFirstSegment].creationContext;
163163
return vc.$uiViewContextAnchor === (uiViewContext && uiViewContext.name);
164-
};
164+
}
165165

166166
sync() {
167167
let uiViewsByFqn: TypedMap<ActiveUIView> =
@@ -205,7 +205,11 @@ export class ViewService {
205205
};
206206

207207
// Sort views by FQN and state depth. Process uiviews nearest the root first.
208-
this._uiViews.sort(depthCompare(uiViewDepth, 1)).map(matchingConfigPair).forEach(configureUIView);
208+
const pairs = this._uiViews.sort(depthCompare(uiViewDepth, 1)).map(matchingConfigPair);
209+
210+
trace.traceViewSync(pairs);
211+
212+
pairs.forEach(configureUIView);
209213
};
210214

211215
/**

0 commit comments

Comments
 (0)