mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-04-26 01:36:15 -04:00
fix(otp-generator): better computation of token
This commit is contained in:
parent
15cb03347c
commit
5281824b5d
2 changed files with 21 additions and 26 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue