@@ -646,7 +646,7 @@ export class NSVElement<T extends NativeView = NativeView> extends NSVNode imple
646646 }
647647 }
648648
649- private getTextFromChildTextNodes ( ) : string {
649+ public getTextFromChildTextNodes ( ) : string {
650650 return this . childNodes
651651 . filter ( ( node ) => node . nodeType === NSVNodeTypes . TEXT )
652652 . reduce ( ( text : string , currentNode ) => {
@@ -677,19 +677,52 @@ export class NSVComment extends NSVNode {
677677 }
678678}
679679
680+ /**
681+ * This is a text node. It's a virtual element (is non-visual), and serves only as a data structure.
682+ * Whenever its data changes, we tell its parentNode to update its "text" property.
683+ */
680684export class NSVText extends NSVNode {
681685 constructor ( private _text : string ) {
682686 super ( NSVNodeTypes . TEXT ) ;
683687 // console.log(`[NSVText] constructor "${this._text}"`);
684688 }
685689
690+ /**
691+ * The Svelte runtime calls this upon the text node.
692+ * @see set_data()
693+ */
694+ get wholeText ( ) : string | undefined {
695+ return this . text ;
696+ }
697+
698+ set wholeText ( val ) {
699+ this . text = val ;
700+ }
701+
702+ /**
703+ * The Svelte runtime calls this upon the text node.
704+ * @see set_data()
705+ */
706+ get data ( ) : string | undefined {
707+ return this . text ;
708+ }
709+ set data ( val ) {
710+ // console.log(`[NSVText] Was asked to set "data" to`, val);
711+ this . text = val ;
712+ }
713+
686714 get text ( ) : string | undefined {
687715 return this . _text ;
688716 }
689717
690718 set text ( t : string | undefined ) {
691- // console.log(`NSVText text setter was called!`);
719+ console . log ( `NSVText text setter was called!` ) ;
692720 this . _text = t ;
721+ // Tell any parent node to update its "text" property because this text node has just updated
722+ // its contents.
723+ if ( this . parentNode && ( this . parentNode as NSVElement ) . getTextFromChildTextNodes ) {
724+ this . parentNode . text = ( this . parentNode as NSVElement ) . getTextFromChildTextNodes ( ) ;
725+ }
693726 }
694727
695728 toString ( ) : string {
0 commit comments