feat: enable returning observable state from hooks()
This commit is contained in:
parent
6767bf83c4
commit
a17c377be0
@ -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)
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user