+34
-1
lines changedFilter options
+34
-1
lines changed Original file line number Diff line number Diff line change
@@ -7,7 +7,8 @@ import {
7
7
TriggerOpTypes,
8
8
DebuggerEvent,
9
9
markRaw,
10
-
shallowReactive
10
+
shallowReactive,
11
+
readonly
11
12
} from '../src/index'
12
13
import { ITERATE_KEY } from '../src/effect'
13
14
@@ -832,4 +833,32 @@ describe('reactivity/effect', () => {
832
833
observed2.obj2 = obj2
833
834
expect(fnSpy2).toHaveBeenCalledTimes(1)
834
835
})
836
+
837
+
describe('readonly + reactive for Map', () => {
838
+
test('should work with readonly(reactive(Map))', () => {
839
+
const m = reactive(new Map())
840
+
const roM = readonly(m)
841
+
const fnSpy = jest.fn(() => roM.get(1))
842
+
843
+
effect(fnSpy)
844
+
expect(fnSpy).toHaveBeenCalledTimes(1)
845
+
m.set(1, 1)
846
+
expect(fnSpy).toHaveBeenCalledTimes(2)
847
+
})
848
+
849
+
test('should work with observed value as key', () => {
850
+
const key = reactive({})
851
+
const m = reactive(new Map())
852
+
m.set(key, 1)
853
+
const roM = readonly(m)
854
+
const fnSpy = jest.fn(() => roM.get(key))
855
+
856
+
effect(fnSpy)
857
+
expect(fnSpy).toHaveBeenCalledTimes(1)
858
+
m.set(key, 1)
859
+
expect(fnSpy).toHaveBeenCalledTimes(1)
860
+
m.set(key, 2)
861
+
expect(fnSpy).toHaveBeenCalledTimes(2)
862
+
})
863
+
})
835
864
})
Original file line number Diff line number Diff line change
@@ -49,6 +49,10 @@ function get(
49
49
return wrap(target.get(key))
50
50
} else if (has.call(rawTarget, rawKey)) {
51
51
return wrap(target.get(rawKey))
52
+
} else if (target !== rawTarget) {
53
+
// #3602 readonly(reactive(Map))
54
+
// ensure that the nested reactive `Map` can do tracking for itself
55
+
target.get(key)
52
56
}
53
57
}
54
58
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4