mirror of
https://github.com/Art051/it-tools.git
synced 2025-08-11 19:29:03 +00:00
fix(otp-generator): better computation of token
This commit is contained in:
committed by
Corentin THOMASSET
parent
15cb03347c
commit
5281824b5d
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user