1
0
Fork 0
mirror of synced 2024-09-20 03:08:18 +12:00
budibase/packages/builder/src/builderStore/buildStateOrigins.js
Martin McKeaveney 7ae40de558 eslint tidy up
2020-02-25 15:46:04 +00:00

28 lines
766 B
JavaScript

/**
* 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
}