Independent Consultant & Software Architect
Trainer, Speaker, JS/TS Expert
ArchitekturaNaFroncie.pl (ANF)
Warsaw, PL
tomasz (at) ducin.dev
@tomasz_ducin
render phase (virtual) + commit phase (DOM repaint)
<script>
let price = 0;
function handleClick() {
price += 1;
}
</script>
<button on:click={handleClick}>
Price: {price} {price ? '$' : ''}
</button>
<button on:click={handleClick}>
Price: {price} {price ? '$' : ''}
</button>
function c(){
button = element("button");
t0 = text("Price: ");
t1 = text(ctx.price);
t2 = space();
t3 = text(t3_value);
dispose = listen(button, "click", ctx.handleClick);
}
let quantity = 1;
let price = 4.99;
let totalPrice = quantity * price; // 4.99
quantity++;
totalPrice // DESYNC
totalPrice == quantity * price
let quantity$ = fromClickEvent()
let price$ = fromHTTP(4.99)
let totalPrice$ = combineLatest(
quantity$, price$,
(quantity, price) => quantity * price
)
INC quantity$ // click!
totalPrice$ // 9.98
<script>
let quantity = 0;
let price = 4.99;
$: totalPrice = quantity * price;
function handleClick() {
quantity += 1;
}
</script>
<button on:click={handleClick}>
Price: {totalPrice} {totalPrice ? '$' : ''}
</button>
<script>
let quantity = 0;
let price = 4.99;
$: totalPrice = quantity * price;
function handleClick() {
quantity += 1;
}
async function update(data){
return http.post(url, data)
.then(...).catch(...)
}
$: update({ totalPrice })
</script>