-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix interaction state when using mouse wheel (#840)
- Loading branch information
1 parent
ef5372f
commit c9daf7f
Showing
4 changed files
with
55 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* global setTimeout, clearTimeout */ | ||
/* eslint-disable consistent-this, func-names */ | ||
export default function debounce(func, delay) { | ||
let _this; | ||
let _arguments; | ||
let timeout; | ||
|
||
const executeNow = () => { | ||
timeout = null; | ||
return func.apply(_this, _arguments); | ||
}; | ||
|
||
return function() { | ||
_this = this; | ||
_arguments = arguments; | ||
|
||
if (timeout) { | ||
clearTimeout(timeout); | ||
} | ||
timeout = setTimeout(executeNow, delay); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* global setTimeout */ | ||
import test from 'tape-catch'; | ||
import debounce from 'react-map-gl/utils/debounce'; | ||
|
||
test('debounce', t => { | ||
const funcCalled = []; | ||
|
||
function func(x) { | ||
funcCalled.push({context: this, arg: x}); | ||
} | ||
|
||
const debounced = debounce(func, 1); | ||
|
||
debounced.call('0', 0); | ||
debounced.call('1', 1); | ||
debounced.call('2', 2); | ||
|
||
t.deepEquals(funcCalled, [], 'function is not called yet'); | ||
|
||
setTimeout(() => { | ||
t.deepEquals(funcCalled, [{context: '2', arg: 2}], 'function is called once'); | ||
t.end(); | ||
}, 5); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters