Skip to content

Commit

Permalink
[wip] fix prop normalization
Browse files Browse the repository at this point in the history
This (along with some changes to Ember that I will also PR) solves emberjs/ember.js#16311 and emberjs/ember.js#16477

This is not ready to go yet because I'm also going to refactor so we don't compute the normalized property name twice.
  • Loading branch information
ef4 committed Apr 21, 2018
1 parent 213c3a3 commit 933a3a9
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/@glimmer/runtime/lib/vm/attributes/dynamic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,27 @@ export class SimpleDynamicAttribute extends DynamicAttribute {
}

export class DefaultDynamicProperty extends DynamicAttribute {
private normalizedName: string;

constructor(attribute: Attribute) {
super(attribute);
let { element, name } = this.attribute;
this.normalizedName = normalizeProperty(element, name).normalized;
}

value: Opaque;
set(dom: ElementBuilder, value: Opaque, _env: Environment): void {
if (value !== null && value !== undefined) {
let { name } = this.attribute;
this.value = value;
dom.__setProperty(name, value);
dom.__setProperty(this.normalizedName, value);
}
}

update(value: Opaque, _env: Environment): void {
let { element, name } = this.attribute;
let { element } = this.attribute;

if (this.value !== value) {
element[name] = this.value = value;
element[this.normalizedName] = this.value = value;

if (value === null || value === undefined) {
this.removeAttribute();
Expand All @@ -106,12 +113,12 @@ export class DefaultDynamicProperty extends DynamicAttribute {
protected removeAttribute() {
// TODO this sucks but to preserve properties first and to meet current
// semantics we must do this.
let { element, name, namespace } = this.attribute;
let { element, namespace } = this.attribute;

if (namespace) {
element.removeAttributeNS(namespace, name);
element.removeAttributeNS(namespace, this.normalizedName);
} else {
element.removeAttribute(name);
element.removeAttribute(this.normalizedName);
}
}
}
Expand Down

0 comments on commit 933a3a9

Please sign in to comment.