]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
refactor: simplify code
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Fri, 19 Jan 2024 08:59:03 +0000 (16:59 +0800)
committer三咲智子 Kevin Deng <sxzz@sxzz.moe>
Fri, 19 Jan 2024 08:59:03 +0000 (16:59 +0800)
packages/reactivity/src/index.ts
packages/runtime-vapor/src/index.ts
packages/runtime-vapor/src/render.ts
packages/runtime-vapor/src/renderWatch.ts
packages/runtime-vapor/src/scheduler.ts

index 88ef249e441154750c0e2cb6f2dabb080baeda82..d7857067678ebb653860ad4d5642f22c1ec5a447 100644 (file)
@@ -78,4 +78,5 @@ export {
   type BaseWatchOptions,
   type BaseWatchMiddleware,
   type Scheduler,
+  type SchedulerJob,
 } from './baseWatch'
index 0fc7be64a1296b1cc1a42f15c60c22d49d111f03..244853c537d2e65bfd2c0947f811bbf615d12a69 100644 (file)
@@ -39,15 +39,15 @@ export {
 } from '@vue/reactivity'
 export { withModifiers, withKeys } from '@vue/runtime-dom'
 
+export { nextTick } from './scheduler'
+export { getCurrentInstance, type ComponentInternalInstance } from './component'
 export * from './on'
 export * from './render'
 export * from './renderWatch'
 export * from './template'
-export * from './scheduler'
 export * from './apiWatch'
 export * from './directive'
 export * from './dom'
 export * from './directives/vShow'
 export * from './apiLifecycle'
-export { getCurrentInstance, type ComponentInternalInstance } from './component'
 export * from './if'
index 22c3b7fbfd5be4d05cac61100517ab038277caba..82c8c02e7991bfcbfd9cd1699e5a0aa33a0748af 100644 (file)
@@ -16,11 +16,6 @@ export type ParentBlock = ParentNode | Node[]
 export type Fragment = { nodes: Block; anchor: Node }
 export type BlockFn = (props?: any) => Block
 
-let isRenderingActivity = false
-export function getIsRendering() {
-  return isRenderingActivity
-}
-
 export function render(
   comp: Component,
   props: Data,
@@ -55,13 +50,7 @@ export function mountComponent(
     let block: Block | null = null
     if (state && '__isScriptSetup' in state) {
       instance.setupState = proxyRefs(state)
-      const currentlyRenderingActivity = isRenderingActivity
-      isRenderingActivity = true
-      try {
-        block = component.render(instance.setupState)
-      } finally {
-        isRenderingActivity = currentlyRenderingActivity
-      }
+      block = component.render(instance.setupState)
     } else {
       block = state as Block
     }
index c0167cdf51c6f5a85ad665929d9d165a0fe90d6e..d6943e4d4a7c0900157f425221f717b1b51d671d 100644 (file)
@@ -52,13 +52,12 @@ function doWatch(
   // if (__SSR__) {}
 
   const instance = getCurrentInstance()
-
-  extendOptions.onError = (err: unknown, type: BaseWatchErrorCodes) =>
-    handleErrorWithInstance(err, instance, type)
-  extendOptions.scheduler = createVaporRenderingScheduler(instance)
-
-  extendOptions.middleware = createMiddleware(instance)
-
+  extend(extendOptions, {
+    onError: (err: unknown, type: BaseWatchErrorCodes) =>
+      handleErrorWithInstance(err, instance, type),
+    scheduler: createVaporRenderingScheduler(instance),
+    middleware: createMiddleware(instance),
+  })
   let effect = baseWatch(source, cb, extendOptions)
 
   const unwatch = !effect
index 7a5afb011d7954430b5a1689dccae62a153ac30e..a5e8f1fd17273956c8822183932deef91a210c88 100644 (file)
@@ -1,38 +1,8 @@
-import type { Scheduler } from '@vue/reactivity'
+import type { Scheduler, SchedulerJob } from '@vue/reactivity'
 import type { ComponentInternalInstance } from './component'
 import { isArray } from '@vue/shared'
 
-export interface SchedulerJob extends Function {
-  id?: number
-  pre?: boolean
-  active?: boolean
-  computed?: boolean
-  /**
-   * Indicates whether the effect is allowed to recursively trigger itself
-   * when managed by the scheduler.
-   *
-   * By default, a job cannot trigger itself because some built-in method calls,
-   * e.g. Array.prototype.push actually performs reads as well (#1740) which
-   * can lead to confusing infinite loops.
-   * The allowed cases are component update functions and watch callbacks.
-   * Component update functions may update child component props, which in turn
-   * trigger flush: "pre" watch callbacks that mutates state that the parent
-   * relies on (#1801). Watch callbacks doesn't track its dependencies so if it
-   * triggers itself again, it's likely intentional and it is the user's
-   * responsibility to perform recursive state mutation that eventually
-   * stabilizes (#1727).
-   */
-  allowRecurse?: boolean
-  /**
-   * Attached by renderer.ts when setting up a component's render effect
-   * Used to obtain component information when reporting max recursive updates.
-   * dev only.
-   */
-  ownerInstance?: ComponentInternalInstance
-}
-
 export type SchedulerJobs = SchedulerJob | SchedulerJob[]
-
 export type QueueEffect = (
   cb: SchedulerJobs,
   suspense: ComponentInternalInstance | null,
@@ -210,7 +180,7 @@ export type SchedulerFactory = (
 ) => Scheduler
 
 export const createVaporSyncScheduler: SchedulerFactory =
-  (instance) => (job, effect, isInit) => {
+  () => (job, effect, isInit) => {
     if (isInit) {
       effect.run()
     } else {
@@ -241,7 +211,7 @@ export const createVaporRenderingScheduler: SchedulerFactory =
   }
 
 export const createVaporPostScheduler: SchedulerFactory =
-  (instance) => (job, effect, isInit) => {
+  () => (job, effect, isInit) => {
     if (isInit) {
       queuePostRenderEffect(effect.run.bind(effect))
     } else {