How can I modify a ReactiveVar inside of a jQuery plugin event?


I have a ReactiveVar that I need to read from and modify inside of an initialized jQuery plugin. Unfortunately I can’t find a way to call my template’s context inside of the jQuery event callbacks. This is all client side. I can’t use a Session here. Here is some code:

Setup my var

   this.isPlaying = new ReactiveVar;

Init my jQuery plugin

Template.player.onRendered(function() {

relevant portion of initPlayer():

master = new TimelineMax({
    paused: true
master.eventCallback("onUpdate", function() {
        //Template.instance().isPlaying.set(false) //can't do this here
        //reactive variables in jquery events are out of scope?

I have tried running the init function in an autotracker without any luck. I know I could use a Session here but I really want a reactive variable that will be destroyed along with the template. Any ideas of how to model this?


Pass the current instance of your template to your init function :

Template.player.onRendered(function() {
initPlayer( this )

var initPlayer = function( template ){
template.isPlaying.set( value )


Thank you that does it!