My random thoughts on Svelte
Tags: svelte, frontend, webdev, javascript
Published: 2022-01-15 14:34:09

### Reactivity

Svelte has cool and simple reactive model. Really easy to understand and use, when I read docs for the first time I had thought why is that wasn’t done before? However, I think there is could be more. I would like svelte to be more reactive, something like `array.push` could trigger render. As well as methods in custom classes, which mutate `this`. Probably,  it’s possible to check in compile time is method mutate this or not and behavior corresponding.

### Async

Asynchronous blocks look fantastic. There is even no need to have an async function in components - just pass promise as props, and Svelte will do everything that should be done. Also, I like how easy to handle exceptions and loading states. However, it's a bit unclear, at least right now, how is it possible to do some logic in case a promise fails? What if you need to repeat a request or make something else?

### Template syntax

Do not like template syntax. Reminds some old times with template engines. It doesn’t look modern and elegant. Not really a downside, rather personal aesthetic preference

### Event handling

Not sure about putting event modifiers into an event handler assignment. As long as we can write on JavaScript in a handler function body, we can call modifiers against event objects. Looks too much. I think a good solution should try to do as least as possible in general, and personally can't see how that feature makes code easier to read and write.

### Custom events

Keeping consistent custom events names could be an annoying and bug-prone task when some wrapper could just propagate the event above in a tree. Maybe it's not a bad idea to make Svelte push developers declare an event name somewhere in a code and import it to the subscription's place

### Media

Updating time for video and audio happens in `requestAnimationFrame`. Why don't in `requestIdleCallback`?

### Lifecycle

Lifecycle functions remind me of old good react (before hooks era), but there is something good from hooks. For instance, the `onMount` callback could return a function invoked while destroying. It's really convenient, especially while we have the `onDestroy` lifecycle function. Also, it's excellent that Svelte allows unbound lifecycle functions with components and lets us reuse them just like React hooks! So in comparison to React, these lifecycle functions got the best parts from hooks and lifecycle class methods and did it better, in my opinion.



### Layout

Tick - elegant solution, like it a lot. Easy concept, unlike `useLayoutEffect`. Just great.

### Stores

Like everything else in Svelte, stores feel simple to use and understand. API has no complex concept; just subscribe if you wanna data! I have to admit, when I started reading the Svelte tutorial, I was preparing to understand a new complex framework with complex abstractions, etc. But instead, I see one of the best tutorials I’ve ever seen, simple, kind API (I don’t know, I feel that way), syntax, and it’s excellent! It’s like a breath of fresh air in the modern web (sorry, but especially after React hooks).

### Transitions

Transitions are funky, but it looks like those features aim to substitute some CSS. To be honest, I have an undefined opinion about that. There is such a high abstraction, so it's easy to make something, but what is the price? Obviously, not performance - everything happens in compile time. Probably skill? It's incredibly newbie-friendly, in my opinion, but it is crucial to keep learning js and DOM fundamentals for beginners. There is a lot of magic under the hood; hence, it's fun and easy to make the frontend with Svelte, but it will end immediately when you need to write some code outside the framework.

## Conclusion

Svelte made many common frontends development patterns less boilerplate and less annoying but left expressiveness and even added fun. Frankly, I'm a bit scared about how much framework is doing for me, like I lost control, but that fear isn't rational and shouldn't be considered as a reason to not use Svelte. Actually, the most important conclusion is that - Svelte made me want to write some frontend again 🙂

Photo by [Jonny Gios](https://unsplash.com/@supergios)