I'm trying to use Monaco Editor in Svelte. I found this snippet online and it has an interesting way of defining the component. It looks like it declares this content
object in the onMount phase which should allow a parent component to subscribe to the editor.onDidChangeModelContent
event. However, I can't tell how could a parent component use the content
as a prop. Maybe I could get some help?
// MonacoEditor.sveltelet subscriptions = [];export let content;onMount(async () => { editor.onDidChangeModelContent(() => { const text = editor.getValue(); subscriptions.forEach((sub) => sub(text)); }); content = { subscribe(func) { subscriptions.push(func); return () => { subscriptions = subscriptions.filter((sub) => sub != func); }; }, set(val) { editor.setValue(val); }, }; return () => { editor.dispose(); };});
I tried to use binding in the parent component and declaring the content in an onMount directive inside the parent component, none of it makes total sense and none of it worked...