Quantcast
Channel: Active questions tagged svelte - Stack Overflow
Viewing all articles
Browse latest Browse all 1541

How does this props passing method which includes a subscriber in the onMount directive work?

$
0
0

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...


Viewing all articles
Browse latest Browse all 1541

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>