Skip to content

Add prefer-reactive-destructuring rule #205

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

Closed
wants to merge 4 commits into from

Conversation

tivac
Copy link
Collaborator

@tivac tivac commented Jul 31, 2022

From the docs:


This rule triggers whenever a reactive statement contains an assignment that could be rewritten using destructuring. This is beneficial because it allows svelte's change-tracking to prevent wasteful redraws whenever the object is changed.

This svelte REPL example shows just how effective this can be at preventing bogus redraws.

<script>
  /* eslint svelte/prefer-reactive-destructuring: "error" */
  /* ✓ GOOD */
  $: ({ foo } = info)
  $: ({ bar: baz } = info)

  /* ✗ BAD */
  $: foo = info.foo
  $: baz = info.bar
</script>

@ota-meshi
Copy link
Member

I've noticed that sometimes what the rule report doesn't lead to a reduction in render times.
I think the documentation might need to be fixed.

See #208 (comment)

export default createRule("prefer-reactive-destructuring", {
meta: {
docs: {
description: "Prefer destructuring from objects in reactive statements",
Copy link
Contributor

Choose a reason for hiding this comment

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

The first letter should be lowercase to be consistent with existing rules. (see #218)

@baseballyama
Copy link
Member

baseballyama commented Sep 5, 2022

@tivac What are the remaining tasks of the PR? I can do the remaining tasks if you need.

@tivac
Copy link
Collaborator Author

tivac commented Sep 6, 2022

@baseballyama Needs to be changed to a stylistic rule and any remaining comments need to be addressed (I think it's just capitalization nit?). Seems like either svelte has improved object access change tracking or my initial tests when I wrote these rules years ago were faulty 🤷🏻‍♂️ So this is really a style preference over a perf thing.

@baseballyama
Copy link
Member

baseballyama commented Sep 12, 2022

I checked this rule well, and now I understand this rule doesn't have an impact on rendering frequency.
And already ESLint can report destructuring through prefer-destructuring rule.

So I think even in terms of styling, I don't think we need to add this rule.
Now I tried to update this PR, but before that, I would like to clarify the needs of this rule.

@ota-meshi
Copy link
Member

Thank you for the explanation.

And already ESLint can report destructuring through prefer-destructuring rule.
So I think even in terms of styling, I don't think we need to add this rule.

You are right. So I will close this PR.

@ota-meshi ota-meshi closed this Sep 13, 2022
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.

4 participants