Skip to content

Commit b02a306

Browse files
committed
chore: update
1 parent c406fd0 commit b02a306

File tree

3 files changed

+16
-23
lines changed

3 files changed

+16
-23
lines changed

packages/runtime-core/src/component.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ export interface GenericComponentInstance {
381381
/**
382382
* @internal
383383
*/
384-
getRawProps: () => Record<string, any> | null
384+
getKeysFromRawProps: () => string[] | undefined
385385

386386
// exposed properties via expose()
387387
exposed: Record<string, any> | null
@@ -735,7 +735,7 @@ export function createComponentInstance(
735735

736736
// props default value
737737
propsDefaults: null,
738-
getRawProps: null!,
738+
getKeysFromRawProps: null!, // to be set immediately
739739

740740
// inheritAttrs
741741
inheritAttrs: type.inheritAttrs,
@@ -783,7 +783,10 @@ export function createComponentInstance(
783783
}
784784
instance.root = parent ? parent.root : instance
785785
instance.emit = emit.bind(null, instance)
786-
instance.getRawProps = () => instance.vnode.props
786+
instance.getKeysFromRawProps = () => {
787+
const { props } = instance.vnode
788+
if (props) return Object.keys(props)
789+
}
787790

788791
// apply custom element special handling
789792
if (vnode.ce) {

packages/runtime-core/src/helpers/useModel.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,17 @@ export function useModel(
6565
) {
6666
return
6767
}
68-
const rawProps = i.getRawProps()
68+
const rawPropKeys = i.getKeysFromRawProps()
6969
if (
7070
!(
71-
rawProps &&
71+
rawPropKeys &&
7272
// check if parent has passed v-model
73-
(name in rawProps ||
74-
camelizedName in rawProps ||
75-
hyphenatedName in rawProps) &&
76-
(`onUpdate:${name}` in rawProps ||
77-
`onUpdate:${camelizedName}` in rawProps ||
78-
`onUpdate:${hyphenatedName}` in rawProps)
73+
(rawPropKeys.includes(name) ||
74+
rawPropKeys.includes(camelizedName) ||
75+
rawPropKeys.includes(hyphenatedName)) &&
76+
(rawPropKeys.includes(`onUpdate:${name}`) ||
77+
rawPropKeys.includes(`onUpdate:${camelizedName}`) ||
78+
rawPropKeys.includes(`onUpdate:${hyphenatedName}`))
7979
)
8080
) {
8181
// no v-model, local update

packages/runtime-vapor/src/component.ts

+2-12
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export class VaporComponentInstance implements GenericComponentInstance {
285285
props: Record<string, any>
286286
attrs: Record<string, any>
287287
propsDefaults: Record<string, any> | null
288-
getRawProps: () => Record<string, any>
288+
getKeysFromRawProps: () => string[] | undefined
289289

290290
slots: StaticSlots
291291

@@ -395,17 +395,7 @@ export class VaporComponentInstance implements GenericComponentInstance {
395395
} else {
396396
this.props = this.attrs = EMPTY_OBJ
397397
}
398-
this.getRawProps = () => {
399-
const keys = getKeysFromRawProps(this.rawProps)
400-
return keys.reduce(
401-
(props, key) => {
402-
// TODO
403-
props[key] = null
404-
return props
405-
},
406-
{} as Record<string, any>,
407-
)
408-
}
398+
this.getKeysFromRawProps = () => getKeysFromRawProps(this.rawProps)
409399

410400
// init slots
411401
this.rawSlots = rawSlots || EMPTY_OBJ

0 commit comments

Comments
 (0)