Skip to content
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

$autorun should rely on reactive property to work #58

Open
red-meadow opened this issue Jun 3, 2019 · 0 comments
Open

$autorun should rely on reactive property to work #58

red-meadow opened this issue Jun 3, 2019 · 0 comments

Comments

@red-meadow
Copy link

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.

@red-meadow red-meadow changed the title $autorun should rely on reacive property to work $autorun should rely on reactive property to work Jun 3, 2019
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

No branches or pull requests

1 participant