wip: $state -> $data

This commit is contained in:
Evan You
2019-06-19 17:08:42 +08:00
parent 5228f0343b
commit 976844790e
2 changed files with 34 additions and 28 deletions

View File

@@ -2,17 +2,17 @@ import { ComponentInstance } from './component'
export const RenderProxyHandlers = {
get(target: ComponentInstance, key: string) {
const { state, props } = target
if (state.hasOwnProperty(key)) {
return state[key]
const { data, props } = target
if (data.hasOwnProperty(key)) {
return data[key]
} else if (props.hasOwnProperty(key)) {
return props[key]
} else {
switch (key) {
case '$state':
return target.state
case '$data':
return data
case '$props':
return target.props
return props
case '$attrs':
return target.attrs
case '$slots':
@@ -23,8 +23,6 @@ export const RenderProxyHandlers = {
return target.parent
case '$root':
return target.root
case '$el':
return target.vnode && target.vnode.el
case '$emit':
return target.emit
default:
@@ -33,9 +31,9 @@ export const RenderProxyHandlers = {
}
},
set(target: ComponentInstance, key: string, value: any): boolean {
const { state } = target
if (state.hasOwnProperty(key)) {
state[key] = value
const { data } = target
if (data.hasOwnProperty(key)) {
data[key] = value
return true
} else {
if (__DEV__) {