From 90fd005a5aacec27d6253d09cd11eaed58a892cb Mon Sep 17 00:00:00 2001 From: Rizumu Ayaka Date: Thu, 28 Dec 2023 21:05:03 +0800 Subject: [PATCH] chore: organize exports --- packages/reactivity/src/baseWatch.ts | 12 +++---- packages/reactivity/src/index.ts | 3 ++ packages/runtime-core/src/apiWatch.ts | 34 ------------------- packages/runtime-core/src/componentOptions.ts | 3 +- packages/runtime-core/src/directives.ts | 3 +- 5 files changed, 11 insertions(+), 44 deletions(-) diff --git a/packages/reactivity/src/baseWatch.ts b/packages/reactivity/src/baseWatch.ts index caa6f2fff2c..5a04ed4ae23 100644 --- a/packages/reactivity/src/baseWatch.ts +++ b/packages/reactivity/src/baseWatch.ts @@ -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 = Ref | ComputedRef | (() => T) +type WatchSource = Ref | ComputedRef | (() => T) -export type WatchCallback = ( +type WatchCallback = ( value: V, oldValue: OV, onCleanup: OnCleanup, @@ -77,7 +77,7 @@ export interface BaseWatchOptions extends DebuggerOptions { handleWarn?: HandleWarn } -export type WatchStopHandle = () => void +type WatchStopHandle = () => void export interface WatchInstance extends WatchStopHandle { effect?: ReactiveEffect @@ -369,7 +369,7 @@ export function traverse(value: unknown, seen?: Set) { return value } -export function callWithErrorHandling( +function callWithErrorHandling( fn: Function, handleError: HandleError, type: BaseWatchErrorCodes, @@ -384,7 +384,7 @@ export function callWithErrorHandling( return res } -export function callWithAsyncErrorHandling( +function callWithAsyncErrorHandling( fn: Function | Function[], handleError: HandleError, type: BaseWatchErrorCodes, diff --git a/packages/reactivity/src/index.ts b/packages/reactivity/src/index.ts index e69d7db0ee1..0f4dc53b553 100644 --- a/packages/reactivity/src/index.ts +++ b/packages/reactivity/src/index.ts @@ -73,5 +73,8 @@ export { baseWatch, onEffectCleanup, BaseWatchErrorCodes, + traverse, type BaseWatchOptions, + type Scheduler, + type WatchInstance, } from './baseWatch' diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 051f305d9d1..08cdca36280 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -3,11 +3,9 @@ import { type BaseWatchOptions, type ComputedRef, type DebuggerOptions, - ReactiveFlags, type Ref, baseWatch, getCurrentScope, - isRef, } from '@vue/reactivity' import { type SchedulerJob, @@ -18,12 +16,7 @@ import { EMPTY_OBJ, NOOP, extend, - isArray, isFunction, - isMap, - isObject, - isPlainObject, - isSet, isString, remove, } from '@vue/shared' @@ -284,30 +277,3 @@ export function createPathGetter(ctx: any, path: string) { return cur } } - -export function traverse(value: unknown, seen?: Set) { - 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 -} diff --git a/packages/runtime-core/src/componentOptions.ts b/packages/runtime-core/src/componentOptions.ts index 7214cca92e4..ef1f14063ed 100644 --- a/packages/runtime-core/src/componentOptions.ts +++ b/packages/runtime-core/src/componentOptions.ts @@ -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' diff --git a/packages/runtime-core/src/directives.ts b/packages/runtime-core/src/directives.ts index a3b44d4c8fa..e3e7222ffee 100644 --- a/packages/runtime-core/src/directives.ts +++ b/packages/runtime-core/src/directives.ts @@ -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 { instance: ComponentPublicInstance | null