2020-01-28 15:14:53 +01:00
|
|
|
export const renderComponent = ({
|
2020-02-03 10:24:25 +01:00
|
|
|
componentConstructor,
|
|
|
|
uiFunctions,
|
|
|
|
htmlElement,
|
|
|
|
anchor,
|
|
|
|
props,
|
|
|
|
initialProps,
|
|
|
|
bb,
|
|
|
|
parentNode,
|
|
|
|
}) => {
|
|
|
|
const func = initialProps._id ? uiFunctions[initialProps._id] : undefined
|
2020-01-28 15:14:53 +01:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const parentContext = (parentNode && parentNode.context) || {}
|
2020-01-30 00:01:14 +01:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
let renderedNodes = []
|
|
|
|
const render = context => {
|
|
|
|
let componentContext = parentContext
|
|
|
|
if (context) {
|
|
|
|
componentContext = { ...componentContext }
|
|
|
|
componentContext.$parent = parentContext
|
|
|
|
}
|
2020-01-28 15:14:53 +01:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
const thisNode = createTreeNode()
|
|
|
|
thisNode.context = componentContext
|
|
|
|
thisNode.parentNode = parentNode
|
|
|
|
thisNode.props = props
|
2020-01-30 00:01:14 +01:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
parentNode.children.push(thisNode)
|
|
|
|
renderedNodes.push(thisNode)
|
2020-01-30 00:01:14 +01:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
initialProps._bb = bb(thisNode, props)
|
2020-01-30 00:01:14 +01:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
thisNode.component = new componentConstructor({
|
|
|
|
target: htmlElement,
|
|
|
|
props: initialProps,
|
|
|
|
hydrate: false,
|
|
|
|
anchor,
|
|
|
|
})
|
2020-01-30 00:01:14 +01:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
thisNode.rootElement = htmlElement.children[htmlElement.children.length - 1]
|
2020-01-28 15:14:53 +01:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
if (initialProps._id) {
|
|
|
|
thisNode.rootElement.classList.add(`pos-${initialProps._id}`)
|
2020-01-28 15:14:53 +01:00
|
|
|
}
|
2020-02-03 10:24:25 +01:00
|
|
|
}
|
2020-01-28 15:14:53 +01:00
|
|
|
|
2020-02-03 10:24:25 +01:00
|
|
|
if (func) {
|
|
|
|
func(render, parentContext)
|
|
|
|
} else {
|
|
|
|
render()
|
|
|
|
}
|
|
|
|
|
|
|
|
return renderedNodes
|
2020-01-28 15:14:53 +01:00
|
|
|
}
|
|
|
|
|
2020-01-30 00:01:14 +01:00
|
|
|
export const createTreeNode = () => ({
|
2020-02-03 10:24:25 +01:00
|
|
|
context: {},
|
|
|
|
props: {},
|
|
|
|
rootElement: null,
|
|
|
|
parentNode: null,
|
|
|
|
children: [],
|
|
|
|
component: null,
|
|
|
|
unsubscribe: () => {},
|
|
|
|
})
|