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
|
||||
propsProxy: P | null
|
||||
setupContext: SetupContext | null
|
||||
|
||||
// user namespace
|
||||
user: { [key: string]: any }
|
||||
} & SetupContext &
|
||||
LifecycleHooks
|
||||
|
||||
@ -198,6 +201,9 @@ export function createComponentInstance(
|
||||
slots: EMPTY_OBJ,
|
||||
refs: EMPTY_OBJ,
|
||||
|
||||
// user namespace for storing whatever the user assigns to `this`
|
||||
user: {},
|
||||
|
||||
emit: (event: string, ...args: unknown[]) => {
|
||||
const props = instance.vnode.props || EMPTY_OBJ
|
||||
const handler = props[`on${event}`] || props[`on${capitalize(event)}`]
|
||||
|
@ -26,7 +26,7 @@ export const RenderProxyHandlers = {
|
||||
case '$emit':
|
||||
return target.emit
|
||||
default:
|
||||
break
|
||||
return target.user[key]
|
||||
}
|
||||
}
|
||||
},
|
||||
@ -35,15 +35,15 @@ export const RenderProxyHandlers = {
|
||||
if (data.hasOwnProperty(key)) {
|
||||
data[key] = value
|
||||
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 {
|
||||
if (__DEV__) {
|
||||
if (key[0] === '$') {
|
||||
// TODO warn attempt of mutating public property
|
||||
} else if (target.props.hasOwnProperty(key)) {
|
||||
// TODO warn attempt of mutating prop
|
||||
}
|
||||
}
|
||||
target.user[key] = value
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user