Skip to content

Commit

Permalink
feat(runtime): set text attribute to NS views when the last element i…
Browse files Browse the repository at this point in the history
…s a text node
  • Loading branch information
msaelices committed Apr 14, 2020
1 parent 8a07385 commit 8c8b4aa
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/runtime/src/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ export class NSVElement extends NSVNode implements INSVElement {
this.nativeView.style = inlineStyle
}

get text(): string | undefined {
return this.nativeView.text
}

set text(t: string | undefined) {
this.nativeView.text = t
}

get meta() {
if (this._meta) {
return this._meta
Expand Down

3 comments on commit 8c8b4aa

@rigor789
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm - I've had this in there before, but then refactored how the text is set when there are text child nodes:

updateText() {
this.setAttribute(
'text',
this.childNodes
.filter(node => node.nodeType === NSVNodeTypes.TEXT)
.reduce((text: string, currentNode) => {
return text + currentNode.text
}, '')
)
}

Have you run into a case where this was needed?

Very possible that I may be missing something, so just checking! :)

@msaelices
Copy link
Collaborator Author

@msaelices msaelices commented on 8c8b4aa Apr 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rigor789 if we don't declare the text getter and setter, it fails setting the text attribute in the NS nativeView when there are several root nodes in the Vue instance:

Screenshot 2020-04-15 at 00 23 35

As you know, allowing several root nodes is a new "feature" in Vue 3. BTW, I don't know why it works in the other cases and for this case doesn't, maybe even it's a Vue issue. You can check it out by commenting on the setter and getter and run yarn test

@rigor789
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@msaelices ah seems like h('Label', 'sometext') has a short path - and the text isn't actually added as a TextNode, but it's directly set as the text on the ElementNode (I assume this would be then set to textContent on web)

Looks good! 👍

Please sign in to comment.