Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/plugins/events/onprops.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,12 @@ const hooks = {
// Implement onEventName attributes/properties
let change = event.detail;

if (change.oldInternalValue) {
this.removeEventListener(eventName, change.oldInternalValue);
if (change.oldValue) {
this.removeEventListener(eventName, change.oldValue);
}

if (change.parsedValue) {
this.addEventListener(eventName, change.parsedValue);
if (change.value) {
this.addEventListener(eventName, change.value);
}
}
});
Expand Down
12 changes: 7 additions & 5 deletions src/plugins/events/propchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { symbols } from "xtensible";
import base, { events } from "./base.js";
import { props } from "../props/index.js";
import PropChangeEvent from "../props/util/PropChangeEvent.js";

const { propchange } = symbols.new;

Expand Down Expand Up @@ -45,12 +46,13 @@ const hooks = {
let propName = this.constructor[propchange][eventName];
let value = this[propName];

if (value !== undefined) {
this.constructor[props].firePropChangeEvent(this, eventName, {
name: propName,
prop: this.constructor[props].get(propName),
});
if (value === undefined) {
continue;
}

let prop = this.constructor[props].get(propName);
let detail = { source: "initial", value };
this.dispatchEvent(new PropChangeEvent(eventName, { name: propName, prop, detail }));
}
},
};
Expand Down
21 changes: 10 additions & 11 deletions src/plugins/props/util/Prop.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,9 @@ let Self = class Prop {
return value;
}

set (element, value, { source, name, oldValue } = {}) {
let oldInternalValue = element.props[this.name];
set (element, value, { source, name, oldAttributeValue } = {}) {
let oldValue = element.props[this.name];

let attributeName = name;
let parsedValue;

try {
Expand All @@ -205,7 +204,7 @@ let Self = class Prop {
parsedValue = this.spec.convert.call(element, parsedValue);
}

if (this.equals(parsedValue, oldInternalValue)) {
if (this.equals(parsedValue, oldValue)) {
return;
}

Expand All @@ -214,10 +213,8 @@ let Self = class Prop {
let change = {
element,
source,
value,
parsedValue,
oldInternalValue,
attributeName: name,
value: parsedValue,
oldValue,
};

if (source === "property") {
Expand All @@ -240,9 +237,9 @@ let Self = class Prop {
}
else if (source === "attribute") {
Object.assign(change, {
attributeName,
attributeName: name,
attributeValue: value,
oldAttributeValue: oldValue,
oldAttributeValue,
});
}

Expand All @@ -254,7 +251,9 @@ let Self = class Prop {
if (element.setAttribute) {
let attributeName = change.attributeName ?? this.toAttribute;
let attributeValue =
change.attributeValue ?? change.element.getAttribute(attributeName);
change.attributeValue !== undefined
? change.attributeValue
: change.element.getAttribute(attributeName);

if (attributeValue === null) {
element.removeAttribute(attributeName);
Expand Down
6 changes: 5 additions & 1 deletion src/plugins/props/util/Props.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ export default class Props extends Map {
let propsFromAttribute = [...this.values()].filter(spec => spec.fromAttribute === name);

for (let prop of propsFromAttribute) {
prop.set(element, element.getAttribute(name), { source: "attribute", name, oldValue });
prop.set(element, element.getAttribute(name), {
source: "attribute",
name,
oldAttributeValue: oldValue,
});
}
}

Expand Down
3 changes: 1 addition & 2 deletions test/plugins/props/propchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ export default {
run () {
let { element } = this.data;
let log = [];
element.addEventListener("propchange", e =>
log.push([e.name, e.detail.parsedValue]));
element.addEventListener("propchange", e => log.push([e.name, e.detail.value]));

element.v = "foo";
element.v = "bar";
Expand Down