From 556a489657e82b64f0fb9543c7139f81a77176de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Richard=20V=C5=A1iansk=C3=BD?= Date: Fri, 1 Sep 2023 15:58:07 +0200 Subject: [PATCH] fix(renderer): fix stringify --- .../react-form-renderer/src/common/helpers.js | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/react-form-renderer/src/common/helpers.js b/packages/react-form-renderer/src/common/helpers.js index a4d4b49bc..aefd8b25e 100644 --- a/packages/react-form-renderer/src/common/helpers.js +++ b/packages/react-form-renderer/src/common/helpers.js @@ -7,22 +7,28 @@ export const TO_STRING = {}.toString; const isObject = (obj) => typeof obj === 'object' && TO_STRING.call(obj) === '[object Object]' && obj !== null; -const stringify = (args) => { - let arr = []; - let value; - let options = args; - if (typeof options === 'number') { - options = options.toString(); +const stringify = (value) => { + if (value === null) { + return 'null'; } - for (let k in options) { - if (HAS_PROP.call(options, k)) { - value = options[k]; - arr.push(k, isValidElement(value) ? stringify(value.props) : isObject(value) ? stringify(value) : value.toString()); - } + if (typeof value === 'boolean') { + return value ? 'true' : 'false'; + } + + if (!value) { + return ''; + } + + if (typeof value === 'string') { + return value; + } + + if (typeof value === 'number') { + return value.toString(); } - return JSON.stringify(arr); + return JSON.stringify(value); }; export const memoize = (func) => { @@ -31,7 +37,7 @@ export const memoize = (func) => { } return (value, allValues, ...options) => { - const key = stringify(value, allValues); + const key = stringify(allValues); return HAS_PROP.call(func.cache, key) ? func.cache[key] : (func.cache[key] = func(value, allValues, ...options)); }; };