fix: small fixes for view engine

This commit is contained in:
Tobias Bosch 2017-02-23 11:33:59 -08:00 committed by Igor Minar
parent e8d2743cfb
commit 6277f16187
4 changed files with 17 additions and 12 deletions

View File

@ -92,8 +92,9 @@ const ALLOW_DEFAULT_VAR = o.variable(`allowDefault`);
class ViewBuilder implements TemplateAstVisitor, LocalResolver, BuiltinConverterFactory {
private compType: o.Type;
private nodeDefs: (() => o.Expression)[] = [];
private purePipeNodeIndices: {[pipeName: string]: number} = {};
private refNodeIndices: {[refName: string]: number} = {};
private purePipeNodeIndices: {[pipeName: string]: number} = Object.create(null);
// Need Object.create so that we don't have builtin values...
private refNodeIndices: {[refName: string]: number} = Object.create(null);
private variables: VariableAst[] = [];
private children: ViewBuilder[] = [];
private updateDirectivesExpressions: UpdateExpression[] = [];
@ -929,7 +930,7 @@ function elementBindingDefs(
function fixedAttrsDef(elementAst: ElementAst): o.Expression {
const mapResult: {[key: string]: string} = {};
const mapResult: {[key: string]: string} = Object.create(null);
elementAst.attrs.forEach(attrAst => { mapResult[attrAst.name] = attrAst.value; });
elementAst.directives.forEach(dirAst => {
Object.keys(dirAst.directive.hostAttributes).forEach(name => {

View File

@ -232,8 +232,8 @@ export function createTemplateRef(view: ViewData, def: NodeDef): TemplateRef<any
return new TemplateRef_(view, def);
}
class TemplateRef_ implements TemplateRef<any> {
constructor(private _parentView: ViewData, private _def: NodeDef) {}
class TemplateRef_ extends TemplateRef<any> {
constructor(private _parentView: ViewData, private _def: NodeDef) { super(); }
createEmbeddedView(context: any): EmbeddedViewRef<any> {
return new ViewRef_(Services.createEmbeddedView(this._parentView, this._def, context));

View File

@ -243,7 +243,12 @@ function debugCheckAndUpdateNode(
} else {
// a regular element.
for (let attr in bindingValues) {
view.renderer.setAttribute(el, attr, bindingValues[attr]);
const value = bindingValues[attr];
if (value != null) {
view.renderer.setAttribute(el, attr, value);
} else {
view.renderer.removeAttribute(el, attr);
}
}
}
}
@ -270,7 +275,7 @@ function camelCaseToDashCase(input: string): string {
function normalizeDebugBindingValue(value: any): string {
try {
// Limit the size of the value as otherwise the DOM just gets polluted.
return value ? value.toString().slice(0, 20) : value;
return value ? value.toString().slice(0, 30) : value;
} catch (e) {
return '[ERROR] Exception while trying to serialize the value';
}

View File

@ -176,11 +176,10 @@ export function splitMatchedQueriesDsl(matchedQueriesDsl: [string | number, Quer
export function getParentRenderElement(view: ViewData, renderHost: any, def: NodeDef): any {
let renderParent = def.renderParent;
if (renderParent) {
const parent = def.parent;
if (parent &&
(parent.type !== NodeType.Element || (parent.flags & NodeFlags.HasComponent) === 0 ||
(parent.element.componentRendererType &&
parent.element.componentRendererType.encapsulation === ViewEncapsulation.Native))) {
if (renderParent.type !== NodeType.Element ||
(renderParent.flags & NodeFlags.HasComponent) === 0 ||
(renderParent.element.componentRendererType &&
renderParent.element.componentRendererType.encapsulation === ViewEncapsulation.Native)) {
// only children of non components, or children of components with native encapsulation should
// be attached.
return asElementData(view, def.renderParent.index).renderElement;