refactor: depend on scheduler directly in core instead of injecting via createRenderer

This commit is contained in:
Evan You
2018-09-21 13:34:00 -04:00
parent bb0e15de4d
commit de76daf073
11 changed files with 63 additions and 26 deletions

View File

@@ -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"
}
}

View File

@@ -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),

View File

@@ -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)
}
})

View File

@@ -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 }

View File

@@ -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'