(
target: Record<string | symbol, unknown>,
key: string | symbol,
value: unknown,
receiver: object,
)
| 140 | } |
| 141 | |
| 142 | set( |
| 143 | target: Record<string | symbol, unknown>, |
| 144 | key: string | symbol, |
| 145 | value: unknown, |
| 146 | receiver: object, |
| 147 | ): boolean { |
| 148 | let oldValue = target[key] |
| 149 | const isArrayWithIntegerKey = isArray(target) && isIntegerKey(key) |
| 150 | if (!this._isShallow) { |
| 151 | const isOldValueReadonly = isReadonly(oldValue) |
| 152 | if (!isShallow(value) && !isReadonly(value)) { |
| 153 | oldValue = toRaw(oldValue) |
| 154 | value = toRaw(value) |
| 155 | } |
| 156 | if (!isArrayWithIntegerKey && isRef(oldValue) && !isRef(value)) { |
| 157 | if (isOldValueReadonly) { |
| 158 | if (__DEV__) { |
| 159 | warn( |
| 160 | `Set operation on key "${String(key)}" failed: target is readonly.`, |
| 161 | target[key], |
| 162 | ) |
| 163 | } |
| 164 | return true |
| 165 | } else { |
| 166 | oldValue.value = value |
| 167 | return true |
| 168 | } |
| 169 | } |
| 170 | } else { |
| 171 | // in shallow mode, objects are set as-is regardless of reactive or not |
| 172 | } |
| 173 | |
| 174 | const hadKey = isArrayWithIntegerKey |
| 175 | ? Number(key) < target.length |
| 176 | : hasOwn(target, key) |
| 177 | const result = Reflect.set( |
| 178 | target, |
| 179 | key, |
| 180 | value, |
| 181 | isRef(target) ? target : receiver, |
| 182 | ) |
| 183 | // don't trigger if target is something up in the prototype chain of original |
| 184 | if (target === toRaw(receiver) && result) { |
| 185 | if (!hadKey) { |
| 186 | trigger(target, TriggerOpTypes.ADD, key, value) |
| 187 | } else if (hasChanged(value, oldValue)) { |
| 188 | trigger(target, TriggerOpTypes.SET, key, value, oldValue) |
| 189 | } |
| 190 | } |
| 191 | return result |
| 192 | } |
| 193 | |
| 194 | deleteProperty( |
| 195 | target: Record<string | symbol, unknown>, |
no test coverage detected