budibase/packages/builder/src/builderStore/buildStateOrigins.js

29 lines
766 B
JavaScript
Raw Normal View History

2020-02-25 16:21:23 +01:00
/**
* 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 = {}
2020-02-25 16:21:23 +01:00
function traverse(propValue) {
for (let key in propValue) {
if (!Array.isArray(propValue[key])) continue
2020-02-25 16:21:23 +01:00
if (key === "_children") propValue[key].forEach(traverse)
2020-02-25 16:21:23 +01:00
for (let element of propValue[key]) {
if (element["##eventHandlerType"] === "Set State")
origins[element.parameters.path] = element
}
}
2020-02-25 16:21:23 +01:00
}
2020-02-25 16:21:23 +01:00
traverse(screenDefinition.props)
2020-02-25 16:21:23 +01:00
return origins
}