MCPcopy Index your code
hub / github.com/ygs-code/vue / getPropDefaultValue

Function getPropDefaultValue

vue.js:2353–2389  ·  view source on GitHub ↗

* Get the default value of a prop. *获取prop 属性默认的vue值

(vm, prop, key)

Source from the content-addressed store, hash-verified

2351 *获取prop 属性默认的vue值
2352 */
2353 function getPropDefaultValue(vm, prop, key) {
2354 // no default, return undefined
2355 //判断该对象prop 中的default 是否是prop 实例化的
2356 if (!hasOwn(prop, 'default')) {
2357 return undefined
2358 }
2359 var def = prop.default;
2360 // warn against non-factory defaults for Object & Array
2361 //警告对象和数组的非工厂默认值
2362 if ("development" !== 'production' && isObject(def)) {
2363 warn(
2364 'Invalid default value for prop "' + key + '": ' +
2365 'Props with type Object/Array must use a factory function ' +
2366 'to return the default value.',
2367 vm
2368 );
2369 }
2370 // the raw prop value was also undefined from previous render,
2371 //原始PROP值也未从先前的渲染中定义,
2372 // return previous default value to avoid unnecessary watcher trigger
2373 //返回先前的默认值以避免不必要的监视触发器
2374 if (vm && vm.$options.propsData &&
2375 vm.$options.propsData[key] === undefined &&
2376 vm._props[key] !== undefined
2377 ) {
2378 return vm._props[key]
2379 }
2380 // call factory function for non-Function types
2381 //非功能类型调用工厂函数
2382 // a value is Function if its prototype is function even across different execution context
2383 //一个值是函数,即使它的原型在不同的执行上下文中也是函数。
2384 //getType检查函数是否是函数声明 如果是函数表达式或者匿名函数是匹配不上的
2385 //判断def 是不是函数 如果是则执行,如果不是则返回props的PropDefaultValue
2386 return typeof def === 'function' && getType(prop.type) !== 'Function'
2387 ? def.call(vm)
2388 : def
2389 }
2390
2391 /**
2392 * Assert whether a prop is valid.

Callers 1

validatePropFunction · 0.85

Calls 3

hasOwnFunction · 0.85
isObjectFunction · 0.85
getTypeFunction · 0.85

Tested by

no test coverage detected