Revert "feat: 使用 radash 的 throttle 包装 load 函数,优化加载频率并重构 refresh 方法"

This reverts commit 40bf214da7.
This commit is contained in:
严浩
2024-12-11 15:44:43 +08:00
parent 40bf214da7
commit aa902ed159

View File

@ -1,6 +1,4 @@
<script lang="ts">
import { throttle } from 'radash';
function checkIsVisible(el: Element, root: Element | null = null) {
if (!el) return false;
@ -45,12 +43,19 @@ defineSlots<{
// 加载失败
error(props: { retry: () => void }): unknown;
}>();
defineExpose({
refresh: () => {
currentPage = 0;
state.value = '';
return load('refresh');
},
});
const target = ref(null);
let currentPage = 0;
const state = ref<'' | 'loading' | 'loaded' | 'complete' | 'error'>('');
const loadImpl = async (why?: string) => {
const load = async (why?: string) => {
console.group('load');
console.debug(`why :>> `, why);
console.groupEnd();
@ -76,19 +81,6 @@ const loadImpl = async (why?: string) => {
}
};
// 使用radash的throttle包装load函数,1秒内最多执行一次
const load = throttle({ interval: 1000 }, loadImpl);
const refresh = () => {
currentPage = 0;
state.value = '';
return loadImpl('refresh'); // refresh 不需要节流
};
defineExpose({
refresh,
});
const { pause, resume /* ,isSupported, isActive */ } = useIntersectionObserver(
target,
([entry]) => {