Skip to content

Commit

Permalink
fix: setInterval callbacks error when from inactive tabs to active ta…
Browse files Browse the repository at this point in the history
…bs (close #601)
  • Loading branch information
dongsik-yoo committed May 15, 2020
1 parent 37b1303 commit 210d6ac
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/js/view/week/timeGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,12 @@ function TimeGrid(name, options, panelElement) {
*/
this.timerID = 0;

/**
* requestAnimationFrame unique ID
* @type {number}
*/
this.rAnimationFrameID = 0;

/**
* @type {boolean}
*/
Expand Down Expand Up @@ -202,6 +208,7 @@ TimeGrid.prototype.viewName = 'timegrid';
TimeGrid.prototype._beforeDestroy = function() {
clearInterval(this.intervalID);
clearTimeout(this.timerID);
reqAnimFrame.cancelAnimFrame(this.rAnimationFrameID);

if (this._autoScroll) {
this._autoScroll.destroy();
Expand All @@ -210,7 +217,7 @@ TimeGrid.prototype._beforeDestroy = function() {
domevent.off(this.stickyContainer, 'click', this._onClickStickyContainer, this);

this._autoScroll = this.hourmarkers = this.intervalID =
this.timerID = this._cacheParentViewModel = this.stickyContainer = null;
this.timerID = this.rAnimationFrameID = this._cacheParentViewModel = this.stickyContainer = null;
};

/**
Expand Down Expand Up @@ -482,15 +489,16 @@ TimeGrid.prototype.refreshHourmarker = function() {
var hourmarkers = this.hourmarkers;
var viewModel = this._cacheParentViewModel;
var hoursLabels = this._cacheHoursLabels;
var rAnimationFrameID = this.rAnimationFrameID;
var baseViewModel;

if (!hourmarkers || !viewModel) {
if (!hourmarkers || !viewModel || rAnimationFrameID) {
return;
}

baseViewModel = this._getBaseViewModel(viewModel);

reqAnimFrame.requestAnimFrame(function() {
this.rAnimationFrameID = reqAnimFrame.requestAnimFrame(function() {
var needsRender = false;

util.forEach(hoursLabels, function(hoursLabel, index) {
Expand Down Expand Up @@ -524,6 +532,8 @@ TimeGrid.prototype.refreshHourmarker = function() {
}
});
}

this.rAnimationFrameID = null;
}, this);
};

Expand All @@ -533,7 +543,7 @@ TimeGrid.prototype.refreshHourmarker = function() {
TimeGrid.prototype.attachEvent = function() {
clearInterval(this.intervalID);
clearTimeout(this.timerID);
this.intervalID = this.timerID = null;
this.intervalID = this.timerID = this.rAnimationFrameID = null;

this.timerID = setTimeout(util.bind(this.onTick, this), (SIXTY_SECONDS - new TZDate().getSeconds()) * 1000);

Expand Down

0 comments on commit 210d6ac

Please sign in to comment.