* Set a property on an object. Adds the new property and * triggers change notification if the property doesn't * already exist.
(target, key, val)
| 1077 | * already exist. |
| 1078 | */ |
| 1079 | function set (target, key, val) { |
| 1080 | if (isUndef(target) || isPrimitive(target) |
| 1081 | ) { |
| 1082 | warn(("Cannot set reactive property on undefined, null, or primitive value: " + ((target)))); |
| 1083 | } |
| 1084 | if (Array.isArray(target) && isValidArrayIndex(key)) { |
| 1085 | target.length = Math.max(target.length, key); |
| 1086 | target.splice(key, 1, val); |
| 1087 | return val |
| 1088 | } |
| 1089 | if (key in target && !(key in Object.prototype)) { |
| 1090 | target[key] = val; |
| 1091 | return val |
| 1092 | } |
| 1093 | var ob = (target).__ob__; |
| 1094 | if (target._isVue || (ob && ob.vmCount)) { |
| 1095 | warn( |
| 1096 | 'Avoid adding reactive properties to a Vue instance or its root $data ' + |
| 1097 | 'at runtime - declare it upfront in the data option.' |
| 1098 | ); |
| 1099 | return val |
| 1100 | } |
| 1101 | if (!ob) { |
| 1102 | target[key] = val; |
| 1103 | return val |
| 1104 | } |
| 1105 | defineReactive$$1(ob.value, key, val); |
| 1106 | ob.dep.notify(); |
| 1107 | return val |
| 1108 | } |
| 1109 | |
| 1110 | /** |
| 1111 | * Delete a property and trigger change if necessary. |
no test coverage detected