I really love Svelte. The compiler is great and very extensible. For example, you can easily add functions to the processing pipeline to process Svelte templates (or the script elements or style sections) in your own special way. It's a fantastic way to build JavaScript frameworks. Svelte people always note Svelte isn't a framework, so this isn't a framework on top of another framework! I used this to build Svekyll,…
Learn how modern JavaScript frameworks work by building one
51–60 of 104 posts
Re: Learn how modern JavaScript frameworks work by building one
#52Re: Learn how modern JavaScript frameworks work by building one
#53No abstraction, no nonstandard HTML tags, no , no Proxy, no master class trying to figure out what part of the DOM should or shouldn't be redrawn based on inbound data. Every component should be autonomous, every screen should be able to destroy or resurrect its own components. If you need a central data cache, put that on the ping and let every component deal with it on the event firing.
[edit] I've built and maintained two frameworks, one for websites and one for single page apps, rewritten and improved over 20 years, originally in PHP, now in Nodejs. The main guiding principle for me has always been decoupling design from code.
Re: Learn how modern JavaScript frameworks work by building one
#54I really love Svelte. The compiler is great and very extensible. For example, you can easily add functions to the processing pipeline to process Svelte templates (or the script elements or style sections) in your own special way. It's a fantastic way to build JavaScript frameworks. Svelte people always note Svelte isn't a framework, so this isn't a framework on top of another framework! I used this to build Svekyll,…
Re: Learn how modern JavaScript frameworks work by building one
#55Please, do not build more JS frameworks (see-no-evil emoji).
You mean, you want React to continue for the rest of human history? Hope not!
Is all this pain and complexity really worth the gain? In practice it often leads to a slower experience for users due to the massive globs of js.
Re: Learn how modern JavaScript frameworks work by building one
#56If anyone is interested in this topic, I would recommend to start from fundamentals, so it would provide some answers on why some "not so modern" frameworks aren't jumping on a "signals" hype-train. - Incremental computing - https://en.wikipedia.org/wiki/Incremental_computing - Self-Adjusting Computation (Umut A. Acar) - https://www.cs.cmu.edu/~rwh/students/acar.pdf - Introducing incremental (JaneStreet) - https://bl…
Besides React, are any of the popular frameworks not on the signals type-train?
At this point I can't stop myself from pointing out that the underlying reactivity/diffing system is rarely what makes an application slow. I've heard the creator of XState and Stately [1] say that React's vdom is not fast enough for updating edges in their state chart in real time without lots of optimisations and I believe him. It's just that most people don't encounter such issues and spend adding a dozen tracking scripts that run before the actual application does.
0 - https://vuejs.org/guide/extras/reactivity-in-depth.html#conn...
Re: Learn how modern JavaScript frameworks work by building one
#57Earlier quoted context omitted.
Author here. Thanks for the thoughtful reply! I did indeed mix up `useMemo` and `React.memo` – fixed it in the post. You're right, I am skipping a lot of details (hence "to grossly oversimplify"). I know that React doesn't invalidate the whole tree, but it does in the worst case. Maybe I should add a note about that. Svelte not being truly reactive makes perfect sense, but in Svelte v5 my understanding is that "runes…
Appreciate the response! You're right on Svelte v5; I just confirmed that Svelte's new runes are indeed reactive: let count = $state(0); function increment() { count += 1; console.log(count + " + 1 = " + countPlusOne); // prints "1 + 1 = 2" } let countPlusOne = $derived(count + 1);
Re: Learn how modern JavaScript frameworks work by building one
#58Re: Learn how modern JavaScript frameworks work by building one
#59Earlier quoted context omitted.
Appreciate the response! You're right on Svelte v5; I just confirmed that Svelte's new runes are indeed reactive: let count = $state(0); function increment() { count += 1; console.log(count + " + 1 = " + countPlusOne); // prints "1 + 1 = 2" } let countPlusOne = $derived(count + 1);
I never used svelte, so it’s probably a weird question, but how is increment() called?
` increment()}>+`
Re: Learn how modern JavaScript frameworks work by building one
#60Earlier quoted context omitted.
React now supports this using Suspense boundaries [0]. Some frameworks (eg. NextJS) already ship variants of it but here is some code you could use in React's development version: function MyComponent() { const promise = ...; const result = use(promise); // use is like await // do something } function Wrapper() { return ( }> ); } You don't need to know this to use it, but the implementation is both interesting and ho…
The way Suspense works is actually even a bit more interesting/horrifying: it doesn’t throw an error, it throws a Promise . Which again you don’t need to know to use it, and so it’s a valid implementation detail, but it’s a really odd one.
The decision to avoid a custom compiler is responsible for almost all oddities and downsides of React.