fix: multi-repo local dev (file:../ deps, package exports, missing deps)
This commit is contained in:
+21
@@ -0,0 +1,21 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 Mathias Buus
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
# debounceify
|
||||
|
||||
Tiny async debouncer
|
||||
|
||||
```
|
||||
npm install debounceify
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
``` js
|
||||
const debounceify = require('debounceify')
|
||||
|
||||
const debounced = debounceify(async function () {
|
||||
console.log('Running...')
|
||||
await new Promise(resolve => setTimeout(1000, resolve))
|
||||
})
|
||||
|
||||
const a = debounced() // triggers the about function
|
||||
const b = debounced()
|
||||
const c = debounced()
|
||||
const d = debounced() // these last 3 wait for the first one to finish
|
||||
// then trigger one more.
|
||||
|
||||
await a
|
||||
await b
|
||||
await c
|
||||
await d
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
#### `fn = debounceify(asyncFunction)`
|
||||
|
||||
Debounces the `asyncFunction` so that
|
||||
|
||||
1. No parallel executions of `asyncFunction` will happen
|
||||
2. Debounces the stack, so if 10 calls happen while `asyncFunction` is running only one more will be triggered when it finishes.
|
||||
3. Forwards errors and return values.
|
||||
|
||||
#### `debounceify.running`
|
||||
|
||||
The active running job, `null` if none.
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
module.exports = function debounce (worker, context = null) {
|
||||
debounced.running = null
|
||||
return debounced
|
||||
|
||||
async function debounced () {
|
||||
if (debounced.running !== null) {
|
||||
try {
|
||||
await debounced.running
|
||||
} catch (_) {
|
||||
// ignore - do not fail on old errors
|
||||
}
|
||||
}
|
||||
|
||||
// another "thread" beat us to it, just piggy pack on that one
|
||||
if (debounced.running !== null) return debounced.running
|
||||
|
||||
debounced.running = worker.call(context)
|
||||
|
||||
try {
|
||||
return await debounced.running
|
||||
} finally {
|
||||
debounced.running = null
|
||||
}
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "debounceify",
|
||||
"version": "1.1.0",
|
||||
"description": "Tiny async debouncer",
|
||||
"main": "index.js",
|
||||
"dependencies": {},
|
||||
"devDependencies": {
|
||||
"standard": "^16.0.3",
|
||||
"tape": "^5.1.1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mafintosh/debounceify.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "standard && tape test.js"
|
||||
},
|
||||
"author": "Mathias Buus (@mafintosh)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/mafintosh/debounceify/issues"
|
||||
},
|
||||
"homepage": "https://github.com/mafintosh/debounceify"
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
const tape = require('tape')
|
||||
const debounce = require('./')
|
||||
|
||||
tape('basic', async function (t) {
|
||||
t.plan(2)
|
||||
const d = debounce(() => {
|
||||
t.pass('called')
|
||||
})
|
||||
|
||||
for (let i = 0; i < 100; i++) d()
|
||||
await d()
|
||||
})
|
||||
|
||||
tape('debounced returns', async function (t) {
|
||||
t.plan(3)
|
||||
|
||||
let cnt = 0
|
||||
const d = debounce(() => {
|
||||
t.pass('called')
|
||||
return cnt++
|
||||
})
|
||||
|
||||
for (let i = 0; i < 100; i++) d()
|
||||
t.same(await d(), 1)
|
||||
})
|
||||
|
||||
tape('debounced throws', async function (t) {
|
||||
t.plan(4)
|
||||
|
||||
let cnt = 0
|
||||
const d = debounce(async () => {
|
||||
t.pass('called')
|
||||
cnt++
|
||||
if (cnt === 1) {
|
||||
throw new Error('sup')
|
||||
}
|
||||
return cnt
|
||||
})
|
||||
|
||||
d().catch(err => t.same(err, new Error('sup')))
|
||||
d()
|
||||
d()
|
||||
d()
|
||||
t.same(await d(), 2)
|
||||
})
|
||||
Reference in New Issue
Block a user