2020-01-28 15:14:53 +01:00
|
|
|
import {
|
|
|
|
setupBinding
|
|
|
|
} from "../state/stateBinding";
|
|
|
|
import {
|
|
|
|
split,
|
|
|
|
last
|
|
|
|
} from "lodash/fp";
|
|
|
|
import { $ } from "../core/common";
|
|
|
|
import { renderComponent } from "./renderComponent";
|
|
|
|
|
|
|
|
export const _initialiseChildren = (initialiseOpts) =>
|
2020-01-30 00:01:14 +01:00
|
|
|
(childrenProps, htmlElement, anchor=null) => {
|
2020-01-28 15:14:53 +01:00
|
|
|
|
|
|
|
const { uiFunctions, bb, coreApi,
|
2020-01-30 00:01:14 +01:00
|
|
|
store, componentLibraries, treeNode,
|
|
|
|
appDefinition, document, hydrate } = initialiseOpts;
|
|
|
|
|
|
|
|
for(let childNode of treeNode.children) {
|
|
|
|
if(childNode.unsubscribe)
|
|
|
|
childNode.unsubscribe();
|
|
|
|
if(childNode.component)
|
|
|
|
childNode.component.$destroy();
|
|
|
|
}
|
2020-01-28 15:14:53 +01:00
|
|
|
|
|
|
|
if(hydrate) {
|
|
|
|
while (htmlElement.firstChild) {
|
|
|
|
htmlElement.removeChild(htmlElement.firstChild);
|
|
|
|
}
|
|
|
|
}
|
2020-01-31 17:01:58 +01:00
|
|
|
|
|
|
|
htmlElement.classList.add(`lay-${treeNode.props._id}`)
|
2020-01-30 00:01:14 +01:00
|
|
|
|
|
|
|
const renderedComponents = [];
|
2020-01-28 15:14:53 +01:00
|
|
|
for(let childProps of childrenProps) {
|
|
|
|
|
|
|
|
const {componentName, libName} = splitName(childProps._component);
|
|
|
|
|
|
|
|
if(!componentName || !libName) return;
|
|
|
|
|
|
|
|
const {initialProps, bind} = setupBinding(
|
2020-01-30 00:01:14 +01:00
|
|
|
store, childProps, coreApi,
|
|
|
|
appDefinition.appRootPath);
|
|
|
|
|
2020-01-28 15:14:53 +01:00
|
|
|
const componentConstructor = componentLibraries[libName][componentName];
|
|
|
|
|
2020-01-30 00:01:14 +01:00
|
|
|
const renderedComponentsThisIteration = renderComponent({
|
|
|
|
props: childProps,
|
|
|
|
parentNode: treeNode,
|
2020-01-28 15:14:53 +01:00
|
|
|
componentConstructor,uiFunctions,
|
2020-01-30 00:01:14 +01:00
|
|
|
htmlElement, anchor, initialProps,
|
2020-02-01 00:11:50 +01:00
|
|
|
bb});
|
2020-01-30 00:01:14 +01:00
|
|
|
|
|
|
|
for(let comp of renderedComponentsThisIteration) {
|
|
|
|
comp.unsubscribe = bind(comp.component);
|
|
|
|
renderedComponents.push(comp);
|
|
|
|
}
|
2020-01-28 15:14:53 +01:00
|
|
|
}
|
|
|
|
|
2020-01-30 00:01:14 +01:00
|
|
|
return renderedComponents;
|
2020-01-28 15:14:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const splitName = fullname => {
|
|
|
|
const componentName = $(fullname, [
|
|
|
|
split("/"),
|
|
|
|
last
|
|
|
|
]);
|
|
|
|
|
|
|
|
const libName =fullname.substring(
|
|
|
|
0, fullname.length - componentName.length - 1);
|
|
|
|
|
|
|
|
return {libName, componentName};
|
2020-01-30 00:01:14 +01:00
|
|
|
}
|