3 ms·
This looks really nice! I’m interested to learn more about the custom reactivity model. I am a Svelte developer, and so far, Svelte is the most economic and
by FractalHQ 5y ago
This looks really nice! I’m interested to learn more about the custom reactivity model. I am a Svelte developer, and so far, Svelte is the most economic and powerful DSL I’ve used on web. I enjoy using it every day! I would be remiss if I didn’t ask- have you tried it? I would love to know how Svelte might influence your perspective on the perfect web language, or perhaps just what your opinion of it is. I’m also fascinated by Scrimba- it looks lovely and the product that its built for (scrimba.com) is pretty incredible web tech.
- brundolf 5y agoThanks! I haven't used Svelte firsthand, but I definitely researched it as part of my process for Bagel. As far as influence goes: Svelte definitely turned me on to the idea that you could skip a lot of the metaprogramming and overhead that MobX has to do, by injecting observe/invalidate calls at compile time. Both the bundle size and runtime memory usage should be dramatically lighter-weight as a result. With that said, Bagel's reactivity system is different from Svelte's in a couple of key ways: 1. From what I remember, Svelte can only react to assignments to variables, not deep mutations. If you do a deep mutation, the docs instruct you to re-assign the top level object so that it triggers an update. Bagel on the other hand - like MobX - keys off of object references + property names; each pair can be subscribed to and published individually, regardless of where the object lives. Assignments to raw variables are actually a special case in Bagel; the compiler injects a hidden sentinel object to make those assignments reactive. 2. Unlike Svelte, Bagel doesn't aim to be a DSL for UIs; it's trying to be a general-purpose language. This means it can't rely on, for example, a component lifecycle for standup/teardown of reactions. This forced some rethinks, as discussed in the article, but I think it worked out in the end. The generality also means Bagel can't easily replicate Svelte's "DOM-surgery" approach to reactive UIs (which is really cool, and probably going to change the industry); so I'm sticking with a VDOM model right now. With that said, Bagel is general enough that somebody might be able to add that functionality later in the form of a library! (I feel the need to post a disclaimer, that the current implementation of Bagel’s reactivity system is very crude end inefficient, and probably incomplete. I wanted to prove out the idea and then move on for the time being; but it will be much more fleshed out before release) As for why I don't use Svelte personally- partly I'm uncomfortable with the lack of deep reactivity; I think it would be really easy to forget to re-assign something. The other reason is that (last I checked) it seemed like static types (via TypeScript) are somewhat of a second-class citizen. My understanding is that Svelte shipped without support for TypeScript, and it got added later as people asked for it, but it's still only "mostly" supported because of Svelte’s DSL nature and some parts don’t get fully type-checked. I'm a big advocate of static types, so this is something that bothers me. With all that said, I have a lot of respect for the Svelte folks and I wish y'all success!