Skip to content

Latest commit

 

History

History
55 lines (35 loc) · 1.62 KB

prefer-reactive-destructuring.md

File metadata and controls

55 lines (35 loc) · 1.62 KB
pageClass sidebarDepth title description
rule-details
0
svelte/prefer-reactive-destructuring
Prefer destructuring from objects in reactive statements

svelte/prefer-reactive-destructuring

Prefer destructuring from objects in reactive statements

  • This rule has not been released yet.

📖 Rule Details

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>

🔧 Options

Nothing

❤️ Compatibility

This rule was taken from @tivac/eslint-plugin-svelte.
This rule is compatible with @tivac/svelte/reactive-destructuring rule.

🔍 Implementation