mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-11 14:20:07 +08:00
feat(engine): Add runOnInit method to getContext.
This commit is contained in:
parent
8c67b986c3
commit
2339a3a77d
@ -93,6 +93,26 @@ function getContext({ config, lowdefy, development = false }) {
|
||||
_internal.update = () => {
|
||||
_internal.RootBlocks.update();
|
||||
};
|
||||
_internal.runOnInit = async (progress) => {
|
||||
progress();
|
||||
if (!_internal.State.initialized && !_internal.onInitDone) {
|
||||
await _internal.RootBlocks.areas.root.blocks[0].triggerEvent({
|
||||
name: 'onInit',
|
||||
progress,
|
||||
});
|
||||
_internal.State.freezeState();
|
||||
_internal.onInitDone = true;
|
||||
}
|
||||
};
|
||||
_internal.runOnInitAsync = async (progress) => {
|
||||
if (!_internal.State.initialized && !_internal.onInitAsyncDone) {
|
||||
await _internal.RootBlocks.areas.root.blocks[0].triggerEvent({
|
||||
name: 'onInitAsync',
|
||||
progress,
|
||||
});
|
||||
_internal.onInitAsyncDone = true;
|
||||
}
|
||||
};
|
||||
lowdefy.contexts[id] = ctx;
|
||||
return ctx;
|
||||
}
|
||||
|
@ -24,34 +24,19 @@ const Context = ({ children, config, lowdefy, progress }) => {
|
||||
return (
|
||||
<MountEvents
|
||||
context={context}
|
||||
ename="onInit"
|
||||
triggerEvent={async () => {
|
||||
progress.dispatch({
|
||||
type: 'increment',
|
||||
});
|
||||
if (!context._internal.State.initialized) {
|
||||
await context._internal.RootBlocks.areas.root.blocks[0].triggerEvent({
|
||||
name: 'onInit',
|
||||
progress: () => {
|
||||
progress.dispatch({
|
||||
type: 'increment',
|
||||
});
|
||||
},
|
||||
await context._internal.runOnInit(() => {
|
||||
progress.dispatch({
|
||||
type: 'increment',
|
||||
});
|
||||
context._internal.State.freezeState();
|
||||
}
|
||||
});
|
||||
}}
|
||||
triggerEventAsync={() => {
|
||||
if (!context._internal.State.initialized) {
|
||||
context._internal.RootBlocks.areas.root.blocks[0].triggerEvent({
|
||||
name: 'onInitAsync',
|
||||
progress: () => {
|
||||
progress.dispatch({
|
||||
type: 'increment',
|
||||
});
|
||||
},
|
||||
context._internal.runOnInitAsync(() => {
|
||||
progress.dispatch({
|
||||
type: 'increment',
|
||||
});
|
||||
}
|
||||
});
|
||||
}}
|
||||
>
|
||||
{(loadingOnInit) => {
|
||||
|
Loading…
Reference in New Issue
Block a user