Make ve.dm.Surface.{start,stop}HistoryTracking idempotent.

Add a little robustness, guaranteeing that we don't end up with multiple
history tracking tasks running, leaking one, or try to clear a non-running
interval.

Change-Id: I41db2d6fefc7f45f150aa14ecefc648760ad6200
This commit is contained in:
C. Scott Ananian 2013-08-27 09:31:26 -04:00 committed by Roan Kattouw
parent 3f7761d242
commit 4fee78227d

View file

@ -101,7 +101,9 @@ ve.dm.Surface.prototype.startHistoryTracking = function () {
if ( !this.enabled ) {
return;
}
this.historyTrackingInterval = setInterval( ve.bind( this.breakpoint, this ), 750 );
if ( this.historyTrackingInterval === null ) {
this.historyTrackingInterval = setInterval( ve.bind( this.breakpoint, this ), 750 );
}
};
/**
@ -113,7 +115,10 @@ ve.dm.Surface.prototype.stopHistoryTracking = function () {
if ( !this.enabled ) {
return;
}
clearInterval( this.historyTrackingInterval );
if ( this.historyTrackingInterval !== null ) {
clearInterval( this.historyTrackingInterval );
this.historyTrackingInterval = null;
}
};
/**