Skip to content

Commit b2e282b

Browse files
fix(proxy-state-tree): remove optimization that causes issue with addMutationListener
1 parent 6709cf7 commit b2e282b

File tree

2 files changed

+27
-83
lines changed

2 files changed

+27
-83
lines changed

packages/node_modules/proxy-state-tree/src/Proxyfier.ts

Lines changed: 27 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,6 @@ export class Proxifier {
9090
}
9191
}
9292

93-
shouldTrackMutations(path) {
94-
return (
95-
this.tree.master.options.devmode ||
96-
// We need the !! to avoid weird types for shouldTrackMutations that
97-
// actually break (because they contain references to 'src')
98-
!!(path && this.tree.master.pathDependencies[path])
99-
)
100-
}
101-
10293
ensureMutationTrackingIsEnabled(path) {
10394
if (this.tree.master.options.devmode && !this.tree.canMutate()) {
10495
throw new Error(
@@ -183,10 +174,7 @@ export class Proxifier {
183174

184175
const method = String(prop)
185176

186-
if (
187-
arrayMutations.has(method) &&
188-
proxifier.shouldTrackMutations(nestedPath)
189-
) {
177+
if (arrayMutations.has(method)) {
190178
// On POP we can optimally remove cached proxy by removing the specific one
191179
// that was removed. If it is a PUSH, we do not have to remove anything, as
192180
// existing proxies stays the same
@@ -318,24 +306,22 @@ export class Proxifier {
318306
proxifier.tree.master.removeProxy(nestedPath)
319307
}
320308

321-
if (proxifier.shouldTrackMutations(nestedPath)) {
322-
let objectChangePath
309+
let objectChangePath
323310

324-
if (!(prop in target)) {
325-
objectChangePath = path
326-
}
311+
if (!(prop in target)) {
312+
objectChangePath = path
313+
}
327314

328-
const mutationTree = proxifier.getMutationTree()
315+
const mutationTree = proxifier.getMutationTree()
329316

330-
mutationTree.addMutation(
331-
{
332-
method: 'set',
333-
path: nestedPath,
334-
args: [value],
335-
},
336-
objectChangePath
337-
)
338-
}
317+
mutationTree.addMutation(
318+
{
319+
method: 'set',
320+
path: nestedPath,
321+
args: [value],
322+
},
323+
objectChangePath
324+
)
339325

340326
if (typeof value === 'function') {
341327
return Reflect.set(target, prop, () => value)
@@ -352,23 +338,21 @@ export class Proxifier {
352338
proxifier.tree.master.removeProxy(nestedPath)
353339
}
354340

355-
if (proxifier.shouldTrackMutations(nestedPath)) {
356-
let objectChangePath
357-
if (prop in target) {
358-
objectChangePath = path
359-
}
341+
let objectChangePath
342+
if (prop in target) {
343+
objectChangePath = path
344+
}
360345

361-
const mutationTree = proxifier.getMutationTree()
346+
const mutationTree = proxifier.getMutationTree()
362347

363-
mutationTree.addMutation(
364-
{
365-
method: 'unset',
366-
path: nestedPath,
367-
args: [],
368-
},
369-
objectChangePath
370-
)
371-
}
348+
mutationTree.addMutation(
349+
{
350+
method: 'unset',
351+
path: nestedPath,
352+
args: [],
353+
},
354+
objectChangePath
355+
)
372356

373357
delete target[prop]
374358

packages/node_modules/proxy-state-tree/src/index.test.ts

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -829,46 +829,6 @@ describe('ITERATIONS', () => {
829829
})
830830
})
831831

832-
describe('PRODUCTION', () => {
833-
it('should track mutations for observed paths', () => {
834-
const tree = new ProxyStateTree(
835-
{
836-
items: [
837-
{
838-
title: 'foo',
839-
},
840-
{
841-
title: 'bar',
842-
},
843-
],
844-
},
845-
{
846-
devmode: false,
847-
}
848-
)
849-
850-
const accessTree = tree.getTrackStateTree().track(() => {})
851-
const mutationTree = tree.getMutationTree()
852-
accessTree.state.items[0].title
853-
854-
mutationTree.state.items[0].title = 'foo1'
855-
delete mutationTree.state.items[0].title
856-
mutationTree.state.items[1].title = 'bar2' // this mutation should not be tracked
857-
expect(mutationTree.mutations).toEqual([
858-
{
859-
method: 'set',
860-
path: 'items.0.title',
861-
args: ['foo1'],
862-
},
863-
{
864-
method: 'unset',
865-
path: 'items.0.title',
866-
args: [],
867-
},
868-
])
869-
})
870-
})
871-
872832
describe('RESCOPING', () => {
873833
it('should be able to change scope of state', () => {
874834
const tree = new ProxyStateTree({

0 commit comments

Comments
 (0)