* Get the default value of a prop. * * @param {Vue} vm * @param {Object} prop * @return {*}
(vm, prop)
| 6222 | */ |
| 6223 | |
| 6224 | function getPropDefaultValue(vm, prop) { |
| 6225 | // no default, return undefined |
| 6226 | var options = prop.options; |
| 6227 | if (!hasOwn(options, 'default')) { |
| 6228 | // absent boolean value defaults to false |
| 6229 | return options.type === Boolean ? false : undefined; |
| 6230 | } |
| 6231 | var def = options['default']; |
| 6232 | // warn against non-factory defaults for Object & Array |
| 6233 | if (isObject(def)) { |
| 6234 | 'development' !== 'production' && warn('Invalid default value for prop "' + prop.name + '": ' + 'Props with type Object/Array must use a factory function ' + 'to return the default value.', vm); |
| 6235 | } |
| 6236 | // call factory function for non-Function types |
| 6237 | return typeof def === 'function' && options.type !== Function ? def.call(vm) : def; |
| 6238 | } |
| 6239 | |
| 6240 | /** |
| 6241 | * Assert whether a prop is valid. |
no test coverage detected