Skip to content

Commit

Permalink
chore: organize exports
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleSound committed Dec 28, 2023
1 parent e9555ce commit 90fd005
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 44 deletions.
12 changes: 6 additions & 6 deletions packages/reactivity/src/baseWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ export interface SchedulerJob extends Function {
allowRecurse?: boolean
}

export type WatchEffect = (onCleanup: OnCleanup) => void
type WatchEffect = (onCleanup: OnCleanup) => void

export type WatchSource<T = any> = Ref<T> | ComputedRef<T> | (() => T)
type WatchSource<T = any> = Ref<T> | ComputedRef<T> | (() => T)

export type WatchCallback<V = any, OV = any> = (
type WatchCallback<V = any, OV = any> = (
value: V,
oldValue: OV,
onCleanup: OnCleanup,
Expand All @@ -77,7 +77,7 @@ export interface BaseWatchOptions<Immediate = boolean> extends DebuggerOptions {
handleWarn?: HandleWarn
}

export type WatchStopHandle = () => void
type WatchStopHandle = () => void

export interface WatchInstance extends WatchStopHandle {
effect?: ReactiveEffect
Expand Down Expand Up @@ -369,7 +369,7 @@ export function traverse(value: unknown, seen?: Set<unknown>) {
return value
}

export function callWithErrorHandling(
function callWithErrorHandling(
fn: Function,
handleError: HandleError,
type: BaseWatchErrorCodes,
Expand All @@ -384,7 +384,7 @@ export function callWithErrorHandling(
return res
}

export function callWithAsyncErrorHandling(
function callWithAsyncErrorHandling(
fn: Function | Function[],
handleError: HandleError,
type: BaseWatchErrorCodes,
Expand Down
3 changes: 3 additions & 0 deletions packages/reactivity/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,8 @@ export {
baseWatch,
onEffectCleanup,
BaseWatchErrorCodes,
traverse,
type BaseWatchOptions,
type Scheduler,
type WatchInstance,
} from './baseWatch'
34 changes: 0 additions & 34 deletions packages/runtime-core/src/apiWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import {
type BaseWatchOptions,
type ComputedRef,
type DebuggerOptions,
ReactiveFlags,
type Ref,
baseWatch,
getCurrentScope,
isRef,
} from '@vue/reactivity'
import {
type SchedulerJob,
Expand All @@ -18,12 +16,7 @@ import {
EMPTY_OBJ,
NOOP,
extend,
isArray,
isFunction,
isMap,
isObject,
isPlainObject,
isSet,
isString,
remove,
} from '@vue/shared'
Expand Down Expand Up @@ -284,30 +277,3 @@ export function createPathGetter(ctx: any, path: string) {
return cur
}
}

export function traverse(value: unknown, seen?: Set<unknown>) {
if (!isObject(value) || (value as any)[ReactiveFlags.SKIP]) {
return value
}
seen = seen || new Set()
if (seen.has(value)) {
return value
}
seen.add(value)
if (isRef(value)) {
traverse(value.value, seen)
} else if (isArray(value)) {
for (let i = 0; i < value.length; i++) {
traverse(value[i], seen)
}
} else if (isSet(value) || isMap(value)) {
value.forEach((v: any) => {
traverse(v, seen)
})
} else if (isPlainObject(value)) {
for (const key in value) {
traverse(value[key], seen)
}
}
return value
}
3 changes: 1 addition & 2 deletions packages/runtime-core/src/componentOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@ import {
isPromise,
isString,
} from '@vue/shared'
import { type Ref, getCurrentScope, isRef } from '@vue/reactivity'
import { type Ref, getCurrentScope, isRef, traverse } from '@vue/reactivity'
import { computed } from './apiComputed'
import {
type WatchCallback,
type WatchOptions,
createPathGetter,
traverse,
watch,
} from './apiWatch'
import { inject, provide } from './apiInject'
Expand Down
3 changes: 1 addition & 2 deletions packages/runtime-core/src/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import { currentRenderingInstance } from './componentRenderContext'
import { ErrorCodes, callWithAsyncErrorHandling } from './errorHandling'
import type { ComponentPublicInstance } from './componentPublicInstance'
import { mapCompatDirectiveHook } from './compat/customDirective'
import { pauseTracking, resetTracking } from '@vue/reactivity'
import { traverse } from './apiWatch'
import { pauseTracking, resetTracking, traverse } from '@vue/reactivity'

export interface DirectiveBinding<V = any> {
instance: ComponentPublicInstance | null
Expand Down

0 comments on commit 90fd005

Please sign in to comment.