types: massive refactor
This commit is contained in:
@@ -21,7 +21,12 @@ import {
|
||||
} from './errorHandling'
|
||||
import { onBeforeUnmount } from './apiLifecycle'
|
||||
import { queuePostRenderEffect } from './createRenderer'
|
||||
import { WatchHandler } from './apiOptions'
|
||||
|
||||
export type WatchHandler<T = any> = (
|
||||
value: T,
|
||||
oldValue: T,
|
||||
onCleanup: CleanupRegistrator
|
||||
) => any
|
||||
|
||||
export interface WatchOptions {
|
||||
lazy?: boolean
|
||||
@@ -58,11 +63,7 @@ export function watch<T>(
|
||||
// overload #3: array of multiple sources + cb
|
||||
export function watch<T extends readonly WatcherSource<unknown>[]>(
|
||||
sources: T,
|
||||
cb: (
|
||||
newValues: MapSources<T>,
|
||||
oldValues: MapSources<T>,
|
||||
onCleanup: CleanupRegistrator
|
||||
) => any,
|
||||
cb: WatchHandler<MapSources<T>>,
|
||||
options?: WatchOptions
|
||||
): StopHandle
|
||||
|
||||
@@ -84,9 +85,7 @@ export function watch<T = any>(
|
||||
|
||||
function doWatch(
|
||||
source: WatcherSource | WatcherSource[] | SimpleEffect,
|
||||
cb:
|
||||
| ((newValue: any, oldValue: any, onCleanup: CleanupRegistrator) => any)
|
||||
| null,
|
||||
cb: WatchHandler | null,
|
||||
{ lazy, deep, flush, onTrack, onTrigger }: WatchOptions = EMPTY_OBJ
|
||||
): StopHandle {
|
||||
const instance = currentInstance
|
||||
@@ -95,11 +94,10 @@ function doWatch(
|
||||
let getter: () => any
|
||||
if (isArray(source)) {
|
||||
getter = () =>
|
||||
source.map(
|
||||
s =>
|
||||
isRef(s)
|
||||
? s.value
|
||||
: callWithErrorHandling(s, instance, ErrorCodes.WATCH_GETTER)
|
||||
source.map(s =>
|
||||
isRef(s)
|
||||
? s.value
|
||||
: callWithErrorHandling(s, instance, ErrorCodes.WATCH_GETTER)
|
||||
)
|
||||
} else if (isRef(source)) {
|
||||
getter = () => source.value
|
||||
@@ -218,7 +216,7 @@ export function instanceWatch(
|
||||
return stop
|
||||
}
|
||||
|
||||
function traverse(value: any, seen: Set<any> = new Set()) {
|
||||
function traverse(value: unknown, seen: Set<unknown> = new Set()) {
|
||||
if (!isObject(value) || seen.has(value)) {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user