-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
feat: allow modifiying derived props #10080
Conversation
🦋 Changeset detectedLatest commit: 1794b0f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
This comment was marked as outdated.
This comment was marked as outdated.
I have also come across this with e.g. editing a selected object from a list via some key. E.g. const items = $state([
{ text: 'Item 1' },
{ text: 'Item 2' },
{ text: 'Item 3' },
]);
let index = $state(0);
const current = $derived(items[index]);
const onClearCurrent = () => {
current.text = ''; // error
}; Would be in favor of allowing this. @Prinzhorn But as dummdidumm pointed out, creating this inconsistency is already possible in various ways, including bindings and some indirection. |
I assumed this PR was about removing this restriction. If it's only about mutating derived objects then ignore my comment above. |
It's an unnecessary restruction because it can be worked around (hide it behind a getter/setter), already works for bind:x and prevents valid use cases
Started this when looking into #9998 and thinking
$derived
is necessary - turns out it's not, but I thought I'd create this PR anyway and put it up for discussion whether or not this should be allowed.Pros:
$derived
behind a getter and then the validation wouldn't catch it anywaybind:x
caseCons:
Personally I lean towards relaxing this rule.
Before submitting the PR, please make sure you do the following
feat:
,fix:
,chore:
, ordocs:
.Tests and linting
pnpm test
and lint the project withpnpm lint