Skip to content

Commit

Permalink
[BUGFIX release] add template to debug render tree
Browse files Browse the repository at this point in the history
  • Loading branch information
chancancode committed Nov 15, 2019
1 parent 30dfff0 commit e1b945b
Show file tree
Hide file tree
Showing 10 changed files with 196 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,15 @@ export default class CurlyComponentManager
return factory(owner);
}

getDynamicLayout({ component }: ComponentStateBucket): Invocation {
getDynamicLayout(bucket: ComponentStateBucket): Invocation {
let component = bucket.component;
let template = this.templateFor(component);
let layout = template.asWrappedLayout();

if (ENV._DEBUG_RENDER_TREE) {
bucket.environment.debugRenderTree.setTemplate(bucket, template);
}

return {
handle: layout.compile(),
symbolTable: layout.symbolTable,
Expand Down Expand Up @@ -348,6 +353,7 @@ export default class CurlyComponentManager
name: state.name,
args: args.capture(),
instance: component,
template: state.template,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export default class CustomComponentManager<ComponentInstance>
name: definition.name,
args: args.capture(),
instance: component,
template: definition.template,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class InputComponentManager extends InternalComponentManager<Inpu

create(
env: Environment,
{ ComponentClass }: InternalDefinitionState,
{ ComponentClass, layout }: InternalDefinitionState,
args: Arguments,
_dynamicScope: DynamicScope,
caller: VersionedPathReference
Expand All @@ -79,6 +79,7 @@ export default class InputComponentManager extends InternalComponentManager<Inpu
name: 'input',
args: args.capture(),
instance,
template: layout,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ class MountManager extends AbstractManager<EngineState, EngineDefinitionState>
let template = templateFactory(state.engine);
let layout = template.asLayout();

if (ENV._DEBUG_RENDER_TREE) {
state.environment.debugRenderTree.setTemplate(state.controller, template);
}

return {
handle: layout.compile(),
symbolTable: layout.symbolTable,
Expand Down Expand Up @@ -117,13 +121,16 @@ class MountManager extends AbstractManager<EngineState, EngineDefinitionState>
name,
args: args.capture(),
instance: engine,
template: undefined,
});

environment.debugRenderTree.create(controller, {
type: 'route-template',
name: 'application',
args: args.capture(),
instance: controller,
// set in getDynamicLayout
template: undefined,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class OutletComponentManager extends AbstractManager<OutletInstanceState, Outlet
name: state.outlet.name,
args: EMPTY_ARGS,
instance: undefined,
template: undefined,
});

let parentState = parentStateRef.value();
Expand All @@ -120,6 +121,7 @@ class OutletComponentManager extends AbstractManager<OutletInstanceState, Outlet
name: mountPoint,
args: EMPTY_ARGS,
instance: engine,
template: undefined,
});
}

Expand All @@ -128,6 +130,7 @@ class OutletComponentManager extends AbstractManager<OutletInstanceState, Outlet
name: definition.name,
args: args.capture(),
instance: definition.controller,
template: definition.template,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class RootComponentManager extends CurlyComponentManager {
name: state.name,
args: EMPTY_ARGS,
instance: component,
template: state.template,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default class TemplateOnlyComponentManager

create(
environment: Environment,
{ name }: TemplateOnlyComponentDefinitionState,
{ name, template }: TemplateOnlyComponentDefinitionState,
args: Arguments
): Option<DebugStateBucket> {
if (ENV._DEBUG_RENDER_TREE) {
Expand All @@ -65,6 +65,7 @@ export default class TemplateOnlyComponentManager
name: name,
args: args.capture(),
instance: null,
template,
});
return bucket;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { assert } from '@ember/debug';
import { Simple } from '@glimmer/interfaces';
import { Bounds, CapturedArguments } from '@glimmer/runtime';
import { expect, Option, Stack } from '@glimmer/util';
import { OwnedTemplate } from '../template';

export type RenderNodeType = 'outlet' | 'engine' | 'route-template' | 'component';

Expand All @@ -10,6 +11,7 @@ export interface RenderNode {
name: string;
args: CapturedArguments;
instance: unknown;
template?: OwnedTemplate;
}

interface InternalRenderNode<T extends object> extends RenderNode {
Expand All @@ -23,6 +25,7 @@ export interface CapturedRenderNode {
name: string;
args: ReturnType<CapturedArguments['value']>;
instance: unknown;
template: Option<string>;
bounds: Option<{
parentElement: Simple.Element;
firstNode: Simple.Node;
Expand Down Expand Up @@ -90,6 +93,11 @@ export default class DebugRenderTree<Bucket extends object = object> {
this.enter(state);
}

// for dynamic layouts
setTemplate(state: Bucket, template: OwnedTemplate): void {
this.nodeFor(state).template = template;
}

didRender(state: Bucket, bounds: Bounds): void {
assert(`BUG: expecting ${this.stack.current}, got ${state}`, this.stack.current === state);
this.nodeFor(state).bounds = bounds;
Expand Down Expand Up @@ -170,9 +178,14 @@ export default class DebugRenderTree<Bucket extends object = object> {
private captureNode(id: string, state: Bucket): CapturedRenderNode {
let node = this.nodeFor(state);
let { type, name, args, instance, refs } = node;
let template = this.captureTemplate(node);
let bounds = this.captureBounds(node);
let children = this.captureRefs(refs);
return { id, type, name, args: args.value(), instance, bounds, children };
return { id, type, name, args: args.value(), instance, template, bounds, children };
}

private captureTemplate({ template }: InternalRenderNode<Bucket>): Option<string> {
return (template && template.referrer.moduleName) || null;
}

private captureBounds(node: InternalRenderNode<Bucket>): CapturedRenderNode['bounds'] {
Expand Down
Loading

0 comments on commit e1b945b

Please sign in to comment.