fix(otp-generator): better computation of token

This commit is contained in:
Corentin Thomasset 2023-03-31 00:49:45 +02:00 committed by Corentin THOMASSET
parent 15cb03347c
commit 5281824b5d
2 changed files with 21 additions and 26 deletions

View file

@ -1,15 +1,19 @@
import { computedAsync } from '@vueuse/core';
import { computedAsync, watchThrottled } from '@vueuse/core';
import { computed, ref, watch } from 'vue';
export { computedRefreshable, computedRefreshableAsync };
function computedRefreshable<T>(getter: () => T) {
function computedRefreshable<T>(getter: () => T, { throttle }: { throttle?: number } = {}) {
const dirty = ref(true);
let value: T;
const update = () => (dirty.value = true);
watch(getter, update);
if (throttle) {
watchThrottled(getter, update, { throttle });
} else {
watch(getter, update);
}
const computedValue = computed(() => {
if (dirty.value) {