Live data from Hacker News

Svelte 3: Rethinking Reactivity

svelte.dev

31–40 of 186 posts

Re: Svelte 3: Rethinking Reactivity

#31
Would you consider adding a way to set tag names in a component dynamically? I’ve found that to be incredibly useful in React, when you want to encapsulate some behavior but use it in different semantic contexts across an app.

Or is it possible already somehow? I tried to use

  
but it doesn’t appear to support strings, just Svelte components?

Re: Svelte 3: Rethinking Reactivity

#32
post #28

Earlier quoted context omitted.

Yes! I talk a bit about prior art in this section of a recent talk: https://youtu.be/AdNJ3fydeao?t=504 . (Michel Weststrate, the MobX creator, was in the audience!) The difference in how you end up writing your code when you don't have a `this` turns out to be quite profound, and is the main reason that Svelte components are so concise: https://svelte.dev/blog/write-less-code It's also worth noting that this approach…

I was actually physically close to YGLF but unable to attend, I spoke there at a previous year. Michel is a friend and I collaborated with him on MobX. He's also one of the nicest people I know and he visits often. I think you might want to check out WPF + PostSharp for something very similar to this approach in C# land. I definitely think it's the right approach for reactivity.

Echoing your comment about Michel — he's a prince among men! Was great to meet him at YGLF

Re: Svelte 3: Rethinking Reactivity

#34
This is roughly how QML works too right?

> Cybernetically enhanced web apps

That is pretty terrible! It seems to me that the main think that distinguishes Svelt is that more work is done at compile-time? Why not a slogan that says just that?

"Compile-time optimised reactivity." or "Low overhead reactive web apps" or something like that. Cybernetics is nonsense waffle.

Anyway good luck! Seems like a better approach than shadow DOM etc.

Re: Svelte 3: Rethinking Reactivity

#35

I'm wondering how good Typescript support is. Can I use Typescript in the component script?

Sort of, via preprocessing, but you won't get any real benefit from it at present. There are two barriers: the compiler itself needs to become TS-aware, and we need to teach editors like VSCode how to typecheck inside blocks.

It's very much on the radar (I'm a TS convert, personally — Svelte itself is written in TypeScript), we just need to get round to it. The version 3 rewrite was largely about laying the foundations for TS support.

Re: Svelte 3: Rethinking Reactivity

#37
post #31

Would you consider adding a way to set tag names in a component dynamically? I’ve found that to be incredibly useful in React, when you want to encapsulate some behavior but use it in different semantic contexts across an app. Or is it possible already somehow? I tried to use but it doesn’t appear to support strings, just Svelte components?

Just components for now, but we have an issue for it: https://github.com/sveltejs/svelte/issues/2324

Re: Svelte 3: Rethinking Reactivity

#38
post #30

Earlier quoted context omitted.

Yes! I talk a bit about prior art in this section of a recent talk: https://youtu.be/AdNJ3fydeao?t=504 . (Michel Weststrate, the MobX creator, was in the audience!) The difference in how you end up writing your code when you don't have a `this` turns out to be quite profound, and is the main reason that Svelte components are so concise: https://svelte.dev/blog/write-less-code It's also worth noting that this approach…

Also, thanks for rollup, I've used it today and it was a lot of fun to work with. I was up and running (after experience with webpack) very quickly and everything I needed was well maintained and I was pleasantly surprised! The main blocker for me adopting Svetle (and opting for Vue and React) is tooling to be honest. I want code that has a lot of visibility, meaningful stack traces and the debugger stopping in relev…

Updates are asynchronous (they happen at the end of the event loop, so that `x = 1; y = 2;` results in one update instead of two), but I hear you on tooling. Svelte isn't yet as mature as other frameworks on that front (though debugging isn't bad in my experience). One day soon, hopefully!

Re: Svelte 3: Rethinking Reactivity

#39
One area where the virtual DOM seems to be important is for rich text editors, where the VDOM can basically take the input, diff it using an immutable structure, then render it to properly structured HTML.

An example use case where this would be valuable: a user hightlights text, bolds it, then highlights it again plus some more text, and bolds it. A naive approach would have: This text is bolded plus I bolded this when what you want would simply be: This text is bolded plus I bolded this

Libraries like DraftJS and SlateJS use immutable data structures to parse the input/formatting in the VDOM and reconcile them into "blocks" (basically javascript objects containing the formatting) that deduplicate formatting.

The talk below on DraftJS is pretty good.

https://www.youtube.com/watch?v=feUYwoLhE_4

What's the recommended way to handle a rich text application in Svelte? Is there anything like the above for Svelte?

Re: Svelte 3: Rethinking Reactivity

#40
Svelte looks amazing. Some questions that occurred to me:

- Does it work with TypeScript?

- How does it relate to other reactive frameworks, such as RXJS? Does it make sense to use them together or does the Svelte compiler invalidate the benefits of them?

- Does it work with any existing components?

Post reply on HN