* Helper that recursively merges two data objects together.
(from: AnyObject, to: AnyObject)
| 9 | * Helper that recursively merges two data objects together. |
| 10 | */ |
| 11 | function mergeData(from: AnyObject, to: AnyObject): Object { |
| 12 | if (!from) return to |
| 13 | if (!to) return from |
| 14 | |
| 15 | let key: any |
| 16 | let toVal: any |
| 17 | let fromVal: any |
| 18 | |
| 19 | const keys = hasSymbol ? Reflect.ownKeys(from) : Object.keys(from) |
| 20 | |
| 21 | for (let i = 0; i < keys.length; i++) { |
| 22 | key = keys[i] |
| 23 | // in case the object is already observed... |
| 24 | if (key === '__ob__') continue |
| 25 | toVal = to[key] |
| 26 | fromVal = from[key] |
| 27 | if (!hasOwn(to, key)) { |
| 28 | to[key] = fromVal |
| 29 | } else if ( |
| 30 | toVal !== fromVal && |
| 31 | isPlainObject(toVal) && |
| 32 | !isRef(toVal) && |
| 33 | isPlainObject(fromVal) && |
| 34 | !isRef(fromVal) |
| 35 | ) { |
| 36 | mergeData(fromVal, toVal) |
| 37 | } |
| 38 | } |
| 39 | return to |
| 40 | } |
| 41 | |
| 42 | export function install(Vue: VueConstructor) { |
| 43 | if (isVueRegistered(Vue)) { |
no test coverage detected
searching dependent graphs…