0
0
mirror of https://github.com/sveltejs/svelte.git synced 2024-11-30 00:46:29 +01:00

Remove an undefined attribute instead of setting it to "undefined" (string)

This commit is contained in:
Christian Kaisermann 2018-08-20 22:39:32 -03:00
parent 9eec6f8c72
commit 790f2b5313
3 changed files with 23 additions and 4 deletions

View File

@ -82,7 +82,8 @@ export function removeListener(node, event, handler) {
}
export function setAttribute(node, attribute, value) {
node.setAttribute(attribute, value);
if (value === undefined) removeAttribute(node, attribute);
else node.setAttribute(attribute, value);
}
export function setAttributes(node, attributes) {
@ -90,8 +91,7 @@ export function setAttributes(node, attributes) {
if (key in node) {
node[key] = attributes[key];
} else {
if (attributes[key] === undefined) removeAttribute(node, key);
else setAttribute(node, key, attributes[key]);
setAttribute(node, key, attributes[key]);
}
}
}

View File

@ -0,0 +1,5 @@
export default {
'skip-ssr': true,
html: '<div></div>'
};

View File

@ -0,0 +1,14 @@
<div {foo} {bar}></div>
<script>
export default {
data: () => ({
foo: 1,
bar: undefined
}),
oncreate () {
this.set({ foo: undefined });
}
};
</script>