Skip to content

Commit

Permalink
types: use more consistent naming for apiWatch type exports
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Some watch API types are renamed.

    - `BaseWatchOptions` -> `WatchOptionsBase`
    - `StopHandle` -> `WatchStopHandle`
  • Loading branch information
yyx990803 committed Apr 27, 2020
1 parent 8ab44e1 commit 892fb6d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions packages/runtime-core/src/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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
Expand All @@ -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. ` +
Expand All @@ -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(
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,11 @@ export {
export {
// types
WatchEffect,
BaseWatchOptions,
WatchOptions,
WatchOptionsBase,
WatchCallback,
WatchSource,
StopHandle
WatchStopHandle
} from './apiWatch'
export { InjectionKey } from './apiInject'
export {
Expand Down

0 comments on commit 892fb6d

Please sign in to comment.