* Get the default value of a prop.
(vm, prop, key)
| 1310 | * Get the default value of a prop. |
| 1311 | */ |
| 1312 | function getPropDefaultValue (vm, prop, key) { |
| 1313 | // no default, return undefined |
| 1314 | if (!hasOwn(prop, 'default')) { |
| 1315 | return undefined |
| 1316 | } |
| 1317 | var def = prop.default; |
| 1318 | // warn against non-factory defaults for Object & Array |
| 1319 | if ("development" !== 'production' && isObject(def)) { |
| 1320 | warn( |
| 1321 | 'Invalid default value for prop "' + key + '": ' + |
| 1322 | 'Props with type Object/Array must use a factory function ' + |
| 1323 | 'to return the default value.', |
| 1324 | vm |
| 1325 | ); |
| 1326 | } |
| 1327 | // the raw prop value was also undefined from previous render, |
| 1328 | // return previous default value to avoid unnecessary watcher trigger |
| 1329 | if (vm && vm.$options.propsData && |
| 1330 | vm.$options.propsData[key] === undefined && |
| 1331 | vm._props[key] !== undefined) { |
| 1332 | return vm._props[key] |
| 1333 | } |
| 1334 | // call factory function for non-Function types |
| 1335 | // a value is Function if its prototype is function even across different execution context |
| 1336 | return typeof def === 'function' && getType(prop.type) !== 'Function' |
| 1337 | ? def.call(vm) |
| 1338 | : def |
| 1339 | } |
| 1340 | |
| 1341 | /** |
| 1342 | * Assert whether a prop is valid. |
no test coverage detected