Skip to content

Commit

Permalink
fix!: Update development dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
coreyfarrell committed Oct 15, 2023
1 parent 33d7c7e commit 6e77f65
Show file tree
Hide file tree
Showing 5 changed files with 227 additions and 210 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on:
push:
branches:
- master

permissions:
contents: write
pull-requests: write

name: release-please

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: google-github-actions/release-please-action@v3
with:
release-type: node
package-name: '@cfware/nyc'
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: 16
node-version: 18
- run: npm install
- name: Lint
run: npm run -s pretest
Expand Down
120 changes: 60 additions & 60 deletions debouncer.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
export default class Debouncer {
_lastRun = 0;
_firstRequest = 0;
_lastRequest = 0;

constructor(callback, delay = 100, maxDelays = 2) {
if (typeof callback !== 'function') {
throw new TypeError('Function is required');
}

this._cb = callback;
this._delay = delay;
this._maxDelays = maxDelays;
}

_now() {
this._lastRun = Date.now();
this._cb();
this.clear();
}

_later() {
const now = Date.now();
const delta = now - this._lastRequest;
const totalDelta = now - this._firstRequest;
const maxDelay = this._delay * this._maxDelays;
const maxTimeout = Math.min(maxDelay - totalDelta, this._delay - delta);

if (this._lastRun && maxTimeout > 0) {
this._timeout = setTimeout(() => this._later(), maxTimeout);
} else {
this._now();
}
}

run(immediately = false) {
const now = Date.now();

this._lastRequest = now;
if (!this._firstRequest) {
this._firstRequest = now;
}

if (immediately) {
this._now();
} else if (!this._timeout) {
this._timeout = setTimeout(() => this._later(), this._delay);
}
}

flush() {
if (this._timeout) {
this._now();
}
}

clear() {
this._firstRequest = 0;
this._lastRequest = 0;
this._timeout = clearTimeout(this._timeout);
}
_lastRun = 0;
_firstRequest = 0;
_lastRequest = 0;

constructor(callback, delay = 100, maxDelays = 2) {
if (typeof callback !== 'function') {
throw new TypeError('Function is required');
}

this._cb = callback;
this._delay = delay;
this._maxDelays = maxDelays;
}

_now() {
this._lastRun = Date.now();
this._cb();
this.clear();
}

_later() {
const now = Date.now();
const delta = now - this._lastRequest;
const totalDelta = now - this._firstRequest;
const maxDelay = this._delay * this._maxDelays;
const maxTimeout = Math.min(maxDelay - totalDelta, this._delay - delta);

if (this._lastRun && maxTimeout > 0) {
this._timeout = setTimeout(() => this._later(), maxTimeout);
} else {
this._now();
}
}

run(immediately = false) {
const now = Date.now();

this._lastRequest = now;
if (!this._firstRequest) {
this._firstRequest = now;
}

if (immediately) {
this._now();
} else if (!this._timeout) {
this._timeout = setTimeout(() => this._later(), this._delay);
}
}

flush() {
if (this._timeout) {
this._now();
}
}

clear() {
this._firstRequest = 0;
this._lastRequest = 0;
this._timeout = clearTimeout(this._timeout);
}
}
68 changes: 34 additions & 34 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
{
"name": "@cfware/debouncer",
"version": "0.3.3",
"description": "Debouncer class",
"main": "debouncer.js",
"exports": "./debouncer.js",
"type": "module",
"scripts": {
"pretest": "cfware-lint .",
"tests-only": "nyc -s --no-check-coverage node --experimental-loader @istanbuljs/esm-loader-hook test.js | tap-yaml-summary",
"test": "npm run -s tests-only",
"posttest": "nyc report"
},
"engines": {
"node": ">=16.12.0"
},
"author": "Corey Farrell",
"license": "MIT",
"keywords": [],
"repository": {
"type": "git",
"url": "git+https://github.com/cfware/debouncer.git"
},
"bugs": {
"url": "https://github.com/cfware/debouncer/issues"
},
"homepage": "https://github.com/cfware/debouncer#readme",
"devDependencies": {
"@cfware/lint": "^3.0.0",
"@cfware/nyc": "^0.7.1",
"@istanbuljs/esm-loader-hook": "^0.2.0",
"libtap": "^1.4.0",
"nyc": "^15.1.0",
"tap-yaml-summary": "^0.2.0"
}
"name": "@cfware/debouncer",
"version": "0.3.3",
"description": "Debouncer class",
"main": "debouncer.js",
"exports": "./debouncer.js",
"type": "module",
"scripts": {
"pretest": "cfware-lint .",
"tests-only": "nyc -s --no-check-coverage node --experimental-loader @istanbuljs/esm-loader-hook test.js | tap-yaml-summary",
"test": "npm run -s tests-only",
"posttest": "nyc report"
},
"engines": {
"node": ">=18"
},
"author": "Corey Farrell",
"license": "MIT",
"keywords": [],
"repository": {
"type": "git",
"url": "git+https://github.com/cfware/debouncer.git"
},
"bugs": {
"url": "https://github.com/cfware/debouncer/issues"
},
"homepage": "https://github.com/cfware/debouncer#readme",
"devDependencies": {
"@cfware/lint": "^4",
"@cfware/nyc": "^1",
"@istanbuljs/esm-loader-hook": "^0.2",
"libtap": "^1",
"nyc": "^15",
"tap-yaml-summary": "^0.2"
}
}
Loading

0 comments on commit 6e77f65

Please sign in to comment.