fix(otp-generator): better computation of token

This commit is contained in:
Corentin Thomasset authored and Corentin THOMASSET committed 2023-03-31 01:01:44 +02:00
1 parent 15cb03347c
commit 5281824b5d
2 files changed
+21 -26

No files matched your search

+7 -3
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) {