This commit is contained in:
Michael Shanks 2020-01-28 11:00:44 +00:00
parent 78706c9375
commit 7a0f7da119
4 changed files with 30 additions and 75 deletions

View File

@ -50,74 +50,32 @@ export const createApp = (componentLibraries, appDefinition, user, uiFunctions)
if(isFunction(event)) event(context);
}
const initialiseChildrenParams = (parentContext, hydrate) => ({
bb, coreApi, store,
const initialiseChildrenParams = (hydrate, parentContext) => ({
bb, coreApi, store, parentContext,
componentLibraries, appDefinition,
parentContext, hydrate, uiFunctions
hydrate, uiFunctions
});
const bb = (context, props) => ({
hydrateChildren: _initialiseChildren(initialiseChildrenParams(context, true)),
appendChildren: _initialiseChildren(initialiseChildrenParams(context, false)),
insertChildren: (props, htmlElement, anchor, context) =>
_initialiseChildren(initialiseChildrenParams(context, false))
(props, htmlElement, context, anchor),
store,
relativeUrl,
api,
const bb = (componentProps, componentContext, parent) => ({
hydrateChildren: _initialiseChildren(initialiseChildrenParams(true, componentContext)),
appendChildren: _initialiseChildren(initialiseChildrenParams(false, componentContext)),
insertChildren: (props, htmlElement, anchor) =>
_initialiseChildren(initialiseChildrenParams(false, componentContext))
(props, htmlElement, anchor),
context: componentContext,
props: componentProps,
call:safeCallEvent,
isBound,
setStateFromBinding: (binding, value) => setStateFromBinding(store, binding, value),
setState: (path, value) => setState(store, path, value),
getStateOrValue: (prop, currentContext) =>
getStateOrValue(globalState, prop, currentContext),
context,
props
store,
relativeUrl,
api,
isBound,
parent
});
return bb();
}
const buildBindings = (boundProps, boundArrays, contextBoundProps) => {
const bindings = {};
if(boundProps && boundProps.length > 0) {
for(let p of boundProps) {
bindings[p.propName] = {
path: p.path,
fallback: p.fallback,
source: p.source
}
}
}
if(contextBoundProps && contextBoundProps.length > 0) {
for(let p of contextBoundProps) {
bindings[p.propName] = {
path: p.path,
fallback: p.fallback,
source: p.source
}
}
}
if(boundArrays && boundArrays.length > 0) {
for(let a of boundArrays) {
const arrayOfBindings = [];
for(let b of a.arrayOfBindings) {
arrayOfBindings.push(
buildBindings(
b.boundProps,
b.boundArrays,
b.contextBoundProps)
);
}
bindings[a.propName] = arrayOfBindings;
}
}
return bindings;
}

View File

@ -40,11 +40,11 @@ export const loadBudibase = async ({
appDefinition,
user,
uiFunctions || {});
_app.hydrateChildren(
app.hydrateChildren(
[props],
window.document.body);
return _app;
return app;
};
if(window) {

View File

@ -9,7 +9,7 @@ import { $ } from "../core/common";
import { renderComponent } from "./renderComponent";
export const _initialiseChildren = (initialiseOpts) =>
(childrenProps, htmlElement, context, anchor=null) => {
(childrenProps, htmlElement, anchor=null) => {
const { uiFunctions, bb, coreApi,
store, componentLibraries,
@ -31,24 +31,19 @@ export const _initialiseChildren = (initialiseOpts) =>
const {initialProps, bind} = setupBinding(
store, childProps, coreApi,
context || parentContext, appDefinition.appRootPath);
appDefinition.appRootPath);
/// here needs to go inside renderComponent ???
const componentProps = {
...initialProps,
_bb:bb(context || parentContext, childProps)
};
const componentConstructor = componentLibraries[libName][componentName];
const {component} = renderComponent({
const {component, context} = renderComponent({
componentConstructor,uiFunctions,
htmlElement, anchor,
parentContext, componentProps});
parentContext, initialProps, bb});
bind(component);
childComponents.push(component);
childComponents.push({component, context});
}
return childComponents;

View File

@ -2,9 +2,9 @@
export const renderComponent = ({
componentConstructor, uiFunctions,
htmlElement, anchor, parentContext,
componentProps}) => {
initialProps, bb}) => {
const func = componentProps._id
const func = initialProps._id
? uiFunctions[componentProps._id]
: undefined;
@ -19,9 +19,11 @@ export const renderComponent = ({
componentContext = parentContext;
}
initialProps._bb = bb(initialProps, componentContext);
component = new componentConstructor({
target: htmlElement,
props: componentProps,
props: initialProps,
hydrate:false,
anchor
});