From d5213faf668688d7cf68c27bb4106d60ecbafdfc Mon Sep 17 00:00:00 2001 From: khlevon98 Date: Tue, 21 May 2019 19:23:27 +0400 Subject: [PATCH] fixed setAttribute/removeAttribute logic for use AFRAME components with empty data --- src/index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 5bcfeb8..d9037e4 100644 --- a/src/index.js +++ b/src/index.js @@ -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); } } @@ -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); } } } }