Skip to content

Commit

Permalink
fix: slowly when many items checked
Browse files Browse the repository at this point in the history
  • Loading branch information
yujinpan committed Sep 30, 2024
1 parent 78c44fe commit d8516e7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/components/CacheOption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import Vue from 'vue';

import type { PropType } from 'vue';

import { debounce } from '@/components/utils';

export type CacheOption = {
value: string | number | boolean | object;
currentLabel: string | number;
Expand All @@ -24,9 +26,6 @@ const CacheOptions = Vue.extend({
data() {
this.update();
},
values() {
this.update();
},
},
methods: {
update() {
Expand Down Expand Up @@ -58,6 +57,8 @@ const CacheOptions = Vue.extend({
return undefined;
},
mounted() {
this.update = debounce(this.update, 100);

this.update();
},
});
Expand Down
13 changes: 13 additions & 0 deletions src/components/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,19 @@ export const banReactive = (obj: Obj) => {
return obj;
};

export function debounce<T extends (...args: any[]) => any>(
cb: T,
duration: number,
): T {
let timeId: any;
return ((...args) => {
if (timeId) clearTimeout(timeId);
timeId = setTimeout(() => {
cb(...args);
}, duration);
}) as T;
}

export function throttle<T extends (...args: any[]) => any>(
cb: T,
duration: number,
Expand Down

0 comments on commit d8516e7

Please sign in to comment.