1
0
Fork 0
mirror of synced 2024-07-07 23:35:49 +12:00
This commit is contained in:
Michael Shanks 2020-01-28 11:00:44 +00:00
parent 74ae6e6238
commit 739e788da3
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); if(isFunction(event)) event(context);
} }
const initialiseChildrenParams = (parentContext, hydrate) => ({ const initialiseChildrenParams = (hydrate, parentContext) => ({
bb, coreApi, store, bb, coreApi, store, parentContext,
componentLibraries, appDefinition, componentLibraries, appDefinition,
parentContext, hydrate, uiFunctions hydrate, uiFunctions
}); });
const bb = (context, props) => ({ const bb = (componentProps, componentContext, parent) => ({
hydrateChildren: _initialiseChildren(initialiseChildrenParams(context, true)), hydrateChildren: _initialiseChildren(initialiseChildrenParams(true, componentContext)),
appendChildren: _initialiseChildren(initialiseChildrenParams(context, false)), appendChildren: _initialiseChildren(initialiseChildrenParams(false, componentContext)),
insertChildren: (props, htmlElement, anchor, context) => insertChildren: (props, htmlElement, anchor) =>
_initialiseChildren(initialiseChildrenParams(context, false)) _initialiseChildren(initialiseChildrenParams(false, componentContext))
(props, htmlElement, context, anchor), (props, htmlElement, anchor),
store, context: componentContext,
relativeUrl, props: componentProps,
api,
call:safeCallEvent, call:safeCallEvent,
isBound,
setStateFromBinding: (binding, value) => setStateFromBinding(store, binding, value), setStateFromBinding: (binding, value) => setStateFromBinding(store, binding, value),
setState: (path, value) => setState(store, path, value), setState: (path, value) => setState(store, path, value),
getStateOrValue: (prop, currentContext) => getStateOrValue: (prop, currentContext) =>
getStateOrValue(globalState, prop, currentContext), getStateOrValue(globalState, prop, currentContext),
context, store,
props relativeUrl,
api,
isBound,
parent
}); });
return bb(); 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, appDefinition,
user, user,
uiFunctions || {}); uiFunctions || {});
_app.hydrateChildren( app.hydrateChildren(
[props], [props],
window.document.body); window.document.body);
return _app; return app;
}; };
if(window) { if(window) {

View file

@ -9,7 +9,7 @@ import { $ } from "../core/common";
import { renderComponent } from "./renderComponent"; import { renderComponent } from "./renderComponent";
export const _initialiseChildren = (initialiseOpts) => export const _initialiseChildren = (initialiseOpts) =>
(childrenProps, htmlElement, context, anchor=null) => { (childrenProps, htmlElement, anchor=null) => {
const { uiFunctions, bb, coreApi, const { uiFunctions, bb, coreApi,
store, componentLibraries, store, componentLibraries,
@ -30,25 +30,20 @@ export const _initialiseChildren = (initialiseOpts) =>
if(!componentName || !libName) return; if(!componentName || !libName) return;
const {initialProps, bind} = setupBinding( const {initialProps, bind} = setupBinding(
store, childProps, coreApi, 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 componentConstructor = componentLibraries[libName][componentName];
const {component} = renderComponent({ const {component, context} = renderComponent({
componentConstructor,uiFunctions, componentConstructor,uiFunctions,
htmlElement, anchor, htmlElement, anchor,
parentContext, componentProps}); parentContext, initialProps, bb});
bind(component); bind(component);
childComponents.push(component); childComponents.push({component, context});
} }
return childComponents; return childComponents;

View file

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