Good article! Nice to see the same thing implemented in a bunch of the popular frameworks.
I've been playing with Svelte a bit lately too, I think it's great. You mentioned the thing = thing weirdness, and I agree it's a bit weird to get used to, but you can also write things the "immutable" way to avoid it. I noticed your removeTodo function does it this way, so maybe you already knew about this, but for setTodoCompleted you could write it this way and avoid the todoList = todoList:
I tried todo.completed = value by itself and was a bit surprised it didn't work, because it seems Svelte should be able to "know" that todo came from that todoList array when it parses the template. That might be too hard with static analysis though.
Someone else already mentioned the input value binding thing, and yeah, you can shorten the code a bit by declaring a let inputValue up top and then doing <input id="new-todo" bind:value={inputValue} />. Svelte will bind that variable, and then you can just use it as normal in the addTodo function, without having to query for the input element.
Good article! Nice to see the same thing implemented in a bunch of the popular frameworks.
I've been playing with Svelte a bit lately too, I think it's great. You mentioned the
thing = thing
weirdness, and I agree it's a bit weird to get used to, but you can also write things the "immutable" way to avoid it. I noticed yourremoveTodo
function does it this way, so maybe you already knew about this, but forsetTodoCompleted
you could write it this way and avoid thetodoList = todoList
:Or, also, since you have the whole
todo
there already, there's no need tofind
it first, and you could do this:I tried
todo.completed = value
by itself and was a bit surprised it didn't work, because it seems Svelte should be able to "know" thattodo
came from thattodoList
array when it parses the template. That might be too hard with static analysis though.Someone else already mentioned the input value binding thing, and yeah, you can shorten the code a bit by declaring a
let inputValue
up top and then doing<input id="new-todo" bind:value={inputValue} />
. Svelte will bind that variable, and then you can just use it as normal in theaddTodo
function, without having to query for the input element.Hi Dave!
I've updated the Svelte example with
todo.completed = value
. Thanks for the suggestion.I've explained my reasoning for using querySelector to grab the input value in a reply on Silvestres comment.