|
|
|
|
|
by erikpukinskis
1073 days ago
|
|
I don’t follow… in what sense is this JavaScript? <button on:click={incrementCount}>
Specifically, what is on:click? It doesn’t look like JavaScript, and it doesn’t look like the DOM. It looks like a new language which is specific to Svelte.Or what about this… is this JavaScript? $: doubled = count * 2;
Or… {#if user.loggedIn}
<button on:click={toggle}> Log out </button>
{/if}
Or… <button on:click|once={handleClick}> Click me </button>
I am willing to believe that all of that is ergonomic in some way, but it doesn’t appear to me at first blush as very JavaScript-y, or explicit. I see a lot of black box stuff controlled by a declarative API. |
|
it's not. it's html. incrementCount is a pointer to a javascript function.
> Or what about this… is this JavaScript? > $: doubled = count * 2;
Yes. $: is a javascript label. We use it to indicate that a function should be reactive - if the count variable changes, the right hand will be rerun and double updated.
> <button on:click|once={handleClick}> Click me </button>
html again. the |once is a modifier to click which detaches the handler after a single use. It's a directive in the html markup (still valid html) which the compiler picks up and converts into node.removeEventHandler.