refactor: depend on scheduler directly in core instead of injecting via createRenderer
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
},
|
||||
"homepage": "https://github.com/vuejs/vue/tree/dev/packages/core#readme",
|
||||
"dependencies": {
|
||||
"@vue/observer": "3.0.0-alpha.1"
|
||||
"@vue/observer": "3.0.0-alpha.1",
|
||||
"@vue/scheduler": "3.0.0-alpha.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
} from './componentOptions'
|
||||
import { setupWatcher } from './componentWatch'
|
||||
import { Autorun, DebuggerEvent, ComputedGetter } from '@vue/observer'
|
||||
import { nextTick } from '@vue/scheduler'
|
||||
|
||||
type Flatten<T> = { [K in keyof T]: T[K] }
|
||||
|
||||
@@ -70,7 +71,6 @@ export class Component {
|
||||
public $options: any
|
||||
public $proxy: any = null
|
||||
public $forceUpdate: (() => void) | null = null
|
||||
public $nextTick: ((fn: () => void) => Promise<any>) | null = null
|
||||
|
||||
public _rawData: Data | null = null
|
||||
public _computedGetters: Record<string, ComputedGetter> | null = null
|
||||
@@ -91,6 +91,10 @@ export class Component {
|
||||
}
|
||||
}
|
||||
|
||||
$nextTick(fn: () => any): Promise<any> {
|
||||
return nextTick(fn)
|
||||
}
|
||||
|
||||
$watch(
|
||||
this: MountedComponent,
|
||||
keyOrFn: string | (() => any),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { MountedComponent } from './component'
|
||||
import { ComponentWatchOptions } from './componentOptions'
|
||||
import { autorun, stop } from '@vue/observer'
|
||||
import { queueJob } from '@vue/scheduler'
|
||||
|
||||
export function initializeWatch(
|
||||
instance: MountedComponent,
|
||||
@@ -40,8 +41,9 @@ export function setupWatcher(
|
||||
|
||||
const runner = autorun(rawGetter, {
|
||||
scheduler: () => {
|
||||
// defer watch callback using the scheduler injected defer.
|
||||
instance._queueJob(applyCb)
|
||||
// defer watch callback using the scheduler so that multiple mutations
|
||||
// result in one call only.
|
||||
queueJob(applyCb)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { autorun, stop } from '@vue/observer'
|
||||
import { queueJob } from '@vue/scheduler'
|
||||
import { VNodeFlags, ChildrenFlags } from './flags'
|
||||
import { EMPTY_OBJ, isReservedProp } from './utils'
|
||||
import {
|
||||
@@ -56,10 +57,6 @@ interface PatchDataFunction {
|
||||
}
|
||||
|
||||
interface RendererOptions {
|
||||
scheduler: {
|
||||
nextTick: (fn: () => void) => Promise<any>
|
||||
queueJob: (fn: () => void, postFlushJob?: () => void) => void
|
||||
}
|
||||
nodeOps: NodeOps
|
||||
patchData: PatchDataFunction
|
||||
teardownVNode?: (vnode: VNode) => void
|
||||
@@ -71,7 +68,6 @@ interface RendererOptions {
|
||||
// renderer alongside an actual renderer.
|
||||
export function createRenderer(options: RendererOptions) {
|
||||
const {
|
||||
scheduler: { queueJob, nextTick },
|
||||
nodeOps: {
|
||||
createElement: platformCreateElement,
|
||||
createText: platformCreateText,
|
||||
@@ -1189,10 +1185,6 @@ export function createRenderer(options: RendererOptions) {
|
||||
(__COMPAT__ && (parentVNode.children as MountedComponent)) ||
|
||||
createComponentInstance(parentVNode, Component, parentComponent)
|
||||
|
||||
// renderer-injected scheduler methods
|
||||
instance.$nextTick = nextTick
|
||||
instance._queueJob = queueJob
|
||||
|
||||
const queueUpdate = (instance.$forceUpdate = () => {
|
||||
queueJob(instance._updateHandle, flushHooks)
|
||||
})
|
||||
@@ -1318,6 +1310,9 @@ export function createRenderer(options: RendererOptions) {
|
||||
}
|
||||
}
|
||||
flushHooks()
|
||||
return vnode && vnode.flags & VNodeFlags.COMPONENT_STATEFUL
|
||||
? (vnode.children as MountedComponent).$proxy
|
||||
: null
|
||||
}
|
||||
|
||||
return { render }
|
||||
|
||||
@@ -10,6 +10,9 @@ export const Component = InternalComponent as ComponentClass
|
||||
// observer api
|
||||
export * from '@vue/observer'
|
||||
|
||||
// scheduler api
|
||||
export { nextTick } from '@vue/scheduler'
|
||||
|
||||
// internal api
|
||||
export { createComponentInstance } from './componentUtils'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user