Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Svelte 5: $state proxying opt-out mechanism #9762

Closed
Rich-Harris opened this issue Dec 4, 2023 · 3 comments
Closed

Svelte 5: $state proxying opt-out mechanism #9762

Rich-Harris opened this issue Dec 4, 2023 · 3 comments

Comments

@Rich-Harris
Copy link
Member

Describe the problem

In some cases, the app developer may know that they don't need deep reactivity. To wring out maximum performance, it would be kind to offer a way to opt out of that behaviour.

Describe the proposed solution

let object = $state.raw({
  count: 0
});

// has no effect! `object` properties are not reactive
object.count += 1; 

// works as expected
object = { ...object, count: object.count + 1 };

We would need to add a Symbol to the object passed in to $state.raw, so that it isn't later made reactive if someone does this:

let big_old_bag_of_reactivity = $state({...});
big_old_bag_of_reactivity.object = object;

Alternatives considered

$state.freeze, $state.shallow, etc

Importance

nice to have

@srav001
Copy link

srav001 commented Dec 15, 2023

Just wondering, wouldn't $state.shallow be more clear to understand than .raw ?

@Conduitry
Copy link
Member

After considering a couple other names $state.frozen is the one currently being used in PR #9851.

@benmccann
Copy link
Member

Implemented in #9851

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants