3.1.5 • Published 3 years ago
throttle-and-debounce v3.1.5
throttle-and-debounce
INSTALL
# with npm
npm install throttle-and-debounce
# with yarn
yarn add throttle-and-debounce
QUICK START
javascript
import { throttle } from 'throttle-and-debounce';
const app = document.getElementById('app');
const callback = function(ev) {
console.log(ev);
};
const listener = throttle(callback);
app.addEventListener('click', listener);
typescript
import { throttle } from 'throttle-and-debounce';
const app = document.getElementById('app')
const callback = function(ev: MouseEvent) {
console.log(ev)
}
const listener = throttle(callback)
app!.addEventListener('click', listener)
with Vue2
import { debounce } from 'throttle-and-debounce'
export default {
data() {
return {
debouncedHandleWindowScroll: debounce(this.handleScroll, 200, 'window'),
debouncedHandleDocumentScroll: debounce(this.handleScroll, 200, 'document'),
}
},
mounted() {
window.addEventListener('scroll', this.debouncedHandleWindowScroll)
document.addEventListener('scroll', this.debouncedHandleDocumentScroll)
},
beforeDestroy() {
window.removeEventListener('scroll', this.debouncedHandleWindowScroll)
document.removeEventListener('scroll', this.debouncedHandleDocumentScroll)
},
methods: {
handleScroll(event, type) {
console.log(event)
console.log(type)
},
},
}
3.1.5
3 years ago
3.1.3
3 years ago
3.1.2
3 years ago
3.1.1
3 years ago
3.1.0
3 years ago
3.1.4
3 years ago
3.0.3
4 years ago
3.0.2
4 years ago
3.0.1
4 years ago
3.0.0
4 years ago
2.2.1
4 years ago
2.2.0
4 years ago
2.1.0
4 years ago
2.0.3
4 years ago
2.0.2
4 years ago
2.0.1
4 years ago
2.0.0
4 years ago
1.0.1
5 years ago
1.0.0
5 years ago
0.0.2
5 years ago
0.0.1
5 years ago