Open
Description
Recently I decided to switch to using computed properties returning this.$autorun()
instead of meteor
property, because of this #49 issue. But encountered another issue. Computed property returning this.$autorun()
becomes reactive only if it has any reactive property (data or props) inside function body. Here are two examples illustrating the issue:
<!-- non-reactive example, always 0 -->
<template><div>{{ nonReactiveItems.length }}</div></template>
<script>
const Items = new Mongo.Collection(null)
Meteor.setInterval(() => { Items.insert({}) }, 2000)
export default {
computed: {
nonReactiveItems() {
return this.$autorun(() => Items.find())
}
},
}
</script>
<!-- reactive example -->
<template><div>{{ reactiveItems.length }}</div></template>
<script>
const Items = new Mongo.Collection(null)
Meteor.setInterval(() => { Items.insert({}) }, 2000)
export default {
data() { return { anything: undefined } },
computed: {
reactiveItems() {
this.anything // This line enables reactivity
return this.$autorun(() => Items.find())
},
},
}
</script>
Now the question is whether it is an issue at all? The only provided example in docs relies on reactive this.sort
property, so probably it is an expected behavior? If so, we should update the README to make it clear.
Metadata
Metadata
Assignees
Labels
No labels