How to use the ember-animated.task function in ember-animated

To help you get started, we’ve selected a few ember-animated examples, based on popular ways it is used in public projects.

github ember-animation / ember-animated-tools / addon / components / time-control.js View on Github external
willDestroyElement() {
    if (this.time) {
      this.time.finished();
      this.time = null;
    }
  },
  updateLogSpeed(event) {
    this._setSpeed(fromLogSpeed(event.target.valueAsNumber));
  },
  tickMarkChosen(tickMark) {
    this._setSpeed(tickMark.value);
  },
  _setSpeed(speed) {
    this.get('_speedSetter').perform(speed);
  },
  _speedSetter: task(function * (speed) {
    if (speed === 100) {
      // at normal speed, we want to disable our time control
      // entirely. This means we won't intefere with things like
      // acceptance tests that may already want to take over the
      // timing.
      //
      // But if there's an animation in progress, we must wait until
      // it's done. Otherwise there will be a jarring jump from our
      // fake time to the real time.
      if (this.time) {
        this.time.runAtSpeed(1);
        this.set('speedPercent', speed);
        yield this.get('motionService.waitUntilIdle').perform();
        this.time.finished();
        this.time = null;
      }