{
"dependencies": {}
}
4KB (min + gzip) for a "hello world" app
no virtual DOM
<script>
let a = 1;
let b = 2;
</script>
<input type="number" bind:value={a}>
<input type="number" bind:value={b}>
<p>{a} + {b} = {a + b}</p>
import React, { useState } from 'react';
export default () => {
const [a, setA] = useState(1);
const [b, setB] = useState(2);
function handleChangeA(event) {
setA(+event.target.value);
}
function handleChangeB(event) {
setB(+event.target.value);
}
return (
<div>
<input type="number" value={a} onChange={handleChangeA}/>
<input type="number" value={b} onChange={handleChangeB}/>
<p>{a} + {b} = {a + b}</p>
</div>
);
};
<template>
<div>
<input type="number" v-model.number="a">
<input type="number" v-model.number="b">
<p>{{a}} + {{b}} = {{a + b}}</p>
</div>
</template>
<script>
export default {
data: function() {
return {
a: 1,
b: 2
};
}
};
</script>
Svelte
React (w/ hooks)
Vue
var a = 10;
var b = a + 1;
a = 11;
b = a + 1;
Example from Paul Stovell's What is reactive programming ?
var a = 10;
$: b = a + 1;
a = 20;
console.log(b); // 21
var a = 10;
var b <= a + 1;
a = 20;
console.log(b); // 21
<script>
export let foo;
// Values that are passed in as props
// are immediately available
console.log({ foo });
</script>
You can also "dispatch" custom events up the component tree but general data-flow is top -> down
Bonus : unused selectors are not shipped to the browser !
(aka why don't we refactor all Keytrade web apps to Svelte)
Sapper
Svelte Native
e.g. array methods like .push() and .splice() won't automatically trigger updates !