diff --git a/packages/controls/src/widget_int.ts b/packages/controls/src/widget_int.ts index 840aa662e0..2ec4f580b9 100644 --- a/packages/controls/src/widget_int.ts +++ b/packages/controls/src/widget_int.ts @@ -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')); @@ -846,6 +851,8 @@ class PlayModel extends BoundedIntModel { this.set('_repeat', !this.get('_repeat')); this.save_changes(); } + + private _timerId: number | null = null; } export