Skip to content

Instantly share code, notes, and snippets.

@0gust1
Last active September 20, 2019 05:21
Show Gist options
  • Save 0gust1/8393f10155d77766a9dff6c75c280f44 to your computer and use it in GitHub Desktop.
Save 0gust1/8393f10155d77766a9dff6c75c280f44 to your computer and use it in GitHub Desktop.
Minimal Svelte info

Minimal Svelte info for @nhoizey

context : https://twitter.com/nhoizey/status/1169577744650428417

Svelte vs VueJs

The next version of Vue will have some Svelte inspired improvements, it seems.
I don't know much more, beside some quickly viewed screenshots of new syntax (I didn't practised Vue since ~1 year)

Svelte really shines on code simplicity/lightness. Developping a component really feels like writing a small HTML fragment (beside the templating directives) Particularities : mostly 2 syntaxes twists,

  • the export keyword is used to declare the props of a component. It may feel weird at first to some people.
  • the $ symbol, used to define reactive computations/functions.

App structure/organization

Classic architecture patterns used in React/Vue will still apply (component trees with descending data flow, using props).

Some (powerful) particularities :

Very simple and powerful. You can easily build upon to fit complex needs.
Take a look at the examples: https://svelte.dev/examples#writable-stores

SetContext/Getcontext – https://svelte.dev/docs#setContext

Used to share a live object instance on a whole component tree (from a root component to all its children tree)

Used to share behaviors (functions) across components, in a composable way.

An 'advanced' feature that you can use to define a "singleton" element over many component instances.

Example : https://svelte.dev/examples#module-exports

SVG

SVG feels like native to svelte.
SVG components are composable and natively dynamic/reactive. No differences from HTML (beside the markup you write).
Examples :

Svelte for esviji

I would eventually consider using sapper. The sapper boilerplate gives you a nice configured project structure with a little server, a configured bundler and really nice SSR+PWA capabilities out of the box.

However, a lot of the sapper boilerplate (the server part) would be useless for esviji, as it's only a client-side PWA. The export command would easily generate the final files (https://sapper.svelte.dev/docs#Exporting).

I filed an issue about this subject (sveltejs/sapper-template#78)

@nhoizey
Copy link

nhoizey commented Sep 20, 2019

Thank you so much, I'll dive into that ASAP!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment