types: use more consistent naming for apiWatch type exports

BREAKING CHANGE: Some watch API types are renamed.

    - `BaseWatchOptions` -> `WatchOptionsBase`
    - `StopHandle` -> `WatchStopHandle`
This commit is contained in:
Evan You 2020-04-27 13:33:57 -04:00
parent 8ab44e1f80
commit 892fb6d229
2 changed files with 12 additions and 12 deletions

View File

@ -54,26 +54,26 @@ type MapOldSources<T, Immediate> = {
type InvalidateCbRegistrator = (cb: () => void) => void
export interface BaseWatchOptions {
export interface WatchOptionsBase {
flush?: 'pre' | 'post' | 'sync'
onTrack?: ReactiveEffectOptions['onTrack']
onTrigger?: ReactiveEffectOptions['onTrigger']
}
export interface WatchOptions<Immediate = boolean> extends BaseWatchOptions {
export interface WatchOptions<Immediate = boolean> 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<T, Immediate extends Readonly<boolean> = false>(
source: WatchSource<T>,
cb: WatchCallback<T, Immediate extends true ? (T | undefined) : T>,
options?: WatchOptions<Immediate>
): 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<MapSources<T>, MapOldSources<T, Immediate>>,
options?: WatchOptions<Immediate>
): StopHandle
): WatchStopHandle
// implementation
export function watch<T = any>(
source: WatchSource<T> | WatchSource<T>[],
cb: WatchCallback<T>,
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]

View File

@ -159,11 +159,11 @@ export {
export {
// types
WatchEffect,
BaseWatchOptions,
WatchOptions,
WatchOptionsBase,
WatchCallback,
WatchSource,
StopHandle
WatchStopHandle
} from './apiWatch'
export { InjectionKey } from './apiInject'
export {