Comments (8)
I can open a PR for this, as soon as the maintainer is fine making it return a Promise only when it's available on the runtime environment. In other words, if you are using oldIE then you don't get a Promise as a result if you don't load a polyfill. That also looks backwards compatible.
from debounce.
It might be worth it as a separate package at that point, tbh.
from debounce.
The first use of the debounced function which should return a promise was returning undefined
import debounce from 'debounce'
const search = (search) => {
return new Promise((resolve,reject)=>{
// ...
resolve(res.data)
})
}
const searchDebounce = debounce(search, 250)
searchDebounce("foobar").then() // threw error, promise wasn't returned, undefined was returned
// sometime later
searchDebounce("foobar").then() // working as intended
I was able to work around the issue by switching out debounce for debouce-promise.
https://github.com/bjoerge/debounce-promise
from debounce.
That's the difference between debounce and throttle.
from debounce.
So this issue seems to be alive.
Back then I ended up publishing debounce-with-result.
from debounce.
This seems like a 100% reasonable thing to expect from this library. I'll make sure I have permissions to do so tomorrow and try to get a working version published to npm.
EDIT - PR welcome. Will merge and publish, but the change is more involved than I need to be in this library right now (only incidentally stumbled upon this issue :/)
from debounce.
I mean, if https://github.com/bjoerge/debounce-promise does what we want, we don't need to over-complicate this library and just add a mention in the README.md. Unless the maintainers really care about this feature!
from debounce.
I don't think promise supports needs to live in this package. There's debounce-promise
as mentioned above and also my p-debounce
package.
from debounce.
Related Issues (16)
- Debounced function executing early? HOT 2
- Proper testing HOT 2
- Usage of 'date-now' actually makes this harder to test with Jasmine HOT 4
- Protect against improper use HOT 1
- Provide a way to cancel scheduled debounces HOT 3
- Add raf support HOT 1
- npm version out of date HOT 6
- Allow ES-style import { debounce } from "debounce"? HOT 11
- Allow injecting a custom setTimeout? HOT 2
- can not call my func right now? HOT 2
- arguments get reset if you call debounced function within itself HOT 1
- snowpack failed to compile. 'debounce' is not exported by node_modules/debounce/index.js, HOT 6
- debounce and throttle seems to decrease performance for window.onscroll HOT 1
- Run debounce() callback if browser tab is closed HOT 1
- Need an esm module
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from debounce.