From d4379d8af1d56ef558811e3748ec0a79cff61d15 Mon Sep 17 00:00:00 2001 From: Marco Cedaro Date: Fri, 18 Oct 2024 17:56:32 +0100 Subject: [PATCH 1/2] added env to the test step (#232) --- .github/workflows/pr-testing.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/pr-testing.yml b/.github/workflows/pr-testing.yml index 3dc58f11..fbdba137 100644 --- a/.github/workflows/pr-testing.yml +++ b/.github/workflows/pr-testing.yml @@ -15,3 +15,5 @@ jobs: cache: 'yarn' - run: yarn install --prefer-offline --frozen-lockfile - run: yarn test + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} From 506e96ec5eb3ae43f516743ab6ab5fb8eb1ee277 Mon Sep 17 00:00:00 2001 From: Roman Gusev Date: Fri, 18 Oct 2024 20:39:36 +0200 Subject: [PATCH 2/2] Remove extra call when debounced with leading option called once (#231) * Add failing test for debounce with leading option * Remove extra call in debounce with leading * Replace extra int variable with bool flag * Updating codesandbox references * Simplify code * Updating codesandbox references --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Marco Cedaro --- src/code-sandbox-refs.json | 2 +- src/code-sandbox.json | 2 +- src/content/lodash/function/debounce/spec.js | 11 ++++++++++- src/content/lodash/function/debounce/vanilla.js | 6 +++++- 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/code-sandbox-refs.json b/src/code-sandbox-refs.json index 530280db..7f24a197 100644 --- a/src/code-sandbox-refs.json +++ b/src/code-sandbox-refs.json @@ -130,7 +130,7 @@ "lodash/function/bind": "https://codesandbox.io/api/v1/sandboxes/define?parameters=N4IgZglgNgpgziAXKMBXAdgYwC4QPboD0ARhOgCaFR7kCGcAFgHQBWCyImB2M62SIQoQAEDbNgAOcREOp1GTLgFtC5PJjiEAxKQoAddBCUS8AJ2zDgw3eWEBfYWFN4lwgORz6DNwYNosuATCAOamMDDYABSh4bjowQA0whIYOKi0gegAlJYGwsJh2Kim6CFhEWTBwgDU7nW12AwQcEyocDCmNcmpRRn46AZ2vugAbrSdeMQsMDjCALyWwm0diO5OMORu9sNjncR4GLYLNtHl2EmT0zhJbk1uWcNKNKiwTDAAHibmcPPWBxSRNwAQnuBiE8wAfO4mo4wuQQQYQAkQM0AEJkcYATyQYFoUHadmR_hw_RIZEoNiYcAkM1Y7FAXD4vH4iE4BDgFg-NJwG1-twgsI2CIGWHZFk8jF-YQAjqgIGFAUwqDQvKDRegOckoLQyFKYLL5TBFYQxoYoNq1QYeBzATY3ElIjk5lDgHlhFyZlEJQwskxsHgAKKyvGRD088gPUruz6eyISbVkX3-oPpKCRb2RuyRpEouDo9BYnF4glEnqkmwm2hm7V0pAM7jMgSMzU2X6RMDoJI4d5JJh9_aHACCpmCcCdUI7TBO3d7_f-5GHo8jfjLQRiEVOsUqSRSAXSmRyrqjhWKpXXcSqtS2WwaTRay06tV3aT6BEGO3Gwkunt-VgfqzcdZNm2EVdj-Q5fhOc8LimT0bjuZd0CecgXhgN5PjMbAfmOedARBSNwWdaEBSA4UczRDFTGxRBcXxGBCRAJgJEKXAOlMTA6zZJk-AEI98j0EB2iUCABNWWj2gSN0BLgSpYAARVQPAeFE4RsFMVAYEkqMBPGZwAHcAAVxl4OAVJ0kY8AgcgBK0_iQFlJSYAM5wpDMkBmPgDoRhgAT33QEAGIkWhMAAa1oYI0LYAhOMZHgeI4AslBgARvTJCgc3IGAaQoXhMAgeBOO9AQABYmAARgAdiYAAmMqcwAAWIWhiBgKBCHUvgjGS1kqrKgBWJhioCuwRrsIA&query=previewwindow%3Dtests%26file%3D%2Ffunction%2Fbind%2Fvanilla.js", "lodash/function/curry": "https://codesandbox.io/api/v1/sandboxes/define?parameters=N4IgZglgNgpgziAXKMBXAdgYwC4QPboD0mqATqQJ6FR4AmAhnABYB0AVgsiJgdjOtiQhChAARNs2AA5xEImg2YseAW0K08mOIQDEJchQA66CCql5S2UcFH7KogL6iwpPCtEByBYyYfjxnnQ4K3oAI0xRAF5RAAp6ABp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DAA7CwoyDHWAACoRhDAUCEEhAimDAQgS4MACsLBC0TDgGw4QA&query=previewwindow%3Dtests%26file%3D%2Ffunction%2Fcurry%2Fvanilla.js", "lodash/function/curryRight": "https://codesandbox.io/api/v1/sandboxes/define?parameters=N4IgZglgNgpgziAXKMBXAdgYwC4QPboD0mqATqQJ4BKEA5gBbaFR4AmAhnPQHQBWCyEJgLYY6bEhCFCAAkbYADnETSWHLt2EBbQqzyY4hAMQly1OowA66CFoV5S2GcBmnKNBk4C-MsKTxaMgDkapz0QdbWwuhwTuwARpgyALwyABTsADQy8dmYAJQpAHwyANpZOXkAupFYBLGuZKQQMKwpjWYejBmJ-bUwAB72jnCaTRTtbi2saQDM-WkATAsAjH1EssklpSvZi9mzNejWg8PYo1oOMOyktHCTTdNLB6vr0sVluzL7Mof9Qw5ztx2FAoDc7g9yE8vj95tZ3ltPnsDkcQJkQBA4AAhCDoG4UJBgEFwGBedFoLC4AjEcZdJhucyebhwBQwTB8ASgaKicSSaINU5s0RtVLAawyDqURBI74ozLimSXUjXW7KGWwqry9ASkFg1XSnbI36a6xeWr8pyhLjtZUAR1QEGVaSC3GYbDCQXWFpkCjBuJtMHtjpgztdADd2DZQexPbVRLFnQygtk0oVEWLtTJBTg0lb6PluNg8ABRe0gtLZ4XrCWVtK-9i4gtF0uoct59ZedZojHY3H4wnE0nkjA4fBEBl0wgRqNgjlILkiMQSRBSWTYegwGQEKATVgQMBgGDKrCbvwBGTrzcMxUwddseGyWy-mBaJfsKnazFyPAAdxk4NQV9xHuWhb3uaJMHfMQoNYKJ6icCcLCcVIKSSdMFW9StWgAQVVdpUO4WB0FodcMPgyVpnaNJuBo8E4DTEoMwlCVlWwMhtTowixBI-gZCKVIsNYXC7gVZiZAAfl8EdqNo1VqzEmRpRk4FVWWD4plaZS6MWTQCEg7AMjk-SzUzVj2Io1pTXNciEjQ9IKlyVwGLKBzqmsmIEMeVpIXcJCegKf4zlGa9Ug0mZ5iWV4Hw-Q1ZWNQLAQuK46J8p5YSijYYphFEEpGYFozw0KvJmbLfjeTZtlKv50G7TEcTxSgBygEkyRAbgFFY3Aj1ITB5yERdeRXJiZEsEASS0CBRulIlmpgLUJVGuBcVoWAAEVUDwUQpovUhUDmhVRpufwfwABRuMQ4G2w6wzwCBYLRA6QHtTaYBO_wlCukAOvgI8wxgUarJq1qFHYTAAGt2FAjkCD67klz6vFX0kPMaU6JDu1YGBWXQTGsBaTkQDzSQABZuBWAB2bhFhWbsAAF4gSGAoEIXbxFsGBJEplYAFZuGJkAvEFwWgA&query=previewwindow%3Dtests%26file%3D%2Ffunction%2FcurryRight%2Fvanilla.js", - "lodash/function/debounce": "https://codesandbox.io/api/v1/sandboxes/define?parameters=N4IgZglgNgpgziAXKMBXAdgYwC4QPboD0AJjAEZ4aYyFR7ECGcAFgHQBWCyImB2M6bEhCFCAAmbZsABziJRdRi1a8AtiTyY4hAMSkKVGAB10EVdLwAnbGOBj9lLDDEBfMWEt5VYgOSKmzD4mJqr0qLCsMAAeFtZwYgC8YgAUrGkMlgDmcACUiQB89uSO1KnpWbkmogVimMwwmADWYtj1LfDY8WBWYqGWzqTYDNBwJiAANCAQcABCEOgZAJ5IYAxQcDAuk2hYuAQkxYYHBk6scNINHFygvIICQog8BHA2YOjxScAmYmL-LIhifoAR1QEH6yR8rFo9ACPhy42-YmkUGG6ABwNB4MhhAAbgxTFAUXCEegXMF0OwOqxUBsAGIMRowAAqZhgljgyRy5NIcEwlggZBgEIchh84xSeQShS-6B-AHkyJScJFBPz4Mk3rlWN1LABRBh1ZLJADajMW4pFTgAupLpYifjy-QKhWbxZyajKfl7fjBXuh7V7BTqYPrDe6pbYA963okxJSXtr0Jyo64uf7Zd72i8IRAbCxKFBiLU1lAWm1LdQizGCNQxAwbK1nAIi3gwGXnCCIL6WqyxRKPSmfrcXkUTpXYxWhW9xQBGAAMC7Tg_cPWSsBsEFjc4A3GJNwAeMTznd7gDUp7ynsz3snxGSEDT15-ZPTT7jVIYxDxThZqjZs0WX8hWPG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cIAALKwGcAB2Vg4cZyFwAAJkAYIKKAhA7qCFZMIFJPtWBxJAC4SplSgA&query=previewwindow%3Dtests%26file%3D%2Ffunction%2Fdebounce%2Fvanilla.js", + "lodash/function/debounce": "https://codesandbox.io/api/v1/sandboxes/define?parameters=N4IgZglgNgpgziAXKMBXAdgYwC4QPboD0AJjAEZ4aYyFR7ECGcAFgHQBWCyImB2M6bEhCFCAAmbZsABziJRdRi1a8AtiTyY4hAMSkKVGAB10EVdLwAnbGOBj9lLDDEBfMWEt5VYgOSKmzD4mJqr0qLCsMAAeFtZwYgC8YgAUrGkMlgDmcACUiQB89uSO1KnpWbkmogVimMwwmADWYtj1LfDY8WBWYqGWzqTYDNBwJiAANCAQcABCEOgZAJ5IYAxQcDAuk2hYuAQkxYYHBk6scNINHFygvIICQog8BHA2YOjxScAmYmL-LIhifoAR1QEH6yR8rFo9ACPhy42-YmkUGG6ABwNB4MhhAAbgxTFAUXCEegXMF0OwOqxUBsAGIMRowAAqZhgljgyRy5NIcEwlggZBgEIchh84xSeQShS-6B-AHkyJScJFBPz4Mk3rlWN1LABRBh1ZLJADajMW4pFTgAupLpYifjy-QKhWbxZyajKfl7fjBXuh7V7BTqYPrDe6pbYA963okxJSXtr0Jyo64uf7Zd72i8IRAbCxKFBiLU1lAWm1LdQizGCNQxAwbK1nAIi3gwGXnCCIL6WqyxRKPSmfrcXkUTpXYxWhW9xQBGAAMC7Tg_cPWSsBsEFjc4A3GJNwAeMTznd7gDUp7ynsz3snxGSEDT15-ZPTT7jVIYxDxThZqjZs0WX8hWPGdHyfaILhwDV0ByVhsDwGYYAAYRLGBiCAjlQOXCCGmwaDYPgxCUMJNCAHVc2YZIAE4qLA70XCXDNvX4bMfFzMR83CItMBLdtRxKND3FlGtnHrPjmzEVs-M7btcD_PtwztJjM2HGxbwnQ4nGg2cFznRi3x1FJ1z3LddwPI8FzM89L2XB1NMre86KfeNsFYT9v2oID2RmQDWWominPo8k3xctyv3xTzWW83y_2SY89OwmJcPw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ED8n2rA3nrJcIilwQA&query=previewwindow%3Dtests%26file%3D%2Ffunction%2Fdebounce%2Fvanilla.js", "lodash/function/delay": "https://codesandbox.io/api/v1/sandboxes/define?parameters=N4IgZglgNgpgziAXKMBXAdgYwC4QPboD0AJjFAIYCehUex5cAFgHQBWCyImB2M62SEIUIACRtmwAHOImG16TZtwC2JPJjiEAxKQqUAOugjLJeAE7YRwEbqoiAviLBm8ykQHJ5DRu8OHldKiwzDAAHqYWcCIAvE7oMQB8NmRUABRg6AA0IgCMAAwF2Z7kvGbuAJSGwokimIwwmADWItj1LfDYUWDmIgFmMMnY5NBwhiCZIBBwAEIQ6ORmlEhg5FBwMPYTaFi4BCQp1LaUzHCSDWwcoNz8fAKIXARwlhlRscCGIiJeTIgi_QCOqAg_VS7mYNDo3gqmQ-IkkFDmvwBQJBYMIADdyEYoBRoYZ7H50KwOsxUOsAGLkRowAAqxhgZjgqUq6EMpDgmDMEAARjBQUd3NlmTV3vERAB5bnEnAhfhc-DpdBwcrMbpmACi5DqqVSAG1qZRskcALrlEWwz7szk8vkGoVm6JJUWfF1fGDPVli128tUwTXa4WOqwW11xGIiYlPVXoZkhz72Flx9pPVL6SaWJh4ILEEToPCWTCrKAtNpHGA57Y4fDxCBgEsDXDKAbECDEdDuSySBijcYiQNOpOWg6Klmhl1hM44EfMbB4aYwADCRfLdKbTLyo9DCcJY94KfcEAzjCzUBzhZx9eSenLTgwVYIIlrl8bAy7cHWxEFfYdA69oaOI47mOEYkuQxCYlgtL0oy0yUKufL5HkOSJn-roTg02DTrO85LjiK70kyyGDiI6FThkKrYYuy7EAA6oejCghQpQVEm25_mx8Ysmx4yTDMcwLEsiArGsGxbHeuxEEcGJYtAFAXEgVw8LcgjXE8V52LEirZC-ZjZMw-kLAA5sqNTrNg8FZph_ZxKk-nMEZyradBKEBMQQQwCE4TmJ04YZDUAEZNkiF5EUTEMix6A8VMszzIsyyrOsmwgMwkj9BIEAMmYmAKQ8Nz8IIzoiGm6zKBAaa_MJ6wwmKxVzIZsAAIqoPmMDlS0ZioDA1WfGmCwuAA7gACgsfA9r8vXongrZpt1RUgICLWDS40htWmqXwAy6KtSA-JjElXZNOQhkeewBA5dcvD5Zw8xNoI3yMPseg8aQZzoKQWAZZcID3YIAAszA5AA7MwABMOQ8QAAty5C8lAhAdfw9KCMDOQAKzML9ID2Nj2NAA&query=previewwindow%3Dtests%26file%3D%2Ffunction%2Fdelay%2Fvanilla.js", "lodash/function/flip": "https://codesandbox.io/api/v1/sandboxes/define?parameters=N4IgZglgNgpgziAXKMBXAdgYwC4QPboD0YUEADoVHgCYCGcAFgHQBWCyImB2M62SIQoQAEDbNjJxEQqnUZMuAW0LU8mOIQDEJcgB10ERWTwAnbMODCdZYQF8rJvIuEByWfQYv9-rujjnrMhhqYQBeK1IyAAoopjjaEwBzOABKMIA-YQTklO90RRpUWCYYAA9jMzgwiPIg6iiXWhcAGlcAIxbXTE6XahdcohFQzIBtXp7u1pcOqaaAXX0QZpAIOAAhCHQEgE8kMFooOBhbZbQsXAJiSKvyJjggzFZ2UF8ePgFff2Eyh54Q8LGfSmk3aPXmeU-5ncjGqJhgAEdUBA4Q0mJQaB5-j4CF8yFBaJtYQikSiXGiAG60AxQfFY9D6Hj-BrWTpRNLDCz6YTfcowHBRaEMFJMbB4ACiiIOUR-fL-A25Mv5eIJ6GFoolqClgoGtgGSxW602Oz2ByOJ3AGBw-CI1kIlOp-KeSBe3F4_EQnBxAUiYS5VktGT9sXiSVSgfQ3O5Z0wwaY2TgTDh5JgJiObIG2L83tqwWq1hicTjofZmXjGfyhWKP1M2Cq4UCwQaTSmMy6PT6AyEGWEgImPVbjRcC3Q-tWGy2Jl2iH2h2OyyYZDh4ggKZMmGdnr4boEwD9uhAR0UEH3iCsppgzT3B82iVgAEVUHgeCfhNgTKgL1eEo4AO4ABQSXg4BffdaHJPAIGofdLwjYR90RJ8YD_RxJBAkBF3gFNk33fRbEWc0yFoTAAGtaESGAngIDdXm3DgtkUGABEFG4yH1agYCCdB2KwFdnhAQUBAAFiYABGAB2JgACYRP1AABNpaDaGAoEId8-EMRiPQkkSAFYmEEkBbCMoygA&query=previewwindow%3Dtests%26file%3D%2Ffunction%2Fflip%2Fvanilla.js", "lodash/function/negate": "https://codesandbox.io/api/v1/sandboxes/define?parameters=N4IgZglgNgpgziAXKMBXAdgYwC4QPboD06MA5gIbYyFR4Am5cAFgHQBWCyImBV62SEIUIACJtmwAHOImG0GzFjwC2hOnkxxCAYhIUqAHXQRlkvACdsI4CL2UYIgL4iw5vMpEByeYyaejRjzocFYQcACiAG4w6CIAvLbxAHyJAKQiAEzxcQkADAHoyvSosCwwAB5mlnDxIgDaAIwANJktAMwtACwtAKwtAGwAuiyQUFTmABR2VBNhUTEAlAtGwsn1zSIdIj2DRiBNIGEAQhDo5OYAnkhg5FBwMI4HaFi4BMRk9u_6MCxwkjCYdicUBBPgCRDcAghEQVf44GB0WqNdq9XboQJQqw-Zi1cwwACOqAgeImnhYNHovk8yywmJEkig5FOuIJRJJZMIkXIxigjOpBSoIVJ0xgnhaEwWa2ARhEMMqAOwE2xTAWLGweHChNuE1hCoRNNlupwEwZTPQqvVmtQ2uVNMcNP2hzgJzOl2ut3uj3AGBw-CIIs53OgjKBSBBvBi4MhwSsIviMpcPuSCYmLDT51IcElcSSCdlAEJnphU-nzJmaRiYyI5tFYgk6ylYuksjk8gUinQSj9YRZsDUEsjWpsur0BsNRuMph8ZjXFjTVjn1ijtmjHcdTucrogbncHgcWJI8RIIDBzOZMGHo2DBNLYiIDCB7soIA_EC4PTAmgmH3BTqRYAAiqgeCGEgIjYOYqCft-IDnG4ADuAAK5wxHAr73rBkR4BAdAPl-d4PoSIEwIhbjSOhD6HvAp7RA-RiOHsXqSOQmAANbkKQPwcAQl6gpGl5nMoMCCMqXz2I6dAwP86CSVgJ7AiAyqCJ0LANAA7CwGQNI6AACABG5B6TAUCEJB_AmMJEIaQ0PQsJ0ICOI5jlAA&query=previewwindow%3Dtests%26file%3D%2Ffunction%2Fnegate%2Fvanilla.js", diff --git a/src/code-sandbox.json b/src/code-sandbox.json index 5532da47..9b59df22 100644 --- a/src/code-sandbox.json +++ b/src/code-sandbox.json @@ -131,7 +131,7 @@ "lodash/function/bind": "https://codesandbox.io/s/hwqht?previewwindow=tests&file=/function/bind/vanilla.js", "lodash/function/curry": "https://codesandbox.io/s/rjz9o?previewwindow=tests&file=/function/curry/vanilla.js", "lodash/function/curryRight": "https://codesandbox.io/s/3i27g?previewwindow=tests&file=/function/curryRight/vanilla.js", - "lodash/function/debounce": "https://codesandbox.io/s/v49r9y?previewwindow=tests&file=/function/debounce/vanilla.js", + "lodash/function/debounce": "https://codesandbox.io/s/nlxh9g?previewwindow=tests&file=/function/debounce/vanilla.js", "lodash/function/delay": "https://codesandbox.io/s/81fwe7?previewwindow=tests&file=/function/delay/vanilla.js", "lodash/function/flip": "https://codesandbox.io/s/32gwy?previewwindow=tests&file=/function/flip/vanilla.js", "lodash/function/negate": "https://codesandbox.io/s/ib0le?previewwindow=tests&file=/function/negate/vanilla.js", diff --git a/src/content/lodash/function/debounce/spec.js b/src/content/lodash/function/debounce/spec.js index f5595f78..eedcdfc1 100644 --- a/src/content/lodash/function/debounce/spec.js +++ b/src/content/lodash/function/debounce/spec.js @@ -38,7 +38,7 @@ describe('debounce', () => { expect(fn).toBeCalledWith(99) }) - test("with a leading invocation, it should call the debounced fn once, if the time doens't pass", () => { + test("with a leading invocation, it should call the debounced fn once, if the time doesn't pass", () => { const debounced = debounce(fn, 1000, { leading: true }) for (let i = 0; i < 100; i++) { @@ -64,6 +64,15 @@ describe('debounce', () => { expect(fn).toBeCalledWith(0) expect(fn).toBeCalledWith(99) }) + + test('it should call the debounced fn once with leading option if it was called once', () => { + const debounced = debounce(fn, 1000, { leading: true }) + + debounced(); + + jest.advanceTimersByTime(1001) + expect(fn).toBeCalledTimes(1) + }) }) }) }) diff --git a/src/content/lodash/function/debounce/vanilla.js b/src/content/lodash/function/debounce/vanilla.js index 45cef6f7..8b01fc0f 100644 --- a/src/content/lodash/function/debounce/vanilla.js +++ b/src/content/lodash/function/debounce/vanilla.js @@ -1,13 +1,17 @@ const debounce = (func, delay, { leading } = {}) => { let timerId + let shouldInvoke return (...args) => { + shouldInvoke = true + if (!timerId && leading) { func(...args) + shouldInvoke = false } clearTimeout(timerId) - timerId = setTimeout(() => func(...args), delay) + timerId = setTimeout(() => shouldInvoke && func(...args), delay) } }