MCPcopy
hub / github.com/vuejs/core / initProps

Function initProps

packages/runtime-core/src/componentProps.ts:194–232  ·  view source on GitHub ↗
(
  instance: ComponentInternalInstance,
  rawProps: Data | null,
  isStateful: number, // result of bitwise flag comparison
  isSSR = false,
)

Source from the content-addressed store, hash-verified

192export type NormalizedPropsOptions = [NormalizedProps, string[]] | []
193
194export function initProps(
195 instance: ComponentInternalInstance,
196 rawProps: Data | null,
197 isStateful: number, // result of bitwise flag comparison
198 isSSR = false,
199): void {
200 const props: Data = {}
201 const attrs: Data = createInternalObject()
202
203 instance.propsDefaults = Object.create(null)
204
205 setFullProps(instance, rawProps, props, attrs)
206
207 // ensure all declared prop keys are present
208 for (const key in instance.propsOptions[0]) {
209 if (!(key in props)) {
210 props[key] = undefined
211 }
212 }
213
214 // validation
215 if (__DEV__) {
216 validateProps(rawProps || {}, props, instance)
217 }
218
219 if (isStateful) {
220 // stateful
221 instance.props = isSSR ? props : shallowReactive(props)
222 } else {
223 if (!instance.type.props) {
224 // functional w/ optional props, props === attrs
225 instance.props = attrs
226 } else {
227 // functional w/ declared props
228 instance.props = props
229 }
230 }
231 instance.attrs = attrs
232}
233
234function isInHmrContext(instance: ComponentInternalInstance | null) {
235 while (instance) {

Callers 1

setupComponentFunction · 0.90

Calls 4

createInternalObjectFunction · 0.90
shallowReactiveFunction · 0.90
setFullPropsFunction · 0.85
validatePropsFunction · 0.85

Tested by

no test coverage detected