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:
parent
8ab44e1f80
commit
892fb6d229
@ -54,26 +54,26 @@ type MapOldSources<T, Immediate> = {
|
|||||||
|
|
||||||
type InvalidateCbRegistrator = (cb: () => void) => void
|
type InvalidateCbRegistrator = (cb: () => void) => void
|
||||||
|
|
||||||
export interface BaseWatchOptions {
|
export interface WatchOptionsBase {
|
||||||
flush?: 'pre' | 'post' | 'sync'
|
flush?: 'pre' | 'post' | 'sync'
|
||||||
onTrack?: ReactiveEffectOptions['onTrack']
|
onTrack?: ReactiveEffectOptions['onTrack']
|
||||||
onTrigger?: ReactiveEffectOptions['onTrigger']
|
onTrigger?: ReactiveEffectOptions['onTrigger']
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WatchOptions<Immediate = boolean> extends BaseWatchOptions {
|
export interface WatchOptions<Immediate = boolean> extends WatchOptionsBase {
|
||||||
immediate?: Immediate
|
immediate?: Immediate
|
||||||
deep?: boolean
|
deep?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export type StopHandle = () => void
|
export type WatchStopHandle = () => void
|
||||||
|
|
||||||
const invoke = (fn: Function) => fn()
|
const invoke = (fn: Function) => fn()
|
||||||
|
|
||||||
// Simple effect.
|
// Simple effect.
|
||||||
export function watchEffect(
|
export function watchEffect(
|
||||||
effect: WatchEffect,
|
effect: WatchEffect,
|
||||||
options?: BaseWatchOptions
|
options?: WatchOptionsBase
|
||||||
): StopHandle {
|
): WatchStopHandle {
|
||||||
return doWatch(effect, null, options)
|
return doWatch(effect, null, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ export function watch<T, Immediate extends Readonly<boolean> = false>(
|
|||||||
source: WatchSource<T>,
|
source: WatchSource<T>,
|
||||||
cb: WatchCallback<T, Immediate extends true ? (T | undefined) : T>,
|
cb: WatchCallback<T, Immediate extends true ? (T | undefined) : T>,
|
||||||
options?: WatchOptions<Immediate>
|
options?: WatchOptions<Immediate>
|
||||||
): StopHandle
|
): WatchStopHandle
|
||||||
|
|
||||||
// overload #2: array of multiple sources + cb
|
// overload #2: array of multiple sources + cb
|
||||||
// Readonly constraint helps the callback to correctly infer value types based
|
// Readonly constraint helps the callback to correctly infer value types based
|
||||||
@ -98,14 +98,14 @@ export function watch<
|
|||||||
sources: T,
|
sources: T,
|
||||||
cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
|
cb: WatchCallback<MapSources<T>, MapOldSources<T, Immediate>>,
|
||||||
options?: WatchOptions<Immediate>
|
options?: WatchOptions<Immediate>
|
||||||
): StopHandle
|
): WatchStopHandle
|
||||||
|
|
||||||
// implementation
|
// implementation
|
||||||
export function watch<T = any>(
|
export function watch<T = any>(
|
||||||
source: WatchSource<T> | WatchSource<T>[],
|
source: WatchSource<T> | WatchSource<T>[],
|
||||||
cb: WatchCallback<T>,
|
cb: WatchCallback<T>,
|
||||||
options?: WatchOptions
|
options?: WatchOptions
|
||||||
): StopHandle {
|
): WatchStopHandle {
|
||||||
if (__DEV__ && !isFunction(cb)) {
|
if (__DEV__ && !isFunction(cb)) {
|
||||||
warn(
|
warn(
|
||||||
`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
|
`\`watch(fn, options?)\` signature has been moved to a separate API. ` +
|
||||||
@ -120,7 +120,7 @@ function doWatch(
|
|||||||
source: WatchSource | WatchSource[] | WatchEffect,
|
source: WatchSource | WatchSource[] | WatchEffect,
|
||||||
cb: WatchCallback | null,
|
cb: WatchCallback | null,
|
||||||
{ immediate, deep, flush, onTrack, onTrigger }: WatchOptions = EMPTY_OBJ
|
{ immediate, deep, flush, onTrack, onTrigger }: WatchOptions = EMPTY_OBJ
|
||||||
): StopHandle {
|
): WatchStopHandle {
|
||||||
if (__DEV__ && !cb) {
|
if (__DEV__ && !cb) {
|
||||||
if (immediate !== undefined) {
|
if (immediate !== undefined) {
|
||||||
warn(
|
warn(
|
||||||
@ -274,7 +274,7 @@ export function instanceWatch(
|
|||||||
source: string | Function,
|
source: string | Function,
|
||||||
cb: Function,
|
cb: Function,
|
||||||
options?: WatchOptions
|
options?: WatchOptions
|
||||||
): StopHandle {
|
): WatchStopHandle {
|
||||||
const publicThis = this.proxy as any
|
const publicThis = this.proxy as any
|
||||||
const getter = isString(source)
|
const getter = isString(source)
|
||||||
? () => publicThis[source]
|
? () => publicThis[source]
|
||||||
|
@ -159,11 +159,11 @@ export {
|
|||||||
export {
|
export {
|
||||||
// types
|
// types
|
||||||
WatchEffect,
|
WatchEffect,
|
||||||
BaseWatchOptions,
|
|
||||||
WatchOptions,
|
WatchOptions,
|
||||||
|
WatchOptionsBase,
|
||||||
WatchCallback,
|
WatchCallback,
|
||||||
WatchSource,
|
WatchSource,
|
||||||
StopHandle
|
WatchStopHandle
|
||||||
} from './apiWatch'
|
} from './apiWatch'
|
||||||
export { InjectionKey } from './apiInject'
|
export { InjectionKey } from './apiInject'
|
||||||
export {
|
export {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user