Created
June 13, 2020 16:07
-
-
Save Nyrox/5bd763f3ff18228557d1d1a6a5475ec2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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