perf(@vant/use): reduce usePageVisibility event binding (#9835)

* perf(@vant/use): reduce usePageVisibility event binding

* chore: update
This commit is contained in:
neverland
2021-11-11 17:25:48 +08:00
committed by GitHub
parent a9ce9096e4
commit a0b368f1b4
4 changed files with 21 additions and 23 deletions
+5 -8
View File
@@ -1,19 +1,16 @@
import { Ref, unref } from 'vue';
function isWindow(val: unknown): val is Window {
return val === window;
}
const isWindow = (val: unknown): val is Window => val === window;
function makeDOMRect(width: number, height: number) {
return {
const makeDOMRect = (width: number, height: number) =>
({
top: 0,
left: 0,
right: width,
bottom: height,
width,
height,
} as DOMRect;
}
} as DOMRect);
export const useRect = (
elementOrRef: Element | Window | Ref<Element | Window | undefined>
@@ -26,7 +23,7 @@ export const useRect = (
return makeDOMRect(width, height);
}
if (element && element.getBoundingClientRect) {
if (element?.getBoundingClientRect) {
return element.getBoundingClientRect();
}