2020-02-03 10:24:25 +01:00
|
|
|
const buildCodeForSingleScreen = screen => {
|
|
|
|
let code = ""
|
|
|
|
const walkProps = props => {
|
|
|
|
if (props._code && props._code.trim().length > 0) {
|
|
|
|
code += buildComponentCode(props)
|
|
|
|
}
|
2020-02-01 00:11:50 +01:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
if (!props._children) return
|
2020-02-01 00:11:50 +01:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
for (let child of props._children) {
|
|
|
|
walkProps(child)
|
2020-02-01 00:11:50 +01:00
|
|
|
}
|
2020-02-03 10:24:25 +01:00
|
|
|
}
|
2020-02-01 00:11:50 +01:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
walkProps(screen.props)
|
2020-02-01 00:11:50 +01:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
return code
|
2020-02-01 00:11:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const buildCodeForScreens = screens => {
|
2020-02-03 10:24:25 +01:00
|
|
|
let allfunctions = ""
|
|
|
|
for (let screen of screens) {
|
|
|
|
allfunctions += buildCodeForSingleScreen(screen)
|
|
|
|
}
|
|
|
|
|
2020-02-24 15:56:11 +01:00
|
|
|
return `({ ${allfunctions} });`
|
2020-02-01 00:11:50 +01:00
|
|
|
}
|
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const buildComponentCode = componentProps =>
|
2020-02-25 17:01:23 +01:00
|
|
|
`"${componentProps._id}" : (render, context, state, route) => {
|
2020-02-01 00:11:50 +01:00
|
|
|
${componentProps._code}
|
|
|
|
},
|
2020-02-03 10:24:25 +01:00
|
|
|
`
|