Skip to content
This repository has been archived by the owner on Oct 26, 2024. It is now read-only.

Commit

Permalink
Removing lodash
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumebriday committed Dec 22, 2023
1 parent d8cf26f commit 89b28d5
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 28 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Bump dependencies.
- Upgrading to Vite `5.x`.
- Using a `throttle` function without `lodash.throttle`.

## [4.1.0] - 2022-12-25

Expand Down
4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"@babel/preset-env": "^7.23.6",
"@babel/preset-typescript": "^7.23.3",
"@hotwired/stimulus": "^3.2.2",
"@types/lodash.throttle": "^4.1.9",
"autoprefixer": "^10.4.16",
"np": "^9.2.0",
"postcss": "^8.4.32",
Expand All @@ -48,8 +47,5 @@
},
"resolutions": {
"prettierx": "~0.19.0"
},
"dependencies": {
"lodash.throttle": "^4.1.1"
}
}
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Controller } from '@hotwired/stimulus'
import { throttle } from 'lodash'
import { throttle } from './utils'

export default class extends Controller {
// @ts-ignore
Expand All @@ -9,8 +9,8 @@ export default class extends Controller {
static values = {
throttleDelay: {
type: Number,
default: 15
}
default: 15,
},
}

initialize (): void {
Expand Down
15 changes: 15 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export function throttle (callback: Function, delay: number) {
let shouldWait = false

return (...args) => {
if (shouldWait) return

callback.apply(this, args)

shouldWait = true

setTimeout(() => {
shouldWait = false
}, delay)
}
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"lib": ["dom", "es6"],
"types": ["vite/client", "lodash.throttle"],
"types": ["vite/client"],
"skipLibCheck": true,
"target": "es6",
"moduleResolution": "node"
Expand Down
5 changes: 2 additions & 3 deletions vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ export default defineConfig(({ mode }) => {
fileName: 'stimulus-scroll-progress'
},
rollupOptions: {
external: ['@hotwired/stimulus', 'lodash'],
external: ['@hotwired/stimulus'],
output: {
globals: {
'@hotwired/stimulus': 'Stimulus',
lodash: '_'
'@hotwired/stimulus': 'Stimulus'
}
}
}
Expand Down
17 changes: 0 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1534,18 +1534,6 @@
dependencies:
"@types/node" "*"

"@types/lodash.throttle@^4.1.9":
version "4.1.9"
resolved "https://registry.yarnpkg.com/@types/lodash.throttle/-/lodash.throttle-4.1.9.tgz#f17a6ae084f7c0117bd7df145b379537bc9615c5"
integrity sha512-PCPVfpfueguWZQB7pJQK890F2scYKoDUL3iM522AptHWn7d5NQmeS/LTEHIcLr5PaTzl3dK2Z0xSUHHTHwaL5g==
dependencies:
"@types/lodash" "*"

"@types/lodash@*":
version "4.14.202"
resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.202.tgz#f09dbd2fb082d507178b2f2a5c7e74bd72ff98f8"
integrity sha512-OvlIYQK9tNneDlS0VN54LLd5uiPCBOp7gS5Z0f1mjoJYBrtStzgmJBxONW3U6OZqdtNzZPmn9BS/7WI7BFFcFQ==

"@types/minimatch@*":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d"
Expand Down Expand Up @@ -4184,11 +4172,6 @@ lodash.isequal@^4.5.0:
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
integrity sha1-QVxEePK8wwEgwizhDtMib30+GOA=

lodash.throttle@^4.1.1:
version "4.1.1"
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"
integrity sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ==

lodash.zip@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/lodash.zip/-/lodash.zip-4.2.0.tgz#ec6662e4896408ed4ab6c542a3990b72cc080020"
Expand Down

0 comments on commit 89b28d5

Please sign in to comment.