Skip to content

fix: make immutable option work more correctly #13526

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

Merged
merged 1 commit into from
Oct 9, 2024

Conversation

dummdidumm
Copy link
Member

  • make sure to not overfire before/afterUpdate
  • make sure to not fire mutable sources when they were mutated
  • only show deprecation warning when in runes mode to not clutter up console (this is in line with how we made it in other places)

fixes #13454

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 with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

- make sure to not overfire before/afterUpdate
- make sure to not fire mutable sources when they were mutated
- only show deprecation warning when in runes mode to not clutter up console (this is in line with how we made it in other places)

fixes #13454
Copy link

changeset-bot bot commented Oct 8, 2024

🦋 Changeset detected

Latest commit: 54033fa

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

This PR includes changesets to release 1 package
Name Type
svelte Patch

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

let props = () => deep_read_state(context.s);

if (immutable) {
let version = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a source?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's used in the derived, and the derived then does equality checks to see whether or not the version has changed. If we had the possibility of accessing the current/previous value within the derived I would do that instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oooooh gotcha...thanks for the explanation

* @returns {Source<V>}
*/
/*#__NO_SIDE_EFFECTS__*/
export function mutable_source(initial_value) {
export function mutable_source(initial_value, immutable = false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than doing this, can't we just use the non-mutable source instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, because this method additionally adds the source to the before/afterUpdate array, which is necessary in legacy mode

@dummdidumm dummdidumm merged commit 6ed3ca3 into main Oct 9, 2024
9 checks passed
@dummdidumm dummdidumm deleted the immutable-option-fixes branch October 9, 2024 13:03
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

Successfully merging this pull request may close these issues.

Immutable option doesn't work
3 participants