chore(@vant/use): fix some lint issues (#8462)

This commit is contained in:
neverland 2021-04-06 20:03:26 +08:00 committed by GitHub
parent fe453dabb1
commit ace4c9b60b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 36 deletions

View File

@ -59,15 +59,15 @@ export default {
### 类型定义 ### 类型定义
```ts ```ts
type Options = {
eventName?: string;
};
function useClickAway( function useClickAway(
target: Element | Ref<Element | undefined>, target: Element | Ref<Element | undefined>,
listener: EventListener, listener: EventListener,
options?: Options options?: Options
): void; ): void;
type Options = {
eventName?: string;
};
``` ```
### 参数 ### 参数

View File

@ -62,13 +62,13 @@ export default {
### 类型定义 ### 类型定义
```ts ```ts
function useCountDown(options: UseCountDownOptions): CountDown; type CurrentTime = {
days: number;
type UseCountDownOptions = { hours: number;
time: number; total: number;
millisecond?: boolean; minutes: number;
onChange?: (current: CurrentTime) => void; seconds: number;
onFinish?: () => void; milliseconds: number;
}; };
type CountDown = { type CountDown = {
@ -78,14 +78,14 @@ type CountDown = {
current: ComputedRef<CurrentTime>; current: ComputedRef<CurrentTime>;
}; };
type CurrentTime = { type UseCountDownOptions = {
days: number; time: number;
hours: number; millisecond?: boolean;
total: number; onChange?: (current: CurrentTime) => void;
minutes: number; onFinish?: () => void;
seconds: number;
milliseconds: number;
}; };
function useCountDown(options: UseCountDownOptions): CountDown;
``` ```
### 参数 ### 参数

View File

@ -33,17 +33,17 @@ export default {
## 类型定义 ## 类型定义
```ts ```ts
function useEventListener(
type: string,
listener: EventListener,
options?: Options
): void;
type Options = { type Options = {
target?: EventTarget | Ref<EventTarget>; target?: EventTarget | Ref<EventTarget>;
capture?: boolean; capture?: boolean;
passive?: boolean; passive?: boolean;
}; };
function useEventListener(
type: string,
listener: EventListener,
options?: Options
): void;
``` ```
## API ## API

View File

@ -26,9 +26,9 @@ export default {
### 类型定义 ### 类型定义
```ts ```ts
function usePageVisibility(): Ref<VisibilityState>;
type VisibilityState = 'visible' | 'hidden'; type VisibilityState = 'visible' | 'hidden';
function usePageVisibility(): Ref<VisibilityState>;
``` ```
### 返回值 ### 返回值

View File

@ -31,7 +31,9 @@ export default {
### 类型定义 ### 类型定义
```ts ```ts
function useRect((Element | Window) | Ref<Element | Window | undefined>): DOMRect; function useRect(
element: Element | Window | Ref<Element | Window | undefined>
): DOMRect;
``` ```
### 返回值 ### 返回值

View File

@ -16,9 +16,9 @@ function makeDOMRect(width: number, height: number) {
} }
export const useRect = ( export const useRect = (
elementRef: (Element | Window) | Ref<Element | Window | undefined> elementOrRef: Element | Window | Ref<Element | Window | undefined>
) => { ) => {
const element = unref(elementRef); const element = unref(elementOrRef);
if (isWindow(element)) { if (isWindow(element)) {
const width = element.innerWidth; const width = element.innerWidth;

View File

@ -23,10 +23,7 @@ export function useParent<T>(key: string | symbol) {
const { link, unlink, internalChildren, ...rest } = parent; const { link, unlink, internalChildren, ...rest } = parent;
link(instance); link(instance);
onUnmounted(() => unlink(instance));
onUnmounted(() => {
unlink(instance);
});
const index = computed(() => internalChildren.indexOf(instance)); const index = computed(() => internalChildren.indexOf(instance));

View File

@ -24,7 +24,5 @@ export function cancelRaf(id: number) {
// double raf for animation // double raf for animation
export function doubleRaf(fn: FrameRequestCallback): void { export function doubleRaf(fn: FrameRequestCallback): void {
raf(() => { raf(() => raf(fn));
raf(fn);
});
} }