Skip to content

Commit

Permalink
Merge pull request #1 from sebbousquet/feature/improveMouseOverEvent
Browse files Browse the repository at this point in the history
Emit less times the mouseover event
  • Loading branch information
sebbousquet authored Apr 12, 2019
2 parents 2a0f84d + 22d54ca commit 503beee
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mapbox/mapbox-gl-draw",
"version": "1.1.1",
"name": "@gisaia-team/mapbox-gl-draw",
"version": "1.1.2",
"description": "A drawing component for Mapbox GL JS",
"homepage": "https://github.com/mapbox/mapbox-gl-draw",
"author": "mapbox",
Expand Down
4 changes: 2 additions & 2 deletions src/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ module.exports = function(ctx) {
}
currentModeName = modename;
const mode = modebuilder(ctx, nextModeOptions);
currentMode = setupModeHandler(mode, ctx);
currentMode = setupModeHandler(mode, currentModeName, ctx);

if (!eventOptions.silent) {
ctx.map.fire(Constants.events.MODE_CHANGE, { mode: modename});
Expand Down Expand Up @@ -203,7 +203,7 @@ module.exports = function(ctx) {
const api = {
start: function() {
currentModeName = ctx.options.defaultMode;
currentMode = setupModeHandler(modes[currentModeName](ctx), ctx);
currentMode = setupModeHandler(modes[currentModeName](ctx), currentModeName, ctx);
},
changeMode,
actionable,
Expand Down
8 changes: 5 additions & 3 deletions src/lib/mode_handler.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const ModeHandler = function(mode, DrawContext) {
const ModeHandler = function(mode, modename, DrawContext) {

const handlers = {
drag: [],
Expand Down Expand Up @@ -38,7 +38,7 @@ const ModeHandler = function(mode, DrawContext) {
const handle = handles[iHandle];
if (handle.selector(event)) {
handle.fn.call(ctx, event);
DrawContext.store.render();
if (handle.fn.render !== false) DrawContext.store.render();
DrawContext.ui.updateMapClasses();

// ensure an event is only handled once
Expand Down Expand Up @@ -79,7 +79,9 @@ const ModeHandler = function(mode, DrawContext) {
delegate('click', event);
},
mousemove: function(event) {
delegate('mousemove', event);
if (modename !== 'simple_select' && modename !== 'direct_select' && modename !== 'limit_vertex') {
delegate('mousemove', event);
}
},
mousedown: function(event) {
delegate('mousedown', event);
Expand Down
10 changes: 5 additions & 5 deletions test/mode_handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ test('ModeHandler calling mode.start with context, and delegation functionality'
});
const drawContext = createMockModeHandlerContext();

const mh = modeHandler(mode, drawContext);
const mh = modeHandler(mode, 'mode.start', drawContext);
t.equal(handleStartSpy.callCount, 1, 'start was called on mode handler creation');
t.equal(typeof startContext.on, 'function', 'start context has on()');
t.equal(typeof startContext.render, 'function', 'start context has render()');
Expand Down Expand Up @@ -137,7 +137,7 @@ test('ModeHandler calling mode.start with context, and delegation functionality'

test('ModeHandler#stop calling mode.stop', t => {
const mode = createMockMode();
const mh = modeHandler(mode, createMockModeHandlerContext());
const mh = modeHandler(mode, 'mode.stop', createMockModeHandlerContext());

mh.stop();
t.equal(mode.stop.callCount, 1, 'mode.stop called');
Expand All @@ -148,7 +148,7 @@ test('ModeHandler#stop calling mode.stop', t => {
test('ModeHandler#stop not calling nonexistent mode.stop', t => {
const mode = createMockMode();
delete mode.stop;
const mh = modeHandler(mode, createMockModeHandlerContext());
const mh = modeHandler(mode, 'mode.stop', createMockModeHandlerContext());

t.doesNotThrow(() => {
mh.stop();
Expand All @@ -160,7 +160,7 @@ test('ModeHandler#stop not calling nonexistent mode.stop', t => {
test('Modehandler#trash', t => {
const mode = createMockMode();
const drawContext = createMockModeHandlerContext();
const mh = modeHandler(mode, drawContext);
const mh = modeHandler(mode, 'mode.trash', drawContext);

mh.trash();
t.equal(mode.trash.callCount, 1, 'mode.trash called');
Expand All @@ -173,7 +173,7 @@ test('Modehandler#trash without a mode.trash', t => {
const mode = createMockMode();
delete mode.trash;
const drawContext = createMockModeHandlerContext();
const mh = modeHandler(mode, drawContext);
const mh = modeHandler(mode, 'mode.trash', drawContext);

t.doesNotThrow(() => {
mh.trash();
Expand Down

0 comments on commit 503beee

Please sign in to comment.