2020-09-10 22:11:05 +02:00
|
|
|
import { eventHandlers } from "./eventHandlers"
|
2020-02-18 13:29:38 +01:00
|
|
|
import { bbFactory } from "./bbComponentApi"
|
2020-08-11 15:12:05 +02:00
|
|
|
import renderTemplateString from "./renderTemplateString"
|
2020-08-06 22:12:35 +02:00
|
|
|
import appStore from "./store"
|
|
|
|
import hasBinding from "./hasBinding"
|
2020-02-18 13:29:38 +01:00
|
|
|
|
|
|
|
const doNothing = () => {}
|
|
|
|
doNothing.isPlaceholder = true
|
|
|
|
|
|
|
|
const isMetaProp = propName =>
|
|
|
|
propName === "_component" ||
|
|
|
|
propName === "_children" ||
|
|
|
|
propName === "_id" ||
|
|
|
|
propName === "_style" ||
|
|
|
|
propName === "_code" ||
|
2020-05-29 15:06:10 +02:00
|
|
|
propName === "_codeMeta" ||
|
|
|
|
propName === "_styles"
|
2020-02-18 13:29:38 +01:00
|
|
|
|
|
|
|
export const createStateManager = ({
|
|
|
|
componentLibraries,
|
|
|
|
onScreenSlotRendered,
|
2020-02-21 15:44:48 +01:00
|
|
|
routeTo,
|
2020-02-18 13:29:38 +01:00
|
|
|
}) => {
|
2020-09-10 22:11:05 +02:00
|
|
|
let runEventActions = eventHandlers(routeTo)
|
2020-05-30 01:14:41 +02:00
|
|
|
|
2020-02-18 13:29:38 +01:00
|
|
|
const bb = bbFactory({
|
|
|
|
componentLibraries,
|
|
|
|
onScreenSlotRendered,
|
2020-09-10 22:11:05 +02:00
|
|
|
runEventActions,
|
2020-02-18 13:29:38 +01:00
|
|
|
})
|
|
|
|
|
2020-09-10 22:11:05 +02:00
|
|
|
const setup = _setup(bb)
|
2020-05-30 01:14:41 +02:00
|
|
|
|
2020-02-18 13:29:38 +01:00
|
|
|
return {
|
|
|
|
setup,
|
2020-06-01 22:26:32 +02:00
|
|
|
destroy: () => {},
|
2020-02-18 13:29:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-10 22:11:05 +02:00
|
|
|
const _setup = bb => node => {
|
2020-02-18 13:29:38 +01:00
|
|
|
const props = node.props
|
|
|
|
const initialProps = { ...props }
|
|
|
|
|
|
|
|
for (let propName in props) {
|
|
|
|
if (isMetaProp(propName)) continue
|
|
|
|
|
2020-02-21 19:02:02 +01:00
|
|
|
const propValue = props[propName]
|
2020-02-18 13:29:38 +01:00
|
|
|
|
2020-08-06 22:12:35 +02:00
|
|
|
const isBound = hasBinding(propValue)
|
2020-02-21 19:02:02 +01:00
|
|
|
|
2020-05-30 01:14:41 +02:00
|
|
|
if (isBound) {
|
2020-08-06 22:12:35 +02:00
|
|
|
const state = appStore.getState(node.contextStoreKey)
|
2020-08-11 15:12:05 +02:00
|
|
|
initialProps[propName] = renderTemplateString(propValue, state)
|
2020-05-30 01:14:41 +02:00
|
|
|
|
|
|
|
if (!node.stateBound) {
|
|
|
|
node.stateBound = true
|
|
|
|
}
|
2020-05-29 15:06:10 +02:00
|
|
|
}
|
2020-02-18 13:29:38 +01:00
|
|
|
}
|
|
|
|
|
2020-09-10 22:11:05 +02:00
|
|
|
const setup = _setup(bb)
|
2020-02-18 13:29:38 +01:00
|
|
|
initialProps._bb = bb(node, setup)
|
|
|
|
|
|
|
|
return initialProps
|
|
|
|
}
|