Skip to content

Commit

Permalink
cleanup2
Browse files Browse the repository at this point in the history
  • Loading branch information
kepta committed Aug 24, 2017
1 parent 87f4cc3 commit 860aee5
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
12 changes: 6 additions & 6 deletions modules/renderer/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,24 +65,24 @@ export function rendererMap(context) {
.on('zoom', zoomPan);

var _selection = d3.select(null);
var isRenderScheduled = false;
var isRedrawScheduled = false;
var pendingRedrawCall;

function scheduleRedraw() {
// Only schedule the redraw if one has not already been set.
if (isRenderScheduled) return;
isRenderScheduled = true;
if (isRedrawScheduled) return;
isRedrawScheduled = true;
var that = this;
var args = arguments;
pendingRedrawCall = requestIdleCallback(function () {
// Reset the boolean so future redraws can be set.
isRenderScheduled = false;
isRedrawScheduled = false;
redraw.apply(that, args);
}, { timeout: 1400 });
}

function cancelPendingRedraw() {
isRenderScheduled = false;
isRedrawScheduled = false;
window.cancelIdleCallback(pendingRedrawCall);
}

Expand Down Expand Up @@ -286,7 +286,7 @@ export function rendererMap(context) {
.call(drawLabels, graph, data, filter, dimensions, !difference && !extent)
.call(drawPoints, graph, data, filter);

dispatch.call('drawn', this, {full: true});
dispatch.call('drawn', this, {full: true});
}


Expand Down
2 changes: 1 addition & 1 deletion modules/util/call_when_idle.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export function utilCallWhenIdle(func, timeout) {
func.apply(that, args);
}, {timeout: timeout});
};
}
}
25 changes: 25 additions & 0 deletions modules/util/idle_debounce.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
export function utilIdleDebounce(func) {
var timeout, timestamp;
var wait = 99;
var run = function(){
timeout = null;
func();
};
var later = function() {
var last = Date.now() - timestamp;

if (last < wait) {
setTimeout(later, wait - last);
} else {
(requestIdleCallback || run)(run);
}
};

return function() {
timestamp = Date.now();

if (!timeout) {
timeout = setTimeout(later, wait);
}
};
};
2 changes: 1 addition & 1 deletion modules/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ export { utilTagText } from './util';
export { utilTriggerEvent } from './trigger_event';
export { utilWrap } from './util';
export { utilIdleWorker} from './idle_worker';
export { utilCallWhenIdle } from './call_when_idle';
export { utilCallWhenIdle } from './call_when_idle';

0 comments on commit 860aee5

Please sign in to comment.