fix(reactivity): fix iOS 12 JSON.stringify error on reactive objects

- Use WeakMap for raw -> reactive/readonly storage. This is slightly
  more expensive than using a field on the taget object but avoids
  polluting the original.

- also fix Collection.forEach callback value

fix #1916
This commit is contained in:
Evan You
2020-08-24 15:26:53 -04:00
parent 410e7abbbb
commit 016ba116a8
4 changed files with 33 additions and 30 deletions

View File

@@ -228,7 +228,7 @@ describe('reactivity/readonly', () => {
test('should retrieve readonly values on iteration', () => {
const key1 = {}
const key2 = {}
const original = new Collection([[key1, {}], [key2, {}]])
const original = new Map([[key1, {}], [key2, {}]])
const wrapped: any = readonly(original)
expect(wrapped.size).toBe(2)
for (const [key, value] of wrapped) {
@@ -246,7 +246,7 @@ describe('reactivity/readonly', () => {
test('should retrieve reactive + readonly values on iteration', () => {
const key1 = {}
const key2 = {}
const original = reactive(new Collection([[key1, {}], [key2, {}]]))
const original = reactive(new Map([[key1, {}], [key2, {}]]))
const wrapped: any = readonly(original)
expect(wrapped.size).toBe(2)
for (const [key, value] of wrapped) {