Skip to content

Commit

Permalink
Merge branch 'scratch-package-refactor-merge-music-creation'
Browse files Browse the repository at this point in the history
  • Loading branch information
pmalacho-mit committed Jul 24, 2024
2 parents 286cc46 + 142be4f commit d359022
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/svelte/Modal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@
type VirtualMachine = _VirtualMachine & {
extensionManager: ExtensionManager;
};
async function untilDefined<T>(
getter: () => T,
delay: number = 100,
): Promise<T> {
let timeout: Parameters<typeof clearTimeout>[0];
let value = getter();
while (!value) {
await new Promise((resolve) => {
clearTimeout(timeout);
timeout = setTimeout(resolve, delay);
});
value = getter();
}
clearTimeout(timeout);
return value;
}
</script>

<script lang="ts">
Expand All @@ -43,15 +60,13 @@
let constructed: any;
onMount(async () => {
const props = {
close,
extension: vm.extensionManager.getExtensionInstance(id),
};
const options = { target, props };
const constructor = vm.extensionManager.getAuxiliaryObject(
id,
component,
const { extensionManager } = vm;
const extension = await untilDefined(() =>
extensionManager.getExtensionInstance(id),
);
const props = { close, extension };
const options = { target, props };
const constructor = extensionManager.getAuxiliaryObject(id, component);
constructed = new constructor(options);
return;
});
Expand Down

0 comments on commit d359022

Please sign in to comment.