This is a playground
to test code. It runs a full Node.js
environment and already has all of npm
’s 1,000,000+ packages pre-installed, including debounce-promise
with all npm
packages installed. Try it out:
const debounce = require('debounce-promise')
function expensiveOperation (value, delay) {
return Promise.resolve(value)
}
// Simple example
{
const saveCycles = debounce(expensiveOperation, 100);
[1, 2, 3, 4].forEach(num => {
return saveCycles('call no #' + num).then(value => {
console.log(value)
})
})
}
// With leading=true
{
const saveCycles = debounce(expensiveOperation, 100, {leading: true});
[1, 2, 3, 4].forEach(num => {
return saveCycles('call no #' + num).then(value => {
console.log(value)
})
})
}
// With accumulate=true
{
function squareValues (values) {
return Promise.all(values.map(val => val * val))
}
const square = debounce(squareValues, 100, {accumulate: true});
[1, 2, 3, 4].forEach(num => {
return square(num).then(value => {
console.log(value)
})
})
}
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.