From 95ada942d0d4f1be83fc3b8d0285b2d89bca0f1d Mon Sep 17 00:00:00 2001 From: Vincent Fretin Date: Sun, 1 Sep 2024 10:03:40 +0200 Subject: [PATCH] fix export of visible false --- src/json-utils_1.1.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/json-utils_1.1.js b/src/json-utils_1.1.js index 90c7b240..fd9e35a0 100644 --- a/src/json-utils_1.1.js +++ b/src/json-utils_1.1.js @@ -113,8 +113,8 @@ function getAttributes(entity) { elemObj['components'] = {}; for (const componentName in entityComponents) { const modifiedProperty = getModifiedProperty(entity, componentName); - if (modifiedProperty) { - if (isEmpty(modifiedProperty)) { + if (modifiedProperty !== null) { + if (isEmptyObject(modifiedProperty)) { elemObj['components'][componentName] = ''; } else { elemObj['components'][componentName] = toPropString(modifiedProperty); @@ -168,8 +168,13 @@ function isSingleProperty(schema) { return AFRAME.schema.isSingleProperty(schema); } -function isEmpty(object) { - return Object.keys(object).length === 0; +function isEmptyObject(object) { + return ( + typeof object === 'object' && + !Array.isArray(object) && + object !== null && + Object.keys(object).length === 0 + ); } // a list of component:value pairs to exclude from the JSON string. @@ -201,7 +206,7 @@ function filterJSONstreet(streetJSON) { compAttributes = AFRAME.utils.styleParser.parse(value); const removeVal = removeProps[removeKey]; // check for deleting component's attribute - if (typeof removeVal === 'object' && !isEmpty(removeVal)) { + if (!isEmptyObject(removeVal)) { // remove attribute in component const attrNames = Object.keys(removeVal); for (var attrName of attrNames) {