From 79b46b4158f2624aee7cb6ed9b47c3451634d4b8 Mon Sep 17 00:00:00 2001 From: Afshin Mehrabani Date: Sun, 14 Jan 2024 15:04:38 +0000 Subject: [PATCH] fix throttle params + 6.1 --- package-lock.json | 4 ++-- package.json | 2 +- src/util/throttle.ts | 4 ++-- tests/jest/util/throttle.test.ts | 8 ++++---- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2f88b333..ff4ea183 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "gridjs", - "version": "6.0.6", + "version": "6.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "gridjs", - "version": "6.0.6", + "version": "6.1.0", "license": "MIT", "dependencies": { "preact": "^10.11.3" diff --git a/package.json b/package.json index 2207908a..400c9506 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gridjs", - "version": "6.0.6", + "version": "6.1.0", "description": "Advanced table plugin", "author": "Afshin Mehrabani ", "license": "MIT", diff --git a/src/util/throttle.ts b/src/util/throttle.ts index aae8e113..c0fb4723 100644 --- a/src/util/throttle.ts +++ b/src/util/throttle.ts @@ -19,7 +19,7 @@ export const throttle = (fn: (...args) => void, wait = 100) => { if (elapsed >= wait) { // If enough time has passed since the last call, execute the function immediately - execute(args); + execute(...args); } else { // If not enough time has passed, schedule the function call after the remaining delay if (timeoutId) { @@ -27,7 +27,7 @@ export const throttle = (fn: (...args) => void, wait = 100) => { } timeoutId = setTimeout(() => { - execute(args); + execute(...args); timeoutId = null; }, wait - elapsed); } diff --git a/tests/jest/util/throttle.test.ts b/tests/jest/util/throttle.test.ts index 4e6ed5ea..646c0718 100644 --- a/tests/jest/util/throttle.test.ts +++ b/tests/jest/util/throttle.test.ts @@ -8,16 +8,16 @@ describe('throttle', () => { const fn = jest.fn(); const throttled = throttle(fn, wait); - throttled('a'); + throttled('a', 'b', 'c'); sleep(wait - 5); - throttled('b'); + throttled('b', 'a', 'c'); sleep(wait - 10); - throttled('c'); + throttled('c', 'b', 'a'); await sleep(wait); expect(fn).toBeCalledTimes(1); - expect(fn).toBeCalledWith(['c']); + expect(fn).toBeCalledWith('c', 'b', 'a'); }); it('should execute the first call', async () => {