Skip to content

Commit 277343a

Browse files
committed
chore: wip
1 parent d660e61 commit 277343a

File tree

7 files changed

+371
-50
lines changed

7 files changed

+371
-50
lines changed

.stacks/auto-imports.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ declare global {
9999
const database: typeof import('../config/database')['database']
100100
const databasePath: typeof import('./core/path/src/index')['databasePath']
101101
const dd: typeof import('./core/logging/src/index')['dd']
102-
const debounce: typeof import('./core/utils/src/vendor')['debounce']
102+
const debounce: typeof import('./core/utils/src/debounce')['debounce']
103103
const debouncedRef: typeof import('@vueuse/core')['debouncedRef']
104104
const debouncedWatch: typeof import('@vueuse/core')['debouncedWatch']
105105
const debug: typeof import('./core/logging/src/index')['debug']
@@ -409,7 +409,7 @@ declare global {
409409
const test: typeof import('vitest')['test']
410410
const testingPath: typeof import('./core/path/src/index')['testingPath']
411411
const testsPath: typeof import('./core/path/src/index')['testsPath']
412-
const throttle: typeof import('./core/utils/src/vendor')['throttle']
412+
const throttle: typeof import('./core/utils/src/debounce')['throttle']
413413
const throttledRef: typeof import('@vueuse/core')['throttledRef']
414414
const throttledWatch: typeof import('@vueuse/core')['throttledWatch']
415415
const timestamp: typeof import('@vueuse/shared')['timestamp']
@@ -741,7 +741,7 @@ declare module 'vue' {
741741
readonly database: UnwrapRef<typeof import('../config/database')['database']>
742742
readonly databasePath: UnwrapRef<typeof import('./core/path/src/index')['databasePath']>
743743
readonly dd: UnwrapRef<typeof import('./core/logging/src/index')['dd']>
744-
readonly debounce: UnwrapRef<typeof import('./core/utils/src/vendor')['debounce']>
744+
readonly debounce: UnwrapRef<typeof import('./core/utils/src/debounce')['debounce']>
745745
readonly debouncedRef: UnwrapRef<typeof import('@vueuse/core')['debouncedRef']>
746746
readonly debouncedWatch: UnwrapRef<typeof import('@vueuse/core')['debouncedWatch']>
747747
readonly debug: UnwrapRef<typeof import('./core/logging/src/index')['debug']>
@@ -1052,7 +1052,7 @@ declare module 'vue' {
10521052
readonly test: UnwrapRef<typeof import('vitest')['test']>
10531053
readonly testingPath: UnwrapRef<typeof import('./core/path/src/index')['testingPath']>
10541054
readonly testsPath: UnwrapRef<typeof import('./core/path/src/index')['testsPath']>
1055-
readonly throttle: UnwrapRef<typeof import('./core/utils/src/vendor')['throttle']>
1055+
readonly throttle: UnwrapRef<typeof import('./core/utils/src/debounce')['throttle']>
10561056
readonly throttledRef: UnwrapRef<typeof import('@vueuse/core')['throttledRef']>
10571057
readonly throttledWatch: UnwrapRef<typeof import('@vueuse/core')['throttledWatch']>
10581058
readonly timestamp: UnwrapRef<typeof import('@vueuse/shared')['timestamp']>

.stacks/core/utils/package.json

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,34 @@
6464
"p-limit": "^4.0.0",
6565
"rimraf": "^5.0.0",
6666
"semver": "^7.5.0",
67-
"throttle-debounce": "^5.0.0",
6867
"yaml": "^2.2.1"
6968
},
7069
"devDependencies": {
71-
"@stacksjs/development": "workspace:*",
72-
"@types/throttle-debounce": "^5.0.0"
70+
"@stacksjs/development": "workspace:*"
71+
},
72+
"dependencies": {
73+
"@stacksjs/arrays": "workspace:*",
74+
"@stacksjs/cli": "workspace:*",
75+
"@stacksjs/config": "workspace:*",
76+
"@stacksjs/lint": "workspace:*",
77+
"@stacksjs/path": "workspace:*",
78+
"@stacksjs/storage": "workspace:*",
79+
"@stacksjs/types": "workspace:*",
80+
"@vueuse/core": "^10.1.0",
81+
"@vueuse/head": "^1.1.26",
82+
"@vueuse/math": "^10.1.0",
83+
"@vueuse/shared": "^10.1.0",
84+
"defu": "^6.1.2",
85+
"detect-indent": "^7.0.1",
86+
"detect-newline": "^4.0.0",
87+
"dinero.js": "2.0.0-alpha.14",
88+
"esno": "^0.16.3",
89+
"fast-glob": "^3.2.12",
90+
"kolorist": "1.8.0",
91+
"p-limit": "^4.0.0",
92+
"perfect-debounce": "^0.1.3",
93+
"rimraf": "^5.0.0",
94+
"semver": "^7.5.0",
95+
"yaml": "^2.2.1"
7396
}
7497
}

.stacks/core/utils/src/debounce.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { debounce } from 'perfect-debounce'

.stacks/core/utils/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export * from './function'
77
export * from './guards'
88
export { isDef, isBoolean, isFunction, isNumber, isString, isObject, isWindow, isBrowser, isServer, isMap, isSet, isPromise } from './is'
99
export * from './p'
10-
export * from './vendor'
10+
export * from './debounce'
11+
export * from './throttle'
1112
export * as semver from 'semver'
1213

1314
export * from '@vueuse/core'

.stacks/core/utils/src/throttle.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
* Throttle a function.
3+
*
4+
* @param fn
5+
* @param wait
6+
* @returns
7+
*
8+
* @example
9+
* ```ts
10+
* // logs window dimensions at most every 250ms
11+
* window.addEventListener(
12+
* "resize",
13+
* throttle(function (evt) {
14+
* console.log(window.innerWidth)
15+
* console.log(window.innerHeight)
16+
* }, 250)
17+
* )
18+
*/
19+
export const throttle = (fn: Function, wait: number = 300) => {
20+
let inThrottle: boolean
21+
let lastFn: ReturnType<typeof setTimeout>
22+
let lastTime: number
23+
24+
return function (this: any) {
25+
const context = this
26+
const args = arguments
27+
28+
if (!inThrottle) {
29+
fn.apply(context, args)
30+
31+
lastTime = Date.now()
32+
inThrottle = true
33+
} else {
34+
clearTimeout(lastFn)
35+
36+
lastFn = setTimeout(() => {
37+
if (Date.now() - lastTime >= wait) {
38+
fn.apply(context, args)
39+
lastTime = Date.now()
40+
}
41+
}, Math.max(wait - (Date.now() - lastTime), 0))
42+
}
43+
}
44+
}

.stacks/core/utils/src/vendor.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)