import {
handleError,
ErrorTypes,
- callLifecycleHookWithHandle
+ callLifecycleHookWithHandler
} from './errorHandling'
import { warn } from './warning'
import { setCurrentInstance, unsetCurrentInstance } from './experimental/hooks'
instance.$slots = currentVNode.slots || EMPTY_OBJ
if (created) {
- callLifecycleHookWithHandle(created, $proxy, ErrorTypes.CREATED)
+ callLifecycleHookWithHandler(created, $proxy, ErrorTypes.CREATED)
}
currentVNode = currentContextVNode = null
// beforeCreate hook is called right in the constructor
const { beforeCreate, props } = instance.$options
if (beforeCreate) {
- callLifecycleHookWithHandle(beforeCreate, proxy, ErrorTypes.BEFORE_CREATE)
+ callLifecycleHookWithHandler(beforeCreate, proxy, ErrorTypes.BEFORE_CREATE)
}
initializeProps(instance, props, (currentVNode as VNode).data)
}
if (nextProps === null) {
return prevProps !== null
}
- let shouldUpdate = true
const nextKeys = Object.keys(nextProps)
- if (nextKeys.length === Object.keys(prevProps).length) {
- shouldUpdate = false
- for (let i = 0; i < nextKeys.length; i++) {
- const key = nextKeys[i]
- if (nextProps[key] !== prevProps[key]) {
- shouldUpdate = true
- }
+ if (nextKeys.length !== Object.keys(prevProps).length) {
+ return true
+ }
+ for (let i = 0; i < nextKeys.length; i++) {
+ const key = nextKeys[i]
+ if (nextProps[key] !== prevProps[key]) {
+ return true
}
}
- return shouldUpdate
+ return false
+}
+
+export function getReasonForComponentUpdate(
+ prevVNode: VNode,
+ nextVNode: VNode
+): any {
+ // TODO: extract more detailed information on why the component is updating
}
export function createComponentClassFromOptions(
-import { autorun, stop, Autorun, immutable } from '@vue/observer'
+import {
+ autorun,
+ stop,
+ Autorun,
+ immutable,
+ AutorunOptions
+} from '@vue/observer'
import { queueJob, handleSchedulerError, nextTick } from '@vue/scheduler'
import { VNodeFlags, ChildrenFlags } from './flags'
import { EMPTY_OBJ, reservedPropRE, isString } from '@vue/shared'
renderFunctionalRoot,
createComponentInstance,
teardownComponentInstance,
- shouldUpdateComponent
+ shouldUpdateComponent,
+ getReasonForComponentUpdate
} from './componentUtils'
import { KeepAliveSymbol } from './optional/keepAlive'
import { pushWarningContext, popWarningContext, warn } from './warning'
import {
handleError,
ErrorTypes,
- callLifecycleHookWithHandle
+ callLifecycleHookWithHandler
} from './errorHandling'
export interface NodeOps {
instance.$parentVNode = nextVNode as MountedVNode
if (shouldUpdateComponent(prevVNode, nextVNode)) {
+ if (__DEV__ && instance.$options.renderTriggered) {
+ callLifecycleHookWithHandler(
+ instance.$options.renderTriggered,
+ instance.$proxy,
+ ErrorTypes.RENDER_TRIGGERED,
+ getReasonForComponentUpdate(prevVNode, nextVNode)
+ )
+ }
instance.$forceUpdate()
} else if (instance.$vnode.flags & VNodeFlags.COMPONENT) {
instance.$vnode.contextVNode = nextVNode
} = instance
if (beforeMount) {
- callLifecycleHookWithHandle(beforeMount, $proxy, ErrorTypes.BEFORE_MOUNT)
+ callLifecycleHookWithHandler(beforeMount, $proxy, ErrorTypes.BEFORE_MOUNT)
}
const queueUpdate = (instance.$forceUpdate = () => {
queueJob(instance._updateHandle, flushHooks)
})
- instance._updateHandle = autorun(
- () => {
- if (instance._unmounted) {
- return
+ const autorunOptions: AutorunOptions = {
+ scheduler: queueUpdate
+ }
+
+ if (__DEV__) {
+ if (renderTracked) {
+ autorunOptions.onTrack = event => {
+ callLifecycleHookWithHandler(
+ renderTracked,
+ $proxy,
+ ErrorTypes.RENDER_TRACKED,
+ event
+ )
}
- if (instance._mounted) {
- updateComponentInstance(instance, isSVG)
- } else {
- // this will be executed synchronously right here
- instance.$vnode = renderInstanceRoot(instance) as MountedVNode
-
- queuePostCommitHook(() => {
- vnode.el = instance.$vnode.el
- if (__COMPAT__) {
- // expose __vue__ for devtools
- ;(vnode.el as any).__vue__ = instance
- }
- if (vnode.ref) {
- vnode.ref($proxy)
- }
- // retrieve mounted value after initial render so that we get
- // to inject effects in hooks
- const { mounted } = instance.$options
- if (mounted) {
- callLifecycleHookWithHandle(mounted, $proxy, ErrorTypes.MOUNTED)
- }
- })
-
- mount(
- instance.$vnode,
- container,
- vnode as MountedVNode,
- isSVG,
- endNode
+ }
+ if (renderTriggered) {
+ autorunOptions.onTrigger = event => {
+ callLifecycleHookWithHandler(
+ renderTriggered,
+ $proxy,
+ ErrorTypes.RENDER_TRIGGERED,
+ event
)
-
- instance._mounted = true
}
- },
- {
- scheduler: queueUpdate,
- onTrack: renderTracked,
- onTrigger: renderTriggered
}
- )
+ }
+
+ instance._updateHandle = autorun(() => {
+ if (instance._unmounted) {
+ return
+ }
+ if (instance._mounted) {
+ updateComponentInstance(instance, isSVG)
+ } else {
+ // this will be executed synchronously right here
+ instance.$vnode = renderInstanceRoot(instance) as MountedVNode
+
+ queuePostCommitHook(() => {
+ vnode.el = instance.$vnode.el
+ if (__COMPAT__) {
+ // expose __vue__ for devtools
+ ;(vnode.el as any).__vue__ = instance
+ }
+ if (vnode.ref) {
+ vnode.ref($proxy)
+ }
+ // retrieve mounted value after initial render so that we get
+ // to inject effects in hooks
+ const { mounted } = instance.$options
+ if (mounted) {
+ callLifecycleHookWithHandler(mounted, $proxy, ErrorTypes.MOUNTED)
+ }
+ })
+
+ mount(instance.$vnode, container, vnode as MountedVNode, isSVG, endNode)
+
+ instance._mounted = true
+ }
+ }, autorunOptions)
if (__DEV__) {
popWarningContext()
$options: { beforeUpdate }
} = instance
if (beforeUpdate) {
- callLifecycleHookWithHandle(
+ callLifecycleHookWithHandler(
beforeUpdate,
$proxy,
ErrorTypes.BEFORE_UPDATE,
}
const { updated } = instance.$options
if (updated) {
- callLifecycleHookWithHandle(
+ callLifecycleHookWithHandler(
updated,
$proxy,
ErrorTypes.UPDATED,
$options: { beforeUnmount, unmounted }
} = instance
if (beforeUnmount) {
- callLifecycleHookWithHandle(
+ callLifecycleHookWithHandler(
beforeUnmount,
$proxy,
ErrorTypes.BEFORE_UNMOUNT
teardownComponentInstance(instance)
instance._unmounted = true
if (unmounted) {
- callLifecycleHookWithHandle(unmounted, $proxy, ErrorTypes.UNMOUNTED)
+ callLifecycleHookWithHandler(unmounted, $proxy, ErrorTypes.UNMOUNTED)
}
}
callActivatedHook($children[i], false)
}
if (activated) {
- callLifecycleHookWithHandle(activated, $proxy, ErrorTypes.ACTIVATED)
+ callLifecycleHookWithHandler(activated, $proxy, ErrorTypes.ACTIVATED)
}
}
}
callDeactivateHook($children[i], false)
}
if (deactivated) {
- callLifecycleHookWithHandle(deactivated, $proxy, ErrorTypes.DEACTIVATED)
+ callLifecycleHookWithHandler(
+ deactivated,
+ $proxy,
+ ErrorTypes.DEACTIVATED
+ )
}
}
}