svetle5 rune and rune document is not elegant · Issue #16252 · sveltejs/svelte · GitHub | Latest TMZ Celebrity News & Gossip | Watch TMZ Live
Skip to content

svetle5 rune and rune document is not elegant #16252

Closed as not planned
Closed as not planned
@difsch2077

Description

@difsch2077

Describe the problem

Store is elegant

src/use-store.ts:
import { writable } from "svelte/store";
export let s = writable(0);

src/store.svelte:
<script lang="ts">
  import { s } from "./use-store";
</script>
<button on:click={() => ($s += 1)}> {$s}</button>

Rune and rune document is not elegant!

First, someone tries rune:

src/use-rune.ts
export let r = $state(0);

src/rune.svelte:
<script lang="ts">
  import { r } from "./use-rune";
</script>

<button on:click={() => (r = r + 1)}>{r}</button>
ERROR: Cannot assign to import

Then they try

export let r = $state(0); 

change to ->
export let r = $state(0);

export function increment() {
  r += 1;
}
ERROR: The $state rune is only available inside .svelte and .svelte.js/ts files

Then

They read https://svelte.dev/docs/svelte/svelte-js-files and try renaming src/use-rune.ts to src/use-rune.svelte.ts, and change all the imports. Then:

ERROR:Cannot export state from a module if it is reassigned. Either export a function returning the state value or only mutate the state value's properties

https://svelte.dev/e/state_invalid_export

Then they read https://svelte.dev/e/state_invalid_export

The website content:
state_invalid_export
Cannot export state from a module if it is reassigned. Either export a function returning the state value or only mutate the state value's properties

They don't know what function returning means

So they try:

export let r = $state(0);
export let getR = () => r;

and:

<script lang="ts">
  import { getR } from "./use-rune.svelte";
</script>
<button on:click={() => getR()+=1}>{getR()}</button>
ERROR: Assigning to rvalue https://svelte.dev/e/js_parse_error

Then they are confused and read all the documents

Then they find the document https://svelte.dev/docs/svelte/ $state#Passing-state-across-modules

export let r = $state({ value: 0 });

export function increment() {
  r.value += 1;
}

It works, but they don't like to define increment.

Final

They change the code to:

export let r = $state({ value: 0 });

Describe the proposed solution

I think it's better to create $stateValue, $stateValue(xxx) = $state({ value: xxx });

Importance

nice to have

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      TMZ Celebrity News – Breaking Stories, Videos & Gossip

      Looking for the latest TMZ celebrity news? You've come to the right place. From shocking Hollywood scandals to exclusive videos, TMZ delivers it all in real time.

      Whether it’s a red carpet slip-up, a viral paparazzi moment, or a legal drama involving your favorite stars, TMZ news is always first to break the story. Stay in the loop with daily updates, insider tips, and jaw-dropping photos.

      🎥 Watch TMZ Live

      TMZ Live brings you daily celebrity news and interviews straight from the TMZ newsroom. Don’t miss a beat—watch now and see what’s trending in Hollywood.