feat: enable returning observable state from hooks()

This commit is contained in:
Evan You 2018-10-30 00:33:45 -04:00
parent 6767bf83c4
commit a17c377be0
2 changed files with 17 additions and 11 deletions

View File

@ -74,6 +74,10 @@ const renderProxyHandlers = {
if ((i = target._rawData) !== null && i.hasOwnProperty(key)) {
target.$data[key] = value
return true
} else if ((i = target._hookProps) !== null && i.hasOwnProperty(key)) {
// this enables returning observable objects from hooks()
i[key] = value
return true
} else {
return Reflect.set(target, key, value, receiver)
}

View File

@ -105,22 +105,24 @@ export let isRendering = false
export function renderInstanceRoot(instance: ComponentInstance): VNode {
let vnode
const {
$options: { hooks },
render,
$proxy,
$props,
$slots,
$attrs,
$parentVNode
} = instance
try {
setCurrentInstance(instance)
if (instance.hooks) {
instance._hookProps =
instance.hooks.call(instance.$proxy, instance.$props) || null
if (hooks) {
instance._hookProps = hooks.call($proxy, $props) || null
}
if (__DEV__) {
isRendering = true
}
vnode = instance.render.call(
instance.$proxy,
instance.$props,
instance.$slots,
instance.$attrs,
instance.$parentVNode
)
vnode = render.call($proxy, $props, $slots, $attrs, $parentVNode)
if (__DEV__) {
isRendering = false
}
@ -128,7 +130,7 @@ export function renderInstanceRoot(instance: ComponentInstance): VNode {
} catch (err) {
handleError(err, instance, ErrorTypes.RENDER)
}
return normalizeComponentRoot(vnode, instance.$parentVNode)
return normalizeComponentRoot(vnode, $parentVNode)
}
export function renderFunctionalRoot(vnode: VNode): VNode {