chore: allow custom assignment to this
This commit is contained in:
parent
7691c06520
commit
8d99ab1ff8
@ -115,6 +115,9 @@ export type ComponentInstance<P = Data, S = Data> = {
|
|||||||
renderProxy: ComponentRenderProxy | null
|
renderProxy: ComponentRenderProxy | null
|
||||||
propsProxy: P | null
|
propsProxy: P | null
|
||||||
setupContext: SetupContext | null
|
setupContext: SetupContext | null
|
||||||
|
|
||||||
|
// user namespace
|
||||||
|
user: { [key: string]: any }
|
||||||
} & SetupContext &
|
} & SetupContext &
|
||||||
LifecycleHooks
|
LifecycleHooks
|
||||||
|
|
||||||
@ -198,6 +201,9 @@ export function createComponentInstance(
|
|||||||
slots: EMPTY_OBJ,
|
slots: EMPTY_OBJ,
|
||||||
refs: EMPTY_OBJ,
|
refs: EMPTY_OBJ,
|
||||||
|
|
||||||
|
// user namespace for storing whatever the user assigns to `this`
|
||||||
|
user: {},
|
||||||
|
|
||||||
emit: (event: string, ...args: unknown[]) => {
|
emit: (event: string, ...args: unknown[]) => {
|
||||||
const props = instance.vnode.props || EMPTY_OBJ
|
const props = instance.vnode.props || EMPTY_OBJ
|
||||||
const handler = props[`on${event}`] || props[`on${capitalize(event)}`]
|
const handler = props[`on${event}`] || props[`on${capitalize(event)}`]
|
||||||
|
@ -26,7 +26,7 @@ export const RenderProxyHandlers = {
|
|||||||
case '$emit':
|
case '$emit':
|
||||||
return target.emit
|
return target.emit
|
||||||
default:
|
default:
|
||||||
break
|
return target.user[key]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -35,15 +35,15 @@ export const RenderProxyHandlers = {
|
|||||||
if (data.hasOwnProperty(key)) {
|
if (data.hasOwnProperty(key)) {
|
||||||
data[key] = value
|
data[key] = value
|
||||||
return true
|
return true
|
||||||
|
} else if (key[0] === '$' && key.slice(1) in target) {
|
||||||
|
// TODO warn attempt of mutating public property
|
||||||
|
return false
|
||||||
|
} else if (key in target.props) {
|
||||||
|
// TODO warn attempt of mutating prop
|
||||||
|
return false
|
||||||
} else {
|
} else {
|
||||||
if (__DEV__) {
|
target.user[key] = value
|
||||||
if (key[0] === '$') {
|
return true
|
||||||
// TODO warn attempt of mutating public property
|
|
||||||
} else if (target.props.hasOwnProperty(key)) {
|
|
||||||
// TODO warn attempt of mutating prop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user