You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, first of all thanks for everything provided so far 😃
Please describe what the rule should do:
Reports when trying to emit a ref itself, instead of emitting the value of the ref.
What category should the rule belong to?
Enforces code style (layout)
Warns about a potential error (problem)
Suggests an alternate way of doing something (suggestion)
Other (please specify:)
Provide 2-3 code examples that this rule should warn about:
Example 1
<template>
<button@click="increment">Increment</button>
</template>
<script setup>
import { ref } from vueconstemit=defineEmits(['incremented'])constcounter=ref(0)functionincrement() {counter.value++/* Probably an error, trying to emit a ref instead of it's value. */emit('incremented', counter) /* ✗ BAD */emit('incremented', counter.value) /* ✓ GOOD */}
</script>
Example 2
<template>
<button@click="counterA++">Increment A</button>
<button@click="counterB++">Increment B</button>
</template>
<script setup>
import { ref, computed, watch } from vueconstemit=defineEmits(['updated'])constcounterA=ref(0)constcounterB=ref(0)constresult=computed(() => ({ a:counterA.value, b:counterB.value,}))watch(result, () => {/* Probably an error, trying to emit a ref instead of it's value. Additionally, the parent might try to mutate the emitted value in this case where it should be a plain object but is instead a computed ref. Ideally we would use the argument provided by the watcher in this specific case though.*/emit('updated', result) /* ✗ BAD */emit('updated', result.value) /* ✓ GOOD */})
</script>
Additional context
I couldn't think of any usecase that's not against Vue recommendations where emitting the ref itself would be justified, but
if there is any feel free to discard this rule proposal.
Maybe this functionality can be added to no-ref-as-operand instead of creating a new rule as it is quite similar ?
The text was updated successfully, but these errors were encountered:
Hmm. Personally, I would be happy to include that check in vue/no-ref-as-operand, but since the vue/no-ref-as-operand rule is in the essentials category, it might be better to implement it as a separate rule or vue/no-ref-as-operand rule option. Some users might consider it a matter of preference.
Hello, first of all thanks for everything provided so far 😃
Please describe what the rule should do:
Reports when trying to emit a ref itself, instead of emitting the value of the ref.
What category should the rule belong to?
Provide 2-3 code examples that this rule should warn about:
Example 1
Example 2
Additional context
I couldn't think of any usecase that's not against Vue recommendations where emitting the ref itself would be justified, but
if there is any feel free to discard this rule proposal.
Maybe this functionality can be added to
no-ref-as-operand
instead of creating a new rule as it is quite similar ?The text was updated successfully, but these errors were encountered: