1
0
Fork 0
mirror of synced 2024-09-20 03:08:18 +12:00
budibase/packages/builder/src/builderStore/buildCodeForScreens.js
2020-02-21 23:01:16 +00:00

33 lines
700 B
JavaScript

const buildCodeForSingleScreen = screen => {
let code = ""
const walkProps = props => {
if (props._code && props._code.trim().length > 0) {
code += buildComponentCode(props)
}
if (!props._children) return
for (let child of props._children) {
walkProps(child)
}
}
walkProps(screen.props)
return code
}
export const buildCodeForScreens = screens => {
let allfunctions = ""
for (let screen of screens) {
allfunctions += buildCodeForSingleScreen(screen)
}
return `return ({ ${allfunctions} });`
}
const buildComponentCode = componentProps =>
`"${componentProps._id}" : (render, context, state, routeParams) => {
${componentProps._code}
},
`