Reputation: 433
I have the autorun function in rendered callback:
Template.drawFlow.rendered = ->
outerData = this
this.autorun ->
# do some work here using reactive collections
s = Session.get("redrawLines")
connectRecursive outerData.data.tasks, outerData.data.startTask
What I want is that on data change in this.autorun to reexecute the function. Right now it doesn't do it, so I am wondering why.
Update updated the code above, and also, on some events I do:
Session.set('redrawLines', moment())
which should invalidate the computation inside the autorun function. Also, the "outerData" variable should be reactive, as it's from "data" section of the IronRouter.
Upvotes: 0
Views: 48
Reputation: 433
Final working code, which fires after DOM is finshed (as opposed to my solution):
Template.drawFlow.onRendered ->
console.log "Template.drawFlow.onRendered"
this.autorun ->
data = Router.current().data()
Tracker.afterFlush ->
console.log "dom is now created"
Upvotes: 0
Reputation: 573
this.autorun is a reactive computation, but you need a reactive source within that autorun function in order for the view to be rendered upon update of that data.
Reactive sources in Meteor include Session variables, cursors, Meteor.user, and more. Here's a good read that should help you out:
https://www.discovermeteor.com/blog/reactivity-basics-meteors-magic-demystified/
Hope that helps.
Upvotes: 2