Skip to content

Commit b1bc804

Browse files
authored
feat(computedAsync): add option to control watcher's flush timing (#4746)
1 parent 92d855e commit b1bc804

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

packages/core/computedAsync/index.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
import type { Fn } from '@vueuse/shared'
22
import type { Ref } from 'vue'
33
import { noop } from '@vueuse/shared'
4-
import { computed, ref as deepRef, isRef, shallowRef, watchEffect } from 'vue'
4+
import {
5+
computed,
6+
ref as deepRef,
7+
isRef,
8+
shallowRef,
9+
watchEffect,
10+
} from 'vue'
511

612
/**
713
* Handle overlapping async evaluations.
@@ -30,6 +36,16 @@ export interface AsyncComputedOptions {
3036
*/
3137
shallow?: boolean
3238

39+
/**
40+
* The flush option allows for greater control over the timing of a history point, default to `pre`
41+
*
42+
* Possible values: `pre`, `post`, `sync`
43+
*
44+
* It works in the same way as the flush option in watch and watch effect in vue reactivity
45+
* @default 'pre'
46+
*/
47+
flush?: 'pre' | 'post' | 'sync'
48+
3349
/**
3450
* Callback when error is caught.
3551
*/
@@ -72,6 +88,7 @@ export function computedAsync<T>(
7288

7389
const {
7490
lazy = false,
91+
flush = 'pre',
7592
evaluating = undefined,
7693
shallow = true,
7794
onError = noop,
@@ -120,7 +137,7 @@ export function computedAsync<T>(
120137

121138
hasFinished = true
122139
}
123-
})
140+
}, { flush })
124141

125142
if (lazy) {
126143
return computed(() => {

0 commit comments

Comments
 (0)