Files
Automata/packages/editor-ui/src/mixins/debounce.ts
Alex Grozav 9c94050deb feat: Replace Vue.extend with defineComponent in editor-ui (no-changelog) (#6033)
* refactor: replace Vue.extend with defineComponent in editor-ui

* fix: change $externalHooks extractions from mixins

* fix: refactor externalHooks mixin
2023-04-21 18:51:08 +03:00

30 lines
822 B
TypeScript

import { debounce } from 'lodash-es';
import { defineComponent } from 'vue';
export const debounceHelper = defineComponent({
data() {
return {
debouncedFunctions: [] as any[],
};
},
methods: {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
async callDebounced(...inputParameters: any[]): Promise<void> {
const functionName = inputParameters.shift() as string;
const { trailing, debounceTime } = inputParameters.shift();
// @ts-ignore
if (this.debouncedFunctions[functionName] === undefined) {
// @ts-ignore
this.debouncedFunctions[functionName] = debounce(
this[functionName],
debounceTime,
trailing ? { trailing } : { leading: true },
);
}
// @ts-ignore
await this.debouncedFunctions[functionName].apply(this, inputParameters);
},
},
});