1
0
Fork 0
mirror of synced 2024-09-12 23:43:09 +12:00
budibase/packages/client/src/index.js
Michael Shanks c7cbe6ca8b
#24 - Control Flow (#79)
* removed binding references to array type

* refactored initialiseChildren into seperate file

* render function, with code blocks - tested simple cases

* few mores tests for control flow

* md components - getting TestApp to work

* new render wrapper - bug fix

* client: providing access to component root elements

* code editor working

* code editor improvements
2020-01-31 23:11:50 +00:00

55 lines
No EOL
1.5 KiB
JavaScript

import { createApp } from "./createApp";
import { trimSlash } from "./common/trimSlash";
export const loadBudibase = async ({
componentLibraries, props,
window, localStorage, uiFunctions }) => {
const appDefinition = window["##BUDIBASE_APPDEFINITION##"];
const uiFunctionsFromWindow = window["##BUDIBASE_APPDEFINITION##"];
uiFunctions = uiFunctionsFromWindow || uiFunctions;
const userFromStorage = localStorage.getItem("budibase:user")
const user = userFromStorage ? JSON.parse(userFromStorage) : {
name: "annonymous",
permissions : [],
isUser:false,
temp:false
};
if(!componentLibraries) {
const rootPath = appDefinition.appRootPath === ""
? ""
: "/" + trimSlash(appDefinition.appRootPath);
const componentLibraryUrl = (lib) => rootPath + "/" + trimSlash(lib)
componentLibraries = {};
for(let lib of appDefinition.componentLibraries) {
componentLibraries[lib.libName] = await import(
componentLibraryUrl(lib.importPath));
}
}
if(!props) {
props = appDefinition.props;
}
const app = createApp(
window.document,
componentLibraries,
appDefinition,
user,
uiFunctions || {});
app.hydrateChildren(
[props],
window.document.body);
return app;
};
if(window) {
window.loadBudibase = loadBudibase;
}