Throttle and debounce

This commit is contained in:
Guillaume Chau
2017-01-08 03:12:48 +01:00
parent 5a25b1577b
commit 727db404bf
3 changed files with 29 additions and 3 deletions
+16
View File
@@ -0,0 +1,16 @@
import loThrottle from 'lodash.throttle'
import loDebounce from 'lodash.debounce'
function factory (action) {
return (cb, options) => {
if (typeof options === 'number') {
return action(cb, options)
} else {
return action(cb, options.wait, options)
}
}
}
export const throttle = factory(loThrottle)
export const debounce = factory(loDebounce)