Skip to content

Instantly share code, notes, and snippets.

@Nyrox
Created June 13, 2020 16:07
Show Gist options
  • Save Nyrox/5bd763f3ff18228557d1d1a6a5475ec2 to your computer and use it in GitHub Desktop.
Save Nyrox/5bd763f3ff18228557d1d1a6a5475ec2 to your computer and use it in GitHub Desktop.
// old version
customElements.define("monaco-editor", class extends HTMLElement {
constructor() {
super();
this._editorValue = "loading..."
}
set _editorValue(value) {
console.log(value);
if (!this._editor) return;
this._editor.setValue(value);
}
connectedCallback() {
this._editor = monaco.editor.create(this, {
value: this._editorValue,
language: 'javascript'
});
this._editor.onDidChangeModelContent(_ => {
this.dispatchEvent(new CustomEvent("editorValueChanged"))
})
}
})
// new fixed version
customElements.define("monaco-editor", class extends HTMLElement {
constructor() {
super();
this._editorValue = "loading..."
Object.defineProperty(this, "_editorValue", {
set: function(value) {
if (!this._editor) return;
this._editor.setValue(value);
}
})
}
connectedCallback() {
this._editor = monaco.editor.create(this, {
value: this._editorValue,
language: 'javascript'
});
this._editor.onDidChangeModelContent(_ => {
this.dispatchEvent(new CustomEvent("editorValueChanged"))
})
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment