import { initializeWatch, teardownWatch } from './componentWatch'
import { Data, ComponentOptions } from './componentOptions'
import { createRenderProxy } from './componentProxy'
+import { handleError, ErrorTypes } from './errorHandling'
export function createComponentInstance(
vnode: VNode,
}
export function renderInstanceRoot(instance: MountedComponent) {
- // TODO handle render error
- return normalizeComponentRoot(
- instance.render.call(instance.$proxy, instance.$props, instance.$slots),
- instance.$parentVNode
- )
+ let vnode
+ try {
+ vnode = instance.render.call(
+ instance.$proxy,
+ instance.$props,
+ instance.$slots
+ )
+ } catch (e1) {
+ handleError(e1, instance, ErrorTypes.RENDER)
+ if (__DEV__ && instance.renderError) {
+ try {
+ vnode = instance.renderError.call(instance.$proxy, e1)
+ } catch (e2) {
+ handleError(e2, instance, ErrorTypes.RENDER_ERROR)
+ }
+ }
+ }
+ return normalizeComponentRoot(vnode, instance.$parentVNode)
}
export function teardownComponentInstance(instance: MountedComponent) {
export const enum ErrorTypes {
LIFECYCLE = 1,
- RENDER = 2,
- NATIVE_EVENT_HANDLER = 3,
- COMPONENT_EVENT_HANDLER = 4
+ RENDER,
+ RENDER_ERROR,
+ NATIVE_EVENT_HANDLER,
+ COMPONENT_EVENT_HANDLER
}
const globalHandlers: Function[] = []
export function handleError(
err: Error,
instance: MountedComponent,
- type: ErrorTypes,
- code: number
+ type: ErrorTypes
) {
// TODO
}