Skip to content

Expose a $state contract for use outside of .svelte.js and .svelte filesΒ #15011

@SystemParadox

Description

@SystemParadox

Describe the problem

We have a fairly substantial application framework that heavily uses observables (as-in knockout style). Svelte's stores are an amazing fit - we made our observables implement the store contract and mostly this works great - with one exception: the fact that the syntax doesn't allow for nested stores, e.g. you can't do foo.$bar.

When svelte 5 was announced with $state and using proxies/getters I was sure this would allow us to fix this problem and everything would be perfect. Obviously $state itself is a compile-time transform, but I'm really surprised to find that there doesn't seem to be any kind of "contract" I can implement in a non-svelte object to make it observable to svelte as if I had used $state.

Describe the proposed solution

A documented "contract" (similar to the store contract) for making arbitrary objects reactive to svelte, without having to use $state and .svelte.js files, or import svelte internals.

Importance

would make my life easier

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