Skip to content

Commit

Permalink
fix: remove window
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Nov 29, 2021
1 parent 0dd6065 commit 65fc82e
Show file tree
Hide file tree
Showing 21 changed files with 44 additions and 113 deletions.
4 changes: 2 additions & 2 deletions components/_util/css-animation/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ const TransitionEvents = {

addStartEventListener(node, eventListener) {
if (startEvents.length === 0) {
window.setTimeout(eventListener, 0);
setTimeout(eventListener, 0);
return;
}
startEvents.forEach(startEvent => {
Expand All @@ -109,7 +109,7 @@ const TransitionEvents = {

addEndEventListener(node, eventListener) {
if (endEvents.length === 0) {
window.setTimeout(eventListener, 0);
setTimeout(eventListener, 0);
return;
}
endEvents.forEach(endEvent => {
Expand Down
2 changes: 2 additions & 0 deletions components/_util/css-animation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import Event from './Event';
import classes from '../component-classes';
import { requestAnimationTimeout, cancelAnimationTimeout } from '../requestAnimationTimeout';
import { inBrowser } from '../env';

const isCssAnimationSupported = Event.endEvents.length !== 0;
const capitalPrefixes = [
Expand All @@ -15,6 +16,7 @@ const capitalPrefixes = [
const prefixes = ['-webkit-', '-moz-', '-o-', 'ms-', ''];

function getStyleProperty(node, name) {
if (inBrowser) return '';
// old ff need null, https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle
const style = window.getComputedStyle(node, null);
let ret = '';
Expand Down
24 changes: 0 additions & 24 deletions components/_util/dom-closest.js

This file was deleted.

47 changes: 0 additions & 47 deletions components/_util/dom-matches.js

This file was deleted.

2 changes: 1 addition & 1 deletion components/_util/transition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const collapseMotion = (style: Ref<CSSProperties>, className: Ref<string>): CSSM
style.value = getCurrentHeight(node);
},
onLeave: node => {
window.setTimeout(() => {
setTimeout(() => {
style.value = getCollapsedHeight(node);
});
},
Expand Down
2 changes: 1 addition & 1 deletion components/_util/wave.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default defineComponent({
getComputedStyle(node).getPropertyValue('border-top-color') || // Firefox Compatible
getComputedStyle(node).getPropertyValue('border-color') ||
getComputedStyle(node).getPropertyValue('background-color');
this.clickWaveTimeoutId = window.setTimeout(() => this.onClick(node, waveColor), 0);
this.clickWaveTimeoutId = setTimeout(() => this.onClick(node, waveColor), 0);
raf.cancel(this.animationStartId);
this.animationStart = true;

Expand Down
2 changes: 1 addition & 1 deletion components/button/button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default defineComponent({
val => {
clearTimeout(delayTimeoutRef.value);
if (typeof loadingOrDelay.value === 'number') {
delayTimeoutRef.value = window.setTimeout(() => {
delayTimeoutRef.value = setTimeout(() => {
innerLoading.value = val;
}, loadingOrDelay.value);
} else {
Expand Down
6 changes: 3 additions & 3 deletions components/form/ErrorList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ export default defineComponent({
const timeout = ref();
const cacheErrors = ref([...props.errors]);
watch([() => [...props.errors], () => props.help], newValues => {
window.clearTimeout(timeout.value);
clearTimeout(timeout.value);
if (props.help) {
visible.value = !!(props.errors && props.errors.length);
if (visible.value) {
cacheErrors.value = newValues[0];
}
} else {
timeout.value = window.setTimeout(() => {
timeout.value = setTimeout(() => {
visible.value = !!(props.errors && props.errors.length);
if (visible.value) {
cacheErrors.value = newValues[0];
Expand All @@ -40,7 +40,7 @@ export default defineComponent({
}
});
onBeforeUnmount(() => {
window.clearTimeout(timeout.value);
clearTimeout(timeout.value);
});
// Memo status in same visible
watch([visible, status], () => {
Expand Down
6 changes: 3 additions & 3 deletions components/menu/src/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ export default defineComponent({
{ immediate: true },
);

let timeout: number;
let timeout: any;
const changeActiveKeys = (keys: Key[]) => {
window.clearTimeout(timeout);
timeout = window.setTimeout(() => {
clearTimeout(timeout);
timeout = setTimeout(() => {
if (props.activeKey === undefined) {
activeKeys.value = keys;
}
Expand Down
4 changes: 2 additions & 2 deletions components/statistic/Countdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default defineComponent({
}),
emits: ['finish', 'change'],
setup(props, { emit }) {
const countdownId = ref<number>();
const countdownId = ref<any>();
const statistic = ref();
const syncTimer = () => {
const { value } = props;
Expand All @@ -32,7 +32,7 @@ export default defineComponent({
const startTimer = () => {
if (countdownId.value) return;
const timestamp = getTime(props.value);
countdownId.value = window.setInterval(() => {
countdownId.value = setInterval(() => {
statistic.value.$forceUpdate();
if (timestamp > Date.now()) {
emit('change', timestamp - Date.now());
Expand Down
6 changes: 3 additions & 3 deletions components/table/hooks/useFilter/FilterDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -181,16 +181,16 @@ export default defineComponent<FilterDropdownProps<any>>({
const openRef = ref();

const onOpenChange = (keys: string[]) => {
openRef.value = window.setTimeout(() => {
openRef.value = setTimeout(() => {
openKeys.value = keys;
});
};
const onMenuClick = () => {
window.clearTimeout(openRef.value);
clearTimeout(openRef.value);
};

onBeforeUnmount(() => {
window.clearTimeout(openRef.value);
clearTimeout(openRef.value);
});

// ======================= Submit ========================
Expand Down
6 changes: 3 additions & 3 deletions components/tabs/src/TabNavList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ export default defineComponent({
};

// ========================= Mobile ========================
const touchMovingRef = ref<number>();
const touchMovingRef = ref<any>();
const [lockAnimation, setLockAnimation] = useState<number>();

const doLockAnimation = () => {
setLockAnimation(Date.now());
};

const clearTouchMoving = () => {
window.clearTimeout(touchMovingRef.value);
clearTimeout(touchMovingRef.value);
};
const doMove = (setState: (fn: (val: number) => number) => void, offset: number) => {
setState((value: number) => {
Expand Down Expand Up @@ -171,7 +171,7 @@ export default defineComponent({
watch(lockAnimation, () => {
clearTouchMoving();
if (lockAnimation.value) {
touchMovingRef.value = window.setTimeout(() => {
touchMovingRef.value = setTimeout(() => {
setLockAnimation(0);
}, 100);
}
Expand Down
8 changes: 4 additions & 4 deletions components/tabs/src/hooks/useTouchMove.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ export default function useTouchMove(
const [lastTimestamp, setLastTimestamp] = useState<number>(0);
const [lastTimeDiff, setLastTimeDiff] = useState<number>(0);
const [lastOffset, setLastOffset] = useState<{ x: number; y: number }>();
const motionRef = ref<number>();
const motionInterval = ref<any>();

// ========================= Events =========================
// >>> Touch events
function onTouchStart(e: TouchEvent) {
const { screenX, screenY } = e.touches[0];
setTouchPosition({ x: screenX, y: screenY });
window.clearInterval(motionRef.value);
clearInterval(motionInterval.value);
}

function onTouchMove(e: TouchEvent) {
Expand Down Expand Up @@ -62,9 +62,9 @@ export default function useTouchMove(
let currentX = distanceX;
let currentY = distanceY;

motionRef.value = window.setInterval(() => {
motionInterval.value = setInterval(() => {
if (Math.abs(currentX) < STOP_SWIPE_DISTANCE && Math.abs(currentY) < STOP_SWIPE_DISTANCE) {
window.clearInterval(motionRef.value);
clearInterval(motionInterval.value);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions components/typography/Base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ const Base = defineComponent<InternalBlockProps>({
});

onBeforeUnmount(() => {
window.clearTimeout(state.copyId);
clearTimeout(state.copyId);
raf.cancel(state.rafId);
});

Expand Down Expand Up @@ -223,7 +223,7 @@ const Base = defineComponent<InternalBlockProps>({
copyConfig.onCopy();
}

state.copyId = window.setTimeout(() => {
state.copyId = setTimeout(() => {
state.copied = false;
}, 3000);
});
Expand Down
6 changes: 3 additions & 3 deletions components/vc-align/hooks/useBuffer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default (callback: () => boolean, buffer: ComputedRef<number>) => {
let timeout = null;

function cancelTrigger() {
window.clearTimeout(timeout);
clearTimeout(timeout);
}

function trigger(force?: boolean) {
Expand All @@ -17,12 +17,12 @@ export default (callback: () => boolean, buffer: ComputedRef<number>) => {

called = true;
cancelTrigger();
timeout = window.setTimeout(() => {
timeout = setTimeout(() => {
called = false;
}, buffer.value);
} else {
cancelTrigger();
timeout = window.setTimeout(() => {
timeout = setTimeout(() => {
called = false;
trigger();
}, buffer.value);
Expand Down
4 changes: 2 additions & 2 deletions components/vc-mentions/src/Mentions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@ export default defineComponent({
onBlur(event);
};
const onFocus = (event: Event) => {
window.clearTimeout(focusId.value);
clearTimeout(focusId.value);
const { isFocus } = state;
if (!isFocus && event) {
emit('focus', event);
}
state.isFocus = true;
};
const onBlur = (event: Event) => {
focusId.value = window.setTimeout(() => {
focusId.value = setTimeout(() => {
state.isFocus = false;
stopMeasure();
emit('blur', event);
Expand Down
2 changes: 1 addition & 1 deletion components/vc-picker/RangePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ function RangerPicker<DateType>() {
function triggerOpenAndFocus(index: 0 | 1) {
triggerOpen(true, index);
// Use setTimeout to make sure panel DOM exists
window.setTimeout(() => {
setTimeout(() => {
const inputRef = [startInputRef, endInputRef][index];
if (inputRef.value) {
inputRef.value.focus();
Expand Down
6 changes: 3 additions & 3 deletions components/vc-select/hooks/useDelayReset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ export default function useDelayReset(
timeout = 10,
): [Ref<Boolean>, (val: boolean, callback?: () => void) => void, () => void] {
const bool = ref(false);
let delay: number;
let delay: any;

const cancelLatest = () => {
window.clearTimeout(delay);
clearTimeout(delay);
};

onMounted(() => {
cancelLatest();
});
const delaySetBool = (value: boolean, callback: () => void) => {
cancelLatest();
delay = window.setTimeout(() => {
delay = setTimeout(() => {
bool.value = value;
if (callback) {
callback();
Expand Down
8 changes: 4 additions & 4 deletions components/vc-select/hooks/useLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import { onBeforeUpdate } from 'vue';
*/
export default function useLock(duration = 250): [() => boolean | null, (lock: boolean) => void] {
let lock: boolean | null = null;
let timeout: number;
let timeout: any;

onBeforeUpdate(() => {
window.clearTimeout(timeout);
clearTimeout(timeout);
});

function doLock(locked: boolean) {
if (locked || lock === null) {
lock = locked;
}

window.clearTimeout(timeout);
timeout = window.setTimeout(() => {
clearTimeout(timeout);
timeout = setTimeout(() => {
lock = null;
}, duration);
}
Expand Down
Loading

0 comments on commit 65fc82e

Please sign in to comment.