Files
Automata/packages/editor-ui/src/mixins/debounce.ts
Csaba Tuncsik 50f568560f perf: Make frontend linting faster (no-changelog) (#7717)
Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
2023-11-22 15:01:22 +01:00

31 lines
850 B
TypeScript

import { debounce } from 'lodash-es';
import { defineComponent } from 'vue';
export const debounceHelper = defineComponent({
data() {
return {
debouncedFunctions: {} as Record<string, (...args: unknown[]) => Promise<void> | void>,
};
},
methods: {
async callDebounced(
functionName: string,
options: { debounceTime: number; trailing?: boolean },
...inputParameters: unknown[]
): Promise<void> {
const { trailing, debounceTime } = options;
if (this.debouncedFunctions[functionName] === undefined) {
this.debouncedFunctions[functionName] = debounce(
async (...args: unknown[]) => {
// @ts-ignore
await this[functionName](...args);
},
debounceTime,
trailing ? { trailing } : { leading: true },
);
}
await this.debouncedFunctions[functionName](...inputParameters);
},
},
});