jeudi 27 août 2015

Correct way to destroy a slider instance in willDestroyElement callback

Within an Ember component I am instantiating a slider ( http://ift.tt/1lwYnrc ) and trying to clean it up when then component is destroyed. My setup and tear down functions are:

didInsertElement: function() {
  let component = this;
  let elem = component.$().find('.slider')[0];

  let slider = Ember.$(elem).slider({
    ticks: [0, 20, 40, 60, 80, 100],
    ticks_labels: ['0','20','40','60','80','100'],
    ticks_snap_bounds: 5,
    range: true
  });
  let min = parseInt(component.get('min')),
      max = parseInt(component.get('max'));

  slider.slider('setValue', [ min, max ], true, false);

  slider.on('change', function(evt) {
    component.set('last', evt.value.newValue);
    Ember.run.debounce(component, component.sendScores, 200);
  });

  component.set('slider', slider);
},

willDestroyElement: function() {
  console.log(this);
  console.log(this.get('slider'));
  this.get('slider').destroy();
}

The problem is that I'm getting a Uncaught TypeError: this.get(...).destroy is not a function exception tear down.

The specific question: what am I doing wrong here so the destroy() method is unavailable.

The general question is: should I be storing a "handle" to my slider instance as an Ember property and retrieving it like this or is there a better way?




Aucun commentaire:

Enregistrer un commentaire