From c1b3e7c5dbbb7e16bc21d4e9ab27212f87726f23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Thu, 4 Jan 2024 23:10:02 +0800 Subject: [PATCH] chore: update --- packages/reactivity/__tests__/baseWatch.spec.ts | 2 +- packages/reactivity/src/baseWatch.ts | 10 ++-------- packages/reactivity/src/index.ts | 2 +- packages/runtime-core/src/apiWatch.ts | 11 +++-------- packages/runtime-core/src/componentOptions.ts | 2 +- packages/runtime-core/src/renderer.ts | 4 ++-- packages/runtime-core/src/scheduler.ts | 6 +++--- 7 files changed, 13 insertions(+), 24 deletions(-) diff --git a/packages/reactivity/__tests__/baseWatch.spec.ts b/packages/reactivity/__tests__/baseWatch.spec.ts index 6fa29ade0..02d9e64e0 100644 --- a/packages/reactivity/__tests__/baseWatch.spec.ts +++ b/packages/reactivity/__tests__/baseWatch.spec.ts @@ -6,7 +6,7 @@ import { baseWatch, onEffectCleanup, ref, -} from '../src/index' +} from '../src' const queue: SchedulerJob[] = [] diff --git a/packages/reactivity/src/baseWatch.ts b/packages/reactivity/src/baseWatch.ts index 4f47809ef..a97f43366 100644 --- a/packages/reactivity/src/baseWatch.ts +++ b/packages/reactivity/src/baseWatch.ts @@ -58,15 +58,12 @@ export interface SchedulerJob extends Function { } type WatchEffect = (onCleanup: OnCleanup) => void - type WatchSource = Ref | ComputedRef | (() => T) - type WatchCallback = ( value: V, oldValue: OV, onCleanup: OnCleanup, ) => any - type OnCleanup = (cleanupFn: () => void) => void export interface BaseWatchOptions extends DebuggerOptions { @@ -86,17 +83,14 @@ export type Scheduler = ( effect: ReactiveEffect, isInit: boolean, ) => void - -const DEFAULT_SCHEDULER: Scheduler = job => job() - export type HandleError = (err: unknown, type: BaseWatchErrorCodes) => void +export type HandleWarn = (msg: string, ...args: any[]) => void +const DEFAULT_SCHEDULER: Scheduler = job => job() const DEFAULT_HANDLE_ERROR: HandleError = (err: unknown) => { throw err } -export type HandleWarn = (msg: string, ...args: any[]) => void - const cleanupMap: WeakMap void)[]> = new WeakMap() let activeEffect: ReactiveEffect | undefined = undefined diff --git a/packages/reactivity/src/index.ts b/packages/reactivity/src/index.ts index 6e2e51875..a8db2454a 100644 --- a/packages/reactivity/src/index.ts +++ b/packages/reactivity/src/index.ts @@ -72,8 +72,8 @@ export { TrackOpTypes, TriggerOpTypes, ReactiveFlags } from './constants' export { baseWatch, onEffectCleanup, - BaseWatchErrorCodes, traverse, + BaseWatchErrorCodes, type BaseWatchOptions, type Scheduler, } from './baseWatch' diff --git a/packages/runtime-core/src/apiWatch.ts b/packages/runtime-core/src/apiWatch.ts index 8535b262c..b6c0d5f83 100644 --- a/packages/runtime-core/src/apiWatch.ts +++ b/packages/runtime-core/src/apiWatch.ts @@ -8,7 +8,7 @@ import { getCurrentScope, } from '@vue/reactivity' import { - type CreateScheduler, + type SchedulerFactory, createPreScheduler, createSyncScheduler, } from './scheduler' @@ -156,9 +156,7 @@ export function watch = false>( return doWatch(source as any, cb, options) } -function getSchedulerByFlushMode( - flush: WatchOptionsBase['flush'], -): CreateScheduler { +function getScheduler(flush: WatchOptionsBase['flush']): SchedulerFactory { if (flush === 'post') { return createPostRenderScheduler } @@ -224,12 +222,9 @@ function doWatch( } const instance = currentInstance - extendOptions.onError = (err: unknown, type: BaseWatchErrorCodes) => handleErrorWithInstance(err, instance, type) - - const scheduler = getSchedulerByFlushMode(flush)(instance) - extendOptions.scheduler = scheduler + extendOptions.scheduler = getScheduler(flush)(instance) let effect = baseWatch(source, cb, extend({}, options, extendOptions)) diff --git a/packages/runtime-core/src/componentOptions.ts b/packages/runtime-core/src/componentOptions.ts index cfeb61118..1017f8b64 100644 --- a/packages/runtime-core/src/componentOptions.ts +++ b/packages/runtime-core/src/componentOptions.ts @@ -942,7 +942,7 @@ export function createWatcher( ? createPathGetter(publicThis, key) : () => (publicThis as any)[key] - const options: WatchOptions = {} + const options: WatchOptions = {} if (__COMPAT__) { const instance = getCurrentScope() === currentInstance?.scope ? currentInstance : null diff --git a/packages/runtime-core/src/renderer.ts b/packages/runtime-core/src/renderer.ts index f80d3c438..08762084e 100644 --- a/packages/runtime-core/src/renderer.ts +++ b/packages/runtime-core/src/renderer.ts @@ -38,7 +38,7 @@ import { isReservedProp, } from '@vue/shared' import { - type CreateScheduler, + type SchedulerFactory, type SchedulerJob, flushPostFlushCbs, flushPreFlushCbs, @@ -282,7 +282,7 @@ export const queuePostRenderEffect = __FEATURE_SUSPENSE__ : queueEffectWithSuspense : queuePostFlushCb -export const createPostRenderScheduler: CreateScheduler = +export const createPostRenderScheduler: SchedulerFactory = instance => (job, effect, isInit) => { if (isInit) { queuePostRenderEffect( diff --git a/packages/runtime-core/src/scheduler.ts b/packages/runtime-core/src/scheduler.ts index 8cc2db29a..2ab47e51d 100644 --- a/packages/runtime-core/src/scheduler.ts +++ b/packages/runtime-core/src/scheduler.ts @@ -289,11 +289,11 @@ function checkRecursiveUpdates(seen: CountMap, fn: SchedulerJob) { } } -export type CreateScheduler = ( +export type SchedulerFactory = ( instance: ComponentInternalInstance | null, ) => Scheduler -export const createSyncScheduler: CreateScheduler = +export const createSyncScheduler: SchedulerFactory = instance => (job, effect, isInit) => { if (isInit) { effect.run() @@ -302,7 +302,7 @@ export const createSyncScheduler: CreateScheduler = } } -export const createPreScheduler: CreateScheduler = +export const createPreScheduler: SchedulerFactory = instance => (job, effect, isInit) => { if (isInit) { effect.run()