feat(server): Make initLowdefyContext sync.

This commit is contained in:
Gervwyk 2022-03-04 16:48:47 +02:00
parent a872dfcf81
commit ef11ebb3e3
2 changed files with 14 additions and 20 deletions

View File

@ -14,37 +14,33 @@
limitations under the License.
*/
import React from 'react';
import actions from '../../build/plugins/actions.js';
import callRequest from '../utils/callRequest.js';
import blockComponents from '../../build/plugins/blocks.js';
import operators from '../../build/plugins/operatorsClient.js';
const LowdefyContext = ({ children, lowdefy }) => {
if (!lowdefy._internal) {
lowdefy._internal = {
function initLowdefyContext() {
const lowdefy = {
_internal: {
actions,
blockComponents,
callRequest,
components: {},
document,
operators,
updaters: {},
window,
displayMessage: ({ content }) => {
console.log(content);
return () => undefined;
},
link: () => undefined,
};
lowdefy.contexts = {};
lowdefy.inputs = {};
lowdefy.lowdefyGlobal = {};
}
},
contexts: {},
inputs: {},
lowdefyGlobal: {},
};
lowdefy._internal.updateBlock = (blockId) =>
lowdefy._internal.updaters[blockId] && lowdefy._internal.updaters[blockId]();
return <>{children}</>;
};
return lowdefy;
}
export default LowdefyContext;
export default initLowdefyContext;

View File

@ -18,18 +18,16 @@ import React from 'react';
import dynamic from 'next/dynamic';
import { ErrorBoundary } from '@lowdefy/block-utils';
import LowdefyContext from '../lib/components/LowdefyContext.js';
import initLowdefyContext from '../lib/utils/initLowdefyContext.js';
import '../build/plugins/styles.less';
const lowdefy = {};
const lowdefy = initLowdefyContext();
function App({ Component, pageProps }) {
return (
<ErrorBoundary>
<LowdefyContext lowdefy={lowdefy}>
<Component lowdefy={lowdefy} {...pageProps} />
</LowdefyContext>
<Component lowdefy={lowdefy} {...pageProps} />
</ErrorBoundary>
);
}