Skip to content

Commit d2d2e03

Browse files
committed
Clear play animation timer
1 parent fddd2b9 commit d2d2e03

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

packages/controls/src/widget_int.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -802,28 +802,33 @@ class PlayModel extends BoundedIntModel {
802802
this.set('value', this.get('min'));
803803
this.schedule_next();
804804
} else {
805-
this.set('playing', false);
805+
this.pause();
806806
}
807807
}
808808
this.save_changes();
809809
}
810810

811811
schedule_next() {
812-
window.setTimeout(this.loop.bind(this), this.get('interval'));
812+
this._timerId = window.setTimeout(this.loop.bind(this), this.get('interval'));
813813
}
814814

815815
stop() {
816-
this.set('playing', false);
816+
this.pause();
817817
this.set('value', this.get('min'));
818818
this.save_changes();
819819
}
820820

821821
pause() {
822+
window.clearTimeout(this._timerId);
823+
this._timerId = null;
822824
this.set('playing', false);
823825
this.save_changes();
824826
}
825827

826828
animate() {
829+
if (this._timerId !== null) {
830+
return;
831+
}
827832
if (this.get('value') === this.get('max')) {
828833
// if the value is at the end, reset it first, and then schedule the next
829834
this.set('value', this.get('min'));
@@ -847,6 +852,8 @@ class PlayModel extends BoundedIntModel {
847852
this.set('_repeat', !this.get('_repeat'));
848853
this.save_changes();
849854
}
855+
856+
private _timerId: number | null = null;
850857
}
851858

852859
export

0 commit comments

Comments
 (0)