1
0
Fork 0
mirror of synced 2024-09-20 03:08:18 +12:00
budibase/packages/client/src/createApp.js

50 lines
1 KiB
JavaScript
Raw Normal View History

import {
split,
last
} from "lodash/fp";
import {writable} from "svelte/store";
import { $ } from "./core/common";
2019-09-22 16:02:33 +12:00
import { setupBinding } from "./state/stateBinding";
export const createApp = componentLibraries => {
const initialiseComponent = (props, htmlElement) => {
const {componentName, libName} = splitName(props._component);
2019-09-22 16:02:33 +12:00
if(!componentName || !libName) return;
const {initialProps, bind} = setupBinding(store, props);
const component = new (componentLibraries[libName][componentName])({
target: htmlElement,
2019-09-22 16:02:33 +12:00
props: {...initialProps, _app}
});
2019-09-22 16:02:33 +12:00
bind(component);
}
const store = writable({});
const _app = {
initialiseComponent,
store
};
return _app;
}
const splitName = fullname => {
const componentName = $(fullname, [
split("/"),
last
]);
const libName =fullname.substring(
0, fullname.length - componentName.length - 1);
return {libName, componentName};
}