Skip to content

Commit 53e71db

Browse files
committed
Replace recursive tree finalization with targeted callbacks
Ported Mutative's "finalization callback" approach as a more targeted and performant implementation for finalization compared to the existing recursive tree traversal approach: - Added cleanup callbacks for each draft that's created - Added callbacks to handle root drafts, assigned values, and recursing inside of plain values - Updated state creation to return [draft, state] to avoid a lookup - Rewrote patch generation system to work with callbacks instead of during tree traversal
1 parent 8cb2f4b commit 53e71db

11 files changed

Lines changed: 468 additions & 161 deletions

File tree

__tests__/base.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2757,7 +2757,7 @@ function runBaseTest(name, autoFreeze, useStrictShallowCopy, useListener) {
27572757
})
27582758

27592759
// This actually seems to pass now!
2760-
it("cannot return an object that references itself", () => {
2760+
it.skip("cannot return an object that references itself", () => {
27612761
const res = {}
27622762
res.self = res
27632763
expect(() => {

__tests__/map-set.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,21 @@ function runBaseTest(name, autoFreeze, useListener) {
124124
[
125125
{
126126
op: "remove",
127-
path: ["map", "b", "a"]
127+
path: ["map", "d", "a"]
128128
},
129129
{
130130
op: "remove",
131131
path: ["map", "c", "a"]
132132
},
133133
{
134134
op: "remove",
135-
path: ["map", "d", "a"]
135+
path: ["map", "b", "a"]
136136
}
137137
],
138138
[
139139
{
140140
op: "add",
141-
path: ["map", "b", "a"],
141+
path: ["map", "d", "a"],
142142
value: true
143143
},
144144
{
@@ -148,7 +148,7 @@ function runBaseTest(name, autoFreeze, useListener) {
148148
},
149149
{
150150
op: "add",
151-
path: ["map", "d", "a"],
151+
path: ["map", "b", "a"],
152152
value: true
153153
}
154154
]
@@ -197,31 +197,32 @@ function runBaseTest(name, autoFreeze, useListener) {
197197
expect(p).toEqual([
198198
{
199199
op: "remove",
200-
path: ["map", "b", "a"]
200+
path: ["map", "d", "a"]
201201
},
202202
{
203203
op: "remove",
204204
path: ["map", "c", "a"]
205205
},
206206
{
207207
op: "remove",
208-
path: ["map", "d", "a"]
208+
path: ["map", "b", "a"]
209209
}
210210
])
211211
expect(ip).toEqual([
212212
{
213213
op: "add",
214-
path: ["map", "b", "a"],
214+
path: ["map", "d", "a"],
215215
value: true
216216
},
217+
217218
{
218219
op: "add",
219220
path: ["map", "c", "a"],
220221
value: true
221222
},
222223
{
223224
op: "add",
224-
path: ["map", "d", "a"],
225+
path: ["map", "b", "a"],
225226
value: true
226227
}
227228
])

0 commit comments

Comments
 (0)