Skip to content

Commit

Permalink
Don't set empty app before loading the actual one.
Browse files Browse the repository at this point in the history
  • Loading branch information
mchilvers committed May 10, 2024
1 parent 86b89d2 commit fd08d19
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/tools/builder/src/views/builder/builder-model.ts
Expand Up @@ -30,25 +30,32 @@ export class BuilderModel extends ViewModelBase {

public async init(): Promise<void> {
/**
* Wait for the "builder" object to be available in the global scope.
* Wait for the "builder" object to be available in the global window scope.
*/
// @ts-ignore
while (!window['builder']){
await new Promise(r => setTimeout(r, 10));
}

this.getPages();
this.setDefaultPage();
this.getAvailableComponents();
/*
* BuilderUtilities is really just a bridge between this class (the JS-side of
* the view model) and the "Builder" class in "builder.py" (the Python-side of
* the view model).
*/
/**
* BuilderUtilities is really just a bridge between this class (the JS-side of
* the view model) and the "Builder" class in "builder.py" (the Python-side of
* the view model).
*
* Here we just pass a reference to this object (the JS side) to the Python
* side.
*/
BuilderUtilities.init(this);

/**
* Start listening for messages from the hosting application (probably PSDC!).
*/
this.listenForIframeMessages();

/**
* Let the hosting application know that we are ready (and we can now load an
* app.
*/
window.parent.postMessage({
type: "invent-ready"
}, location.origin);
Expand All @@ -73,19 +80,18 @@ export class BuilderModel extends ViewModelBase {
public listenForIframeMessages(): void {
window.addEventListener("message", async (event: MessageEvent) => {
// Only allow same origin messages.
if (event.origin !== location.origin) return;
if (event.origin !== location.origin) return;

const { type, data } = event.data;

console.log(`Invent - received message type ${type}:`, data);
console.log(`Invent - received message type: ${type}:`, data);

switch (type){
case "save-request": {
event.source?.postMessage({
type: "save-response",
data: this.save(),
});

break;
}

Expand Down

0 comments on commit fd08d19

Please sign in to comment.