You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's common to assign a variable to itself to trigger an update:
users.push(user);users=user;
IDEs love to complain about this, and, arguably, it's a bit strange.
Since these calls are transpiled to $$invalidate, I propose an intrinsic function which explicitly exposes this.
This would
make IDEs happy
result in easier to understand code
The snippet below could look like this:
users.push(user);invalidate(users);
Additional context
Maybe this could be usefull in regards to #4535 by offering an alternative to <svelte:options immutable/> for selectively updating a single property. This example could be rewritten like this:
<script>
importTodofrom'./Todo.svelte';let todos = [ { id:1, done:true, text:'wash the car' }, { id:2, done:false, text:'take the dog for a walk' }, { id:3, done:false, text:'mow the lawn' } ];functiontoggle(idx) { todos[idx].done^=true;// invalidate the updated propertyinvalidate(todos[idx].done); }
</script>
<h2>Todos</h2>
{#eachtodosastodo, i}
<Todo {todo} on:click={() =>toggle(i)}/>
{/each}
I'm not sure if it would be possible to implement invalidate like this.
However, even the "simple" usecase, being just an alternative to variable = variable, seems worth it to me.
The text was updated successfully, but these errors were encountered:
The $$invalidate that that compiles to is specific to the given component - it's not just the same function all the time that you can call for any component. We don't want another way to invalidate variables that looks like a function call but really compiles to something else. There should be one way to invalidate variables in Svelte, and if your editor is complaining about it, you should look into further configuring your tooling.
It's common to assign a variable to itself to trigger an update:
IDEs love to complain about this, and, arguably, it's a bit strange.
Since these calls are transpiled to
$$invalidate
, I propose an intrinsic function which explicitly exposes this.This would
The snippet below could look like this:
Additional context
Maybe this could be usefull in regards to #4535 by offering an alternative to
<svelte:options immutable/>
for selectively updating a single property. This example could be rewritten like this:I'm not sure if it would be possible to implement
invalidate
like this.However, even the "simple" usecase, being just an alternative to
variable = variable
, seems worth it to me.The text was updated successfully, but these errors were encountered: