From 695781c14915dbc104e7e648c656839e0c7f7604 Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Wed, 12 Feb 2020 15:10:27 +0000 Subject: [PATCH] move state origin build from server to client --- .../src/builderStore/buildStateOrigins.js | 27 +++++++++++++++ .../src/userInterface/PropertyCascader.svelte | 5 +-- .../builder/tests/buildStateOrigins.spec.js | 29 ++++++++++++++++ packages/server/utilities/builder/index.js | 1 - .../server/utilities/builder/listScreens.js | 34 +------------------ 5 files changed, 60 insertions(+), 36 deletions(-) create mode 100644 packages/builder/src/builderStore/buildStateOrigins.js create mode 100644 packages/builder/tests/buildStateOrigins.spec.js diff --git a/packages/builder/src/builderStore/buildStateOrigins.js b/packages/builder/src/builderStore/buildStateOrigins.js new file mode 100644 index 0000000000..e1c1efed9a --- /dev/null +++ b/packages/builder/src/builderStore/buildStateOrigins.js @@ -0,0 +1,27 @@ + /** + * buildStateOrigins + * + * Builds an object that details all the bound state in the application, and what updates it. + * + * @param screenDefinition - the screen definition metadata. + * @returns {Object} an object with the client state values and how they are managed. + */ + export const buildStateOrigins = screenDefinition => { + const origins = {}; + + function traverse(propValue) { + for (let key in propValue) { + if (!Array.isArray(propValue[key])) continue; + + if (key === "_children") propValue[key].forEach(traverse); + + for (let element of propValue[key]) { + if (element["##eventHandlerType"] === "Set State") origins[element.parameters.path] = element; + } + } + } + + traverse(screenDefinition.props); + + return origins; + }; \ No newline at end of file diff --git a/packages/builder/src/userInterface/PropertyCascader.svelte b/packages/builder/src/userInterface/PropertyCascader.svelte index c8f6b4af6b..fdee0d3a26 100644 --- a/packages/builder/src/userInterface/PropertyCascader.svelte +++ b/packages/builder/src/userInterface/PropertyCascader.svelte @@ -1,6 +1,7 @@ @@ -66,7 +67,7 @@ {#if isOpen}