Force dependencies in autorun

I have an autorun that needs to be run when a collection changes but the collection is not used in the autorun, instead an external function is called.

this.autorun(() => {
  const data = Data.find()
  data.forEach(v => { console.log()})
  this.refresh()
})

refresh : () => {       
    const data = Data.find()
    data.forEach (...)
})

The only way I found to make the autorun react to a change in the data collection was to add the useless line

  data.forEach(v => { console.log()})

Is there a better way to do that ?

Could you explain a bit more what you are trying to achieve ?
I don’t understand what get_collection is, and why it is called both in your autorun and refresh function. BTW, what is your refresh function for ?

[removed get_collection : name => collection]

It’s because fullcalendar.io provides 2 callbacks to update it’s content

  • get_data() : tells full calendar where to get the data
  • refresh() : tells full calendar to rerun get_data

Therefore my code looks like this

get_data : () { 
   const data = Data.find().fetch()
   // give data to fullcalendar.io
}

autorun () => {
  const data = Data.find()
  data.forEach(v => { console.log()}) // if not present, autorun doesn't run
  refresh()
}

This behaviour is documented here: http://docs.meteor.com/api/collections.html#mongo_cursor

If you read through the methods and their reactive properties, you could use the equally useless (although slightly less annoying) line:

data.fetch();

As @vjau says - what are you trying to achieve? You may be able to use observe/observeChanges to rerun the refresh.

1 Like

I need to call refresh() every time the data changes in order for fullcalendar.io to refresh it’s display.
I will try to do it with observe