|
| 1 | +import { Conditions, Config, Mutate, UseConditionWatcherReturn } from './types' |
1 | 2 | import { |
| 3 | + UnwrapNestedRefs, |
| 4 | + computed, |
| 5 | + getCurrentInstance, |
| 6 | + isRef, |
| 7 | + onUnmounted, |
2 | 8 | reactive, |
| 9 | + readonly, |
3 | 10 | ref, |
| 11 | + shallowRef, |
| 12 | + unref, |
4 | 13 | watch, |
5 | | - readonly, |
6 | | - UnwrapNestedRefs, |
7 | | - onUnmounted, |
8 | 14 | watchEffect, |
9 | | - unref, |
10 | | - isRef, |
11 | | - shallowRef, |
12 | | - computed, |
13 | | - getCurrentInstance, |
14 | 15 | } from 'vue-demi' |
15 | | -import { Config, UseConditionWatcherReturn, Conditions, Mutate } from './types' |
16 | | -import { usePromiseQueue, useHistory, useCache, createEvents } from 'vue-condition-watcher/_internal' |
| 16 | +import { containsProp, isNoData as isDataEmpty, isObject, isServer, rAF } from 'vue-condition-watcher/_internal' |
| 17 | +import { createEvents, useCache, useHistory, usePromiseQueue } from 'vue-condition-watcher/_internal' |
17 | 18 | import { |
18 | | - filterNoneValueObject, |
19 | 19 | createParams, |
20 | | - syncQuery2Conditions, |
21 | | - isEquivalent, |
22 | 20 | deepClone, |
| 21 | + filterNoneValueObject, |
| 22 | + isEquivalent, |
23 | 23 | pick, |
| 24 | + syncQuery2Conditions, |
24 | 25 | } from 'vue-condition-watcher/_internal' |
25 | | -import { containsProp, isNoData as isDataEmpty, isObject, isServer, rAF } from 'vue-condition-watcher/_internal' |
26 | 26 |
|
27 | 27 | export default function useConditionWatcher<Cond extends Record<string, any>, Result, AfterFetchResult = Result>( |
28 | 28 | config: Config<Cond, Result, AfterFetchResult> |
@@ -209,11 +209,13 @@ export default function useConditionWatcher<Cond extends Record<string, any>, Re |
209 | 209 | if (pollingTimer.value) return |
210 | 210 |
|
211 | 211 | watchEffect((onCleanup) => { |
212 | | - if (unref(watcherConfig.pollingInterval)) { |
| 212 | + const pollingInterval = unref(watcherConfig.pollingInterval) |
| 213 | + |
| 214 | + if (pollingInterval) { |
213 | 215 | pollingTimer.value = (() => { |
214 | 216 | let timerId = null |
215 | 217 | function next() { |
216 | | - const interval = unref(watcherConfig.pollingInterval) |
| 218 | + const interval = pollingInterval |
217 | 219 | if (interval && timerId !== -1) { |
218 | 220 | timerId = setTimeout(nun, interval) |
219 | 221 | } |
@@ -249,23 +251,23 @@ export default function useConditionWatcher<Cond extends Record<string, any>, Re |
249 | 251 | * - 1. |
250 | 252 | * mutate(newData) |
251 | 253 | * - 2. |
252 | | - * mutate((currentData) => { |
253 | | - * currentData[0].name = 'runkids' |
254 | | - * return currentData |
| 254 | + * mutate((draft) => { |
| 255 | + * draft[0].name = 'runkids' |
| 256 | + * return draft |
255 | 257 | * }) |
256 | 258 | */ |
257 | | - const mutate = (...args): Mutate => { |
| 259 | + const mutate = (...args): Mutate<Result> => { |
258 | 260 | const arg = args[0] |
259 | 261 | if (arg === undefined) { |
260 | | - return data.value as any |
| 262 | + return data.value |
261 | 263 | } |
262 | 264 | if (typeof arg === 'function') { |
263 | 265 | data.value = arg(deepClone(data.value)) |
264 | 266 | } else { |
265 | 267 | data.value = arg |
266 | 268 | } |
267 | 269 | cache.set({ ..._conditions }, data.value) |
268 | | - return data.value as any |
| 270 | + return data.value |
269 | 271 | } |
270 | 272 |
|
271 | 273 | // - History mode base on vue-router |
|
0 commit comments