Skip to content

Commit

Permalink
Fix wrong readme example and add runkit example file
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Jan 28, 2017
1 parent 5cf6dcd commit 8dcc636
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ var saveCycles = debounce(expensiveOperation, 100, {leading: true});
})

//=> call no #1
//=> call no #1
//=> call no #1
//=> call no #1
//=> call no #4
//=> call no #4
//=> call no #4
```

### With accumulate=true
Expand Down
42 changes: 42 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
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)
})
})
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "3.0.0",
"description": "Create a debounced version of a promise returning function",
"main": "dist/index",
"runkitExampleFilename": "./example.js",
"scripts": {
"test": "tap --node-arg -r --node-arg babel-register --node-arg -r --node-arg babel-polyfill test && npm run lint",
"lint": "standard | snazzy",
Expand Down

0 comments on commit 8dcc636

Please sign in to comment.