Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Dec 9, 2024
1 parent 491600b commit f846258
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
19 changes: 10 additions & 9 deletions documentation/docs/98-reference/.generated/compile-warnings.md
Original file line number Diff line number Diff line change
Expand Up @@ -798,12 +798,13 @@ This warning is thrown when the compiler detects the following:
In this case, the state reassignment will not be noticed by whatever you passed it to. For example, if you pass the state to a function, that function will not notice the updates:

```svelte
<!--- Parent.svelte --->
<!--- file: Parent.svelte --->
<script>
import { setContext } from 'svelte';
let count = $state(0);
// warning: state referenced locally
// warning: state_referenced_locally
setContext('count', count);
</script>
Expand All @@ -813,7 +814,7 @@ In this case, the state reassignment will not be noticed by whatever you passed
```

```svelte
<!--- Child.svelte --->
<!--- file: Child.svelte --->
<script>
import { getContext } from 'svelte';
Expand All @@ -824,15 +825,15 @@ In this case, the state reassignment will not be noticed by whatever you passed
<p>The count is {count}</p>
```

To fix this, reference the variable such that it is lazily evaluated. For the above example, this can be achieved by wrapping the count in a function:
To fix this, reference the variable such that it is lazily evaluated. For the above example, this can be achieved by wrapping `count` in a function:

```svelte
<!--- Parent.svelte --->
<!--- file: Parent.svelte --->
<script>
import { setContext } from 'svelte';
let count = $state(0);
setContext('count', () => count);
setContext('count', +++() => count+++);
</script>
<button onclick={() => count++}>
Expand All @@ -841,18 +842,18 @@ To fix this, reference the variable such that it is lazily evaluated. For the ab
```

```svelte
<!--- Child.svelte --->
<!--- file: Child.svelte --->
<script>
import { getContext } from 'svelte';
const count = getContext('count');
</script>
<!-- This will update -->
<p>The count is {count()}</p>
<p>The count is {+++count()+++}</p>
```

For more info, see [the docs on `$state`]($state#Passing-state-into-functions)
For more info, see [Passing state into functions]($state#Passing-state-into-functions).

### store_rune_conflict

Expand Down
16 changes: 8 additions & 8 deletions packages/svelte/messages/compile-warnings/script.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ This warning is thrown when the compiler detects the following:
In this case, the state reassignment will not be noticed by whatever you passed it to. For example, if you pass the state to a function, that function will not notice the updates:

```svelte
<!--- Parent.svelte --->
<!--- file: Parent.svelte --->
<script>
import { setContext } from 'svelte';
Expand All @@ -80,7 +80,7 @@ In this case, the state reassignment will not be noticed by whatever you passed
```

```svelte
<!--- Child.svelte --->
<!--- file: Child.svelte --->
<script>
import { getContext } from 'svelte';
Expand All @@ -91,15 +91,15 @@ In this case, the state reassignment will not be noticed by whatever you passed
<p>The count is {count}</p>
```

To fix this, reference the variable such that it is lazily evaluated. For the above example, this can be achieved by wrapping the count in a function:
To fix this, reference the variable such that it is lazily evaluated. For the above example, this can be achieved by wrapping `count` in a function:

```svelte
<!--- Parent.svelte --->
<!--- file: Parent.svelte --->
<script>
import { setContext } from 'svelte';
let count = $state(0);
setContext('count', () => count);
setContext('count', +++() => count+++);
</script>
<button onclick={() => count++}>
Expand All @@ -108,18 +108,18 @@ To fix this, reference the variable such that it is lazily evaluated. For the ab
```

```svelte
<!--- Child.svelte --->
<!--- file: Child.svelte --->
<script>
import { getContext } from 'svelte';
const count = getContext('count');
</script>
<!-- This will update -->
<p>The count is {count()}</p>
<p>The count is {+++count()+++}</p>
```

For more info, see [the docs on `$state`]($state#Passing-state-into-functions)
For more info, see [Passing state into functions]($state#Passing-state-into-functions).

## store_rune_conflict

Expand Down

0 comments on commit f846258

Please sign in to comment.