From 892fb6d2290516df44241992b62d65f1376f611a Mon Sep 17 00:00:00 2001 From: Evan You Date: Mon, 27 Apr 2020 13:33:57 -0400 Subject: [PATCH] types: use more consistent naming for apiWatch type exports BREAKING CHANGE: Some watch API types are renamed. - `BaseWatchOptions` -> `WatchOptionsBase` - `StopHandle` -> `WatchStopHandle` --- packages/runtime-core/src/apiWatch.ts | 20 ++++++++++---------- packages/runtime-core/src/index.ts | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index c1802e48..13e5ab02 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -54,26 +54,26 @@ type MapOldSources = { type InvalidateCbRegistrator = (cb: () => void) => void -export interface BaseWatchOptions { +export interface WatchOptionsBase { flush?: 'pre' | 'post' | 'sync' onTrack?: ReactiveEffectOptions['onTrack'] onTrigger?: ReactiveEffectOptions['onTrigger'] } -export interface WatchOptions extends BaseWatchOptions { +export interface WatchOptions extends WatchOptionsBase { immediate?: Immediate deep?: boolean } -export type StopHandle = () => void +export type WatchStopHandle = () => void const invoke = (fn: Function) => fn() // Simple effect. export function watchEffect( effect: WatchEffect, - options?: BaseWatchOptions -): StopHandle { + options?: WatchOptionsBase +): WatchStopHandle { return doWatch(effect, null, options) } @@ -85,7 +85,7 @@ export function watch = false>( source: WatchSource, cb: WatchCallback, options?: WatchOptions -): StopHandle +): WatchStopHandle // overload #2: array of multiple sources + cb // Readonly constraint helps the callback to correctly infer value types based @@ -98,14 +98,14 @@ export function watch< sources: T, cb: WatchCallback, MapOldSources>, options?: WatchOptions -): StopHandle +): WatchStopHandle // implementation export function watch( source: WatchSource | WatchSource[], cb: WatchCallback, options?: WatchOptions -): StopHandle { +): WatchStopHandle { if (__DEV__ && !isFunction(cb)) { warn( `\`watch(fn, options?)\` signature has been moved to a separate API. ` + @@ -120,7 +120,7 @@ function doWatch( source: WatchSource | WatchSource[] | WatchEffect, cb: WatchCallback | null, { immediate, deep, flush, onTrack, onTrigger }: WatchOptions = EMPTY_OBJ -): StopHandle { +): WatchStopHandle { if (__DEV__ && !cb) { if (immediate !== undefined) { warn( @@ -274,7 +274,7 @@ export function instanceWatch( source: string | Function, cb: Function, options?: WatchOptions -): StopHandle { +): WatchStopHandle { const publicThis = this.proxy as any const getter = isString(source) ? () => publicThis[source] diff --git a/packages/runtime-core/src/index.ts b/packages/runtime-core/src/index.ts index 3c008c86..57812f34 100644 --- a/packages/runtime-core/src/index.ts +++ b/packages/runtime-core/src/index.ts @@ -159,11 +159,11 @@ export { export { // types WatchEffect, - BaseWatchOptions, WatchOptions, + WatchOptionsBase, WatchCallback, WatchSource, - StopHandle + WatchStopHandle } from './apiWatch' export { InjectionKey } from './apiInject' export {