Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: add setter to$derived class fields#15628

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Rich-Harris merged 1 commit intosveltejs:mainfromOcean-OS:derived-setter
Mar 31, 2025

Conversation

Ocean-OS
Copy link
Contributor

Fixes#15621 by adding a setter to$derived class fields.

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC:https://github.com/sveltejs/rfcs
  • Prefix your PR title withfeat:,fix:,chore:, ordocs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code withinpackages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests withpnpm test and lint the project withpnpm lint

max-got reacted with thumbs up emoji
@changeset-botchangeset-bot
Copy link

🦋 Changeset detected

Latest commit:03d035a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
NameType
sveltePatch

Not sure what this means?Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@svelte-docs-bot
Copy link

@github-actionsGitHub Actions
Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@15628

@dummdidumm
Copy link
Member

Looks good - add a test and we can merge this 👍

Ocean-OS reacted with thumbs up emoji

@Ocean-OS
Copy link
ContributorAuthor

Just realized I haven't implemented this on the server, how should I go about doing that? I'm not sure if we should allow setting it, or if we should have a helper function for it. I'm thinking more towards a helper function, that'd look like this:

functionserver_derived(fn){letvalue;letcomputed_wv=1;letwrite_wv=1;letlast_computed_value;letwv=1;functionread(){if(computed_wv<write_wv){letval=fn();if(val!==last_computed_value){value=val;computed_wv=++wv;last_computed_value=val;}}if(write_wv===1){if(computed_wv===1){value=fn();computed_wv=++wv;last_computed_value=value;}else{letval=fn();if(val!==last_computed_value){value=val;computed_wv=++wv;last_computed_value=val;}}}returnvalue;}functionwrite(next){write_wv=++wv;value=next;}return[read,write];}

@dummdidumm
Copy link
Member

@paoloricciuti started something related in#14977, maybe it's best to not worry about writable derived class fields for now (if you eagerly update them during server rendering, then wtf are you even doing) and incorporate that into#14977 instead.

Ocean-OS reacted with thumbs up emoji

@Rich-HarrisRich-Harris merged commitec91cac intosveltejs:mainMar 31, 2025
9 checks passed
@github-actionsgithub-actionsbot mentioned this pull requestMar 31, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@Rich-HarrisRich-HarrisRich-Harris approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Add setter to $derived property
3 participants
@Ocean-OS@dummdidumm@Rich-Harris

[8]ページ先頭

©2009-2025 Movatter.jp