Meteor jquery-ui slider integration I'm struggling to integrate a jquery-ui slider widget into my Meteor app. The idea is to have a slider value in a Mongo collection and the slider needs to be reactive (automatically synced between clients). I've achieved this and it works but the implementation is not very elegant and clean. It's quite hard to maintain, test and extend such code. I've achieved this via Tracker.autorun and jquery slider slide handle (_.throttle is used to limit mongo update interval).

I'm new to Meteor, and it's awesome, but so far couldn't find better way to implement this (which I bet exists):

Live example

Slider = new Meteor.Collection("Slider");

if (Meteor.isClient) {
    Template.slide.rendered = function() {
        var handler = _.throttle(function(event, ui) {
            var val = Slider.findOne({});
            Slider.update({ _id: val._id }, {$set: {slide: ui.value}});
        }, 50, { leading: false });

        if (!this.$('#slider').data('uiSlider')) {
            $("#slider").slider({
                 slide: handler
            });
        }

        Tracker.autorun(function() {
            var slider = Slider.findOne({});
            if (slider) {
                this.$('#slider').data('uiSlider').value(slider.slide);
            }
        });
    };
}

//seed Collection
if (Meteor.isServer) {
    if (Slider.find().count() == 0) {
        Slider.insert({
            slide: 20
        });
    }
}


HTML

&lt;body&gt;
    &lt;h1&gt;jquery-ui slider test&lt;/h1&gt;
   {{&gt; slide}}
&lt;/body&gt;

&lt;template name="slide"&gt;
    &lt;div id="slider"&gt;&lt;/div&gt;
&lt;/template&gt;
I think you can avoid the Tracker.autorun completely by updating the value in a template helper -- this is possible because your data is coming from a Collection, so it's already reactive.  You can play around with it in this MeteorPad, but a brief summary follows:

&lt;!--HTML--&gt;
&lt;template name="slider"&gt;
  &lt;div id="slider"&gt;&lt;/div&gt;
  Slider's current value is...{{sliderVal}}&lt;!-- You could get rid of this and just do {{sliderVal}} and have that return nothing if you want no text--&gt;
&lt;/template&gt;

//JS -- ommitted the rendered bit, which looks identical to yours w/o the Tracker.autorun
Template.slider.helpers({
  sliderVal:  function() { 
    var slider = Slider.findOne(); // this guy is reactive, so when another client updates the Collection, it'll get pushed to us
    if (slider) {           Template.instance().$('#slider').data('uiSlider').value(slider.slide); // Template.instance() b/c `this` doesn't return a template instance in a helper
      return slider.slide; // again, here you can return nothing if you'd rather have no text
    }
  }
});