Skip to content

Commit e71274b

Browse files
committed
improve computed type signature
1 parent a4cf142 commit e71274b

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/api/computed-watch-api.md

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,31 @@ console.log(count.value) // 0
3434

3535
```ts
3636
// read-only
37-
function computed<T>(getter: () => T): Readonly<Ref<Readonly<T>>>
37+
function computed<T>(
38+
getter: () => T,
39+
debuggerOptions?: DebuggerOptions
40+
): Readonly<Ref<Readonly<T>>>
3841

3942
// writable
40-
function computed<T>(options: { get: () => T; set: (value: T) => void }): Ref<T>
43+
function computed<T>(
44+
options: {
45+
get: () => T
46+
set: (value: T) => void
47+
},
48+
debuggerOptions?: DebuggerOptions
49+
): Ref<T>
50+
51+
interface DebuggerOptions {
52+
onTrack?: (event: DebuggerEvent) => void
53+
onTrigger?: (event: DebuggerEvent) => void
54+
}
55+
56+
interface DebuggerEvent {
57+
effect: ReactiveEffect
58+
target: any
59+
type: OperationTypes
60+
key: string | symbol | undefined
61+
}
4162
```
4263

4364
## `watchEffect`
@@ -94,7 +115,7 @@ Alias of `watchEffect` with `flush: 'sync'` option.
94115
95116
## `watch`
96117
97-
The `watch` API is the exact equivalent of the Options API [this.$watch](./instance-methods.html#watch) (and the corresponding [watch](./options-data.html#watch) option). `watch` requires watching a specific data source and applies side effects in a separate callback function. It also is lazy by default - i.e. the callback is only called when the watched source has changed.
118+
The `watch` API is the exact equivalent of the Options API [this.\$watch](./instance-methods.html#watch) (and the corresponding [watch](./options-data.html#watch) option). `watch` requires watching a specific data source and applies side effects in a separate callback function. It also is lazy by default - i.e. the callback is only called when the watched source has changed.
98119
99120
- Compared to [watchEffect](#watcheffect), `watch` allows us to:
100121

0 commit comments

Comments
 (0)