Skip to content

Commit

Permalink
fixed setAttribute/removeAttribute logic for use AFRAME components wi…
Browse files Browse the repository at this point in the history
…th empty data
  • Loading branch information
khlevon committed May 21, 2019
1 parent b5c064a commit d5213fa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ function doSetAttribute (el, props, propName) {
} else if (props[propName] && props[propName].constructor === Function) {
return;
} else {
el.setAttribute(propName, props[propName]);
let val = props[propName];
if(val === undefined || val === null){
val = "";
}
el.setAttribute(propName, val);
}
}

Expand All @@ -45,7 +49,7 @@ function updateAttributes (el, prevProps, props) {
if (prevProps) {
for (propName in prevProps) {
if (!filterNonEntityPropNames(propName)) { continue; }
if (props[propName] === undefined) { el.removeAttribute(propName); }
if (Object.keys(props).indexOf(propName) === -1) { el.removeAttribute(propName); }
}
}
}
Expand Down

0 comments on commit d5213fa

Please sign in to comment.