Skip to content

Commit e314a90

Browse files
authored
style: 🎨 notes & type prefix
style: 🎨 notes & type prefix
2 parents 0b89bf3 + 89f82eb commit e314a90

File tree

67 files changed

+2291
-700
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2291
-700
lines changed

packages/hooks/src/useAsyncOrder/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useTimeout } from '../index'
33
export type Resolve = (value: any) => void
44
export type InterruptibleRejectType = (error: any) => void
55

6-
export type AsyncOrder = {
6+
export type UseAsyncOrderType = {
77
task: ((resolve?: Resolve, reject?: InterruptibleRejectType, index?: number) => void)[]
88
option?: {
99
/**
@@ -33,7 +33,7 @@ export type AsyncOrder = {
3333
}
3434
}
3535

36-
export default function useAsyncOrder({ task, option }: AsyncOrder) {
36+
export default function useAsyncOrder({ task, option }: UseAsyncOrderType) {
3737
const { delay = 0, onError, onReady, onSuccess } = option ?? {}
3838

3939
if (!(task instanceof Array)) {

packages/hooks/src/useBoolean/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Ref } from "vue";
22
import useToggle from "../useToggle";
33

4-
export interface Actions {
4+
export interface UseBooleanActions {
55
/**
66
* Set state to `true`
77
* @returns void
@@ -28,7 +28,7 @@ export interface Actions {
2828
toggle: () => void;
2929
}
3030

31-
export type UseBooleanResult = [Ref<boolean>, Actions]
31+
export type UseBooleanResult = [Ref<boolean>, UseBooleanActions]
3232

3333
export default function useBoolean(
3434
defaultValue = false

packages/hooks/src/useCookieState/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import Cookies from 'js-cookie'
22
import { ref } from 'vue'
33
import { isFunction } from '../utils/isFunction'
44

5-
export type State = string | undefined
5+
export type UseCookieStateType = string | undefined
66

7-
export interface Options extends Cookies.CookieAttributes {
8-
defaultValue?: State | (() => State)
7+
export interface UseCookieStateOptions extends Cookies.CookieAttributes {
8+
defaultValue?: UseCookieStateType | (() => UseCookieStateType)
99
}
1010

11-
function useCookieState(cookieKey: string, options: Options = {}) {
11+
function useCookieState(cookieKey: string, options: UseCookieStateOptions = {}) {
1212
const defaultValue = () => {
1313
const cookieValue = Cookies.get(cookieKey)
1414

@@ -22,7 +22,7 @@ function useCookieState(cookieKey: string, options: Options = {}) {
2222
const state = ref(defaultValue())
2323

2424
const updateState = (
25-
newValue: State | ((prevState: State) => State),
25+
newValue: UseCookieStateType | ((prevState: UseCookieStateType) => UseCookieStateType),
2626
newOptions: Cookies.CookieAttributes = {},
2727
) => {
2828
// eslint-disable-next-line no-unused-vars

packages/hooks/src/useCounter/index.ts

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,50 @@
1-
import { ref } from 'vue'
1+
import { Ref, ref } from 'vue'
22
import { isNumber } from '../utils'
33

4-
export interface Options {
4+
export interface UseCounterOptions {
5+
/**
6+
* Min count
7+
*/
58
min?: number
9+
10+
/**
11+
* Max count
12+
*/
613
max?: number
714
}
815

9-
export interface Actions {
16+
export interface UseCounterActions {
17+
/**
18+
* Increment, default delta is 1
19+
* @param delta number
20+
* @returns void
21+
*/
1022
inc: (delta?: number) => void
23+
24+
/**
25+
* Decrement, default delta is 1
26+
* @param delta number
27+
* @returns void
28+
*/
1129
dec: (delta?: number) => void
30+
31+
/**
32+
* Set current value
33+
* @param value number | ((c: number) => number)
34+
* @returns void
35+
*/
1236
set: (value: number | ((c: number) => number)) => void
37+
38+
/**
39+
* Reset current value to initial value
40+
* @returns void
41+
*/
1342
reset: () => void
1443
}
1544

1645
export type ValueParam = number | ((c: number) => number)
1746

18-
function getTargetValue(val: number, options: Options = {}) {
47+
function getTargetValue(val: number, options: UseCounterOptions = {}) {
1948
const { min, max } = options
2049
let target = val
2150
if (isNumber(max)) {
@@ -27,7 +56,10 @@ function getTargetValue(val: number, options: Options = {}) {
2756
return target
2857
}
2958

30-
function useCounter(initialValue = 0, options: Options = {}) {
59+
function useCounter(
60+
initialValue = 0,
61+
options: UseCounterOptions = {},
62+
): [Ref<number>, UseCounterActions] {
3163
const { min, max } = options
3264

3365
const current = ref(
@@ -70,7 +102,7 @@ function useCounter(initialValue = 0, options: Options = {}) {
70102
set,
71103
reset,
72104
},
73-
] as const
105+
]
74106
}
75107

76108
export default useCounter
Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
11
import { watchEffect, computed, ComputedRef } from 'vue'
2-
import { useLocalStorageState } from '..'
2+
import useLocalStorageState from '../useLocalStorageState'
33

44
import useMedia from '../useMedia'
55

6-
export default function useDarkMode(): [
7-
ComputedRef<any>,
8-
(value?: unknown) => void
9-
] {
10-
const [enabledState, setEnabledState] = useLocalStorageState(
11-
'dark-mode-enabled'
12-
)
6+
export default function useDarkMode(): [ComputedRef<any>, (value?: unknown) => void] {
7+
const [enabledState, setEnabledState] = useLocalStorageState('dark-mode-enabled')
138

14-
const prefersDarkMode = usePrefersDarkMode()
9+
const prefersDarkMode = usePrefersDarkMode()
1510

16-
const enabled = computed(() => {
17-
return typeof enabledState.value !== 'undefined'
18-
? enabledState.value
19-
: prefersDarkMode.value
20-
})
11+
/**
12+
* Is it in dark mode
13+
*/
14+
const enabled = computed(() => {
15+
return typeof enabledState.value !== 'undefined' ? enabledState.value : prefersDarkMode.value
16+
})
2117

22-
watchEffect(() => {
23-
const className = 'dark-mode'
24-
const element = window.document.body
25-
if (enabled.value) {
26-
element.classList.add(className)
27-
} else {
28-
element.classList.remove(className)
29-
}
30-
})
31-
return [enabled, setEnabledState]
18+
watchEffect(() => {
19+
const className = 'dark-mode'
20+
const element = window.document.body
21+
if (enabled.value) {
22+
element.classList.add(className)
23+
} else {
24+
element.classList.remove(className)
25+
}
26+
})
27+
return [enabled, setEnabledState]
3228
}
3329

3430
function usePrefersDarkMode() {
35-
return useMedia(['(prefers-color-scheme: dark)'], [true], false)
31+
return useMedia(['(prefers-color-scheme: dark)'], [true], false)
3632
}

packages/hooks/src/useDebounceFn/index.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
import debounce from 'lodash/debounce'
22

33
export interface DebounceOptions {
4+
/**
5+
* The number of milliseconds to delay.
6+
*/
47
wait?: number
8+
9+
/**
10+
* Specify invoking on the leading edge of the timeout.
11+
*/
512
leading?: boolean
13+
14+
/**
15+
* Specify invoking on the trailing edge of the timeout.
16+
*/
617
trailing?: boolean
18+
19+
/**
20+
* The maximum time func is allowed to be delayed before it’s invoked.
21+
*/
722
maxWait?: number
823
}
924

@@ -13,8 +28,22 @@ function useDebounceFn<T extends noop>(fn: T, options?: DebounceOptions) {
1328
const wait = options?.wait ?? 1000
1429
const debounced = debounce(fn, wait, options)
1530
return {
31+
/**
32+
* Invode and pass parameters to fn.
33+
* `(...args: any[]) => any`
34+
*/
1635
run: debounced,
36+
37+
/**
38+
* Cancel the invocation of currently debounced function.
39+
* `() => void`
40+
*/
1741
cancel: debounced.cancel,
42+
43+
/**
44+
* Immediately invoke currently debounced function.
45+
* `() => void`
46+
*/
1847
flush: debounced.flush,
1948
}
2049
}

packages/hooks/src/useDrag/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,24 @@ import type { BasicTarget } from '../utils/domTarget'
33
import { getTargetElement } from '../utils/domTarget'
44
import useEffectWithTarget from '../utils/useEffectWithTarget'
55

6-
export interface Options {
6+
export interface UseDragOptions {
77
draggable?: boolean
8+
/**
9+
* On drag start callback
10+
* @param event DragEvent
11+
* @returns void
12+
*/
813
onDragStart?: (event: DragEvent) => void
14+
15+
/**
16+
* On drag end callback
17+
* @param event DragEvent
18+
* @returns void
19+
*/
920
onDragEnd?: (event: DragEvent) => void
1021
}
1122

12-
const useDrag = <T>(data: T, target: BasicTarget, options: Options = {}) => {
23+
const useDrag = <T>(data: T, target: BasicTarget, options: UseDragOptions = {}) => {
1324
const optionsRef = ref(options)
1425

1526
useEffectWithTarget(

0 commit comments

Comments
 (0)