for (let i = 0, l = (this as any).length; i < l; i++) {
track(arr, TrackOpTypes.GET, i + '')
}
- return arr[key](...args.map(toRaw))
+ // we run the method using the orignal args first (which may be reactive)
+ const res = arr[key](...args)
+ if (res === -1 || res === false) {
+ // if that didn't work, run it again using raw values.
+ return arr[key](...args.map(toRaw))
+ } else {
+ return res
+ }
}
})
wrap: typeof toReactive | typeof toReadonly
) {
target = toRaw(target)
- key = toRaw(key)
- track(target, TrackOpTypes.GET, key)
- return wrap(getProto(target).get.call(target, key))
+ const rawKey = toRaw(key)
+ track(target, TrackOpTypes.GET, rawKey)
+ const { has, get } = getProto(target)
+ if (has.call(target, key)) {
+ return wrap(get.call(target, key))
+ } else if (has.call(target, rawKey)) {
+ return wrap(get.call(target, rawKey))
+ }
}
function has(this: CollectionTypes, key: unknown): boolean {
const target = toRaw(this)
- key = toRaw(key)
- track(target, TrackOpTypes.HAS, key)
- return getProto(target).has.call(target, key)
+ const rawKey = toRaw(key)
+ track(target, TrackOpTypes.HAS, rawKey)
+ const has = getProto(target).has
+ return has.call(target, key) || has.call(target, rawKey)
}
function size(target: IterableCollections) {
}
function deleteEntry(this: CollectionTypes, key: unknown) {
- key = toRaw(key)
const target = toRaw(this)
- const proto = getProto(target)
- const hadKey = proto.has.call(target, key)
- const oldValue = proto.get ? proto.get.call(target, key) : undefined
+ const { has, get, delete: del } = getProto(target)
+ let hadKey = has.call(target, key)
+ if (!hadKey) {
+ key = toRaw(key)
+ hadKey = has.call(target, key)
+ }
+ const oldValue = get ? get.call(target, key) : undefined
// forward the operation before queueing reactions
- const result = proto.delete.call(target, key)
+ const result = del.call(target, key)
if (hadKey) {
trigger(target, TriggerOpTypes.DELETE, key, undefined, oldValue)
}
return get(this, key, toReactive)
},
get size() {
- return size(this as unknown as IterableCollections)
+ return size((this as unknown) as IterableCollections)
},
has,
add,