From a579dfdda3d1ee55561dbeea46a5fd6ee09427f9 Mon Sep 17 00:00:00 2001 From: Jon Snyder Date: Mon, 8 Jan 2024 14:58:37 -0700 Subject: [PATCH] Remove debounce as its no longer used, and the unit test was failing on Firefox intermittently --- src/utils/debounce.js | 23 ------------ test/unit/specs/utils/debounce.spec.js | 52 -------------------------- 2 files changed, 75 deletions(-) delete mode 100644 src/utils/debounce.js delete mode 100644 test/unit/specs/utils/debounce.spec.js diff --git a/src/utils/debounce.js b/src/utils/debounce.js deleted file mode 100644 index c2cdc924b..000000000 --- a/src/utils/debounce.js +++ /dev/null @@ -1,23 +0,0 @@ -/* -Copyright 2023 Adobe. All rights reserved. -This file is licensed to you under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. You may obtain a copy -of the License at http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under -the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS -OF ANY KIND, either express or implied. See the License for the specific language -governing permissions and limitations under the License. -*/ -export default (fn, delay = 150) => { - let timer; - return (...args) => { - if (timer) { - clearTimeout(timer); - } - - timer = setTimeout(() => { - fn(...args); - }, delay); - }; -}; diff --git a/test/unit/specs/utils/debounce.spec.js b/test/unit/specs/utils/debounce.spec.js deleted file mode 100644 index d30912377..000000000 --- a/test/unit/specs/utils/debounce.spec.js +++ /dev/null @@ -1,52 +0,0 @@ -/* -Copyright 2023 Adobe. All rights reserved. -This file is licensed to you under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. You may obtain a copy -of the License at http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software distributed under -the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS -OF ANY KIND, either express or implied. See the License for the specific language -governing permissions and limitations under the License. -*/ -import debounce from "../../../../src/utils/debounce"; - -describe("debounce", () => { - let callback; - - beforeEach(() => { - callback = jasmine.createSpy(); - }); - - it("calls a function only once", done => { - const fn = debounce(callback, 150); - - for (let i = 0; i < 10; i += 1) { - fn("oh", "hai"); - } - - setTimeout(() => { - expect(callback).toHaveBeenCalledOnceWith("oh", "hai"); - expect(callback).toHaveBeenCalledTimes(1); - done(); - }, 160); - }); - - it("calls a function only once per delay period", done => { - const fn = debounce(callback, 10); - fn("oh", "hai"); - fn("oh", "hai"); - - setTimeout(() => { - fn("cool", "beans"); - expect(callback).toHaveBeenCalledWith("oh", "hai"); - expect(callback).toHaveBeenCalledTimes(1); - }, 25); - - setTimeout(() => { - expect(callback).toHaveBeenCalledWith("cool", "beans"); - expect(callback).toHaveBeenCalledTimes(2); - done(); - }, 50); - }); -});