Skip to content

Commit

Permalink
make sure preview renders on initial load
Browse files Browse the repository at this point in the history
  • Loading branch information
jpraetorius committed Jun 26, 2024
1 parent f6b4f19 commit 48e0326
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ editor.addEventListener('editor-content-changed', (e) => {
const document = e.detail.content;
previewPane.document = document;
});
// now that everything is wired up make the editor spit put the content for a first render
document.dispatchEvent(new CustomEvent('request-document'));
11 changes: 6 additions & 5 deletions src/ui/elements/editor-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ export class EditorElement extends LitElement {
editor.onDidChangeModelContent(() => {
const content = editor.getValue();
storeDataContractYaml(content);
this.dispatchEvent(new CustomEvent('editor-content-changed', { detail: { content } }));
this.dispatchEvent(new CustomEvent('editor-content-changed', { detail: { content } }));
});

document.addEventListener('request-document', () => {
this.dispatchEvent(new CustomEvent('editor-content-changed', { detail: { content: editor.getValue() }}));
})

// set up to detect editor errors and emit them
monaco.editor.onDidChangeMarkers((resource) => {
const markers = monaco.editor.getModelMarkers({resource});
Expand All @@ -59,7 +63,7 @@ export class EditorElement extends LitElement {
column: marker.startColumn
}))

this.dispatchEvent(new CustomEvent('editor-errors', { detail: { validationErrors } }));
this.dispatchEvent(new CustomEvent('editor-errors', { detail: { validationErrors } }));
});


Expand All @@ -68,9 +72,6 @@ export class EditorElement extends LitElement {
editor.layout();
});
resizeObserver.observe(this.editor);

// emit current content for a first render
this.dispatchEvent(new CustomEvent('editor-content-changed', { detail: { content: editor.getValue() } }));
}
}
customElements.define("dce-editor", EditorElement);

0 comments on commit 48e0326

Please sign in to comment.