From fc9fbbe3905ceb7134a764e6798136b10643b353 Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Mon, 18 Sep 2017 22:01:33 -0400 Subject: [PATCH] Disable mode buttons on leading and trailing debounce --- modules/ui/modes.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/modules/ui/modes.js b/modules/ui/modes.js index ab4bdb024..0787aa348 100644 --- a/modules/ui/modes.js +++ b/modules/ui/modes.js @@ -1,6 +1,7 @@ import * as d3 from 'd3'; import _ from 'lodash'; import { d3keybinding } from '../lib/d3.keybinding.js'; + import { modeAddArea, modeAddLine, @@ -53,12 +54,6 @@ export function uiModes(context) { }) ); - context.map() - .on('move.modes', _.debounce(update, 500)); - - context - .on('enter.modes', update); - buttons .each(function(d) { d3.select(this) @@ -102,6 +97,17 @@ export function uiModes(context) { .call(keybinding); + var debouncedUpdate = _.debounce(update, 500, { leading: true, trailing: true }); + + context.map() + .on('move.modes', debouncedUpdate) + .on('drawn.modes', debouncedUpdate); + + context + .on('enter.modes', update); + + + function update() { selection.selectAll('button.add-button') .property('disabled', !editable());