Skip to content

Commit

Permalink
Clear play animation timer
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Jan 6, 2020
1 parent fddd2b9 commit d2d2e03
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/controls/src/widget_int.ts
Original file line number Diff line number Diff line change
Expand Up @@ -802,28 +802,33 @@ class PlayModel extends BoundedIntModel {
this.set('value', this.get('min'));
this.schedule_next();
} else {
this.set('playing', false);
this.pause();
}
}
this.save_changes();
}

schedule_next() {
window.setTimeout(this.loop.bind(this), this.get('interval'));
this._timerId = window.setTimeout(this.loop.bind(this), this.get('interval'));
}

stop() {
this.set('playing', false);
this.pause();
this.set('value', this.get('min'));
this.save_changes();
}

pause() {
window.clearTimeout(this._timerId);
this._timerId = null;
this.set('playing', false);
this.save_changes();
}

animate() {
if (this._timerId !== null) {
return;
}
if (this.get('value') === this.get('max')) {
// if the value is at the end, reset it first, and then schedule the next
this.set('value', this.get('min'));
Expand All @@ -847,6 +852,8 @@ class PlayModel extends BoundedIntModel {
this.set('_repeat', !this.get('_repeat'));
this.save_changes();
}

private _timerId: number | null = null;
}

export
Expand Down

0 comments on commit d2d2e03

Please sign in to comment.