From b2e282b30c1e32990c4fe3dd39e282490ebc00a0 Mon Sep 17 00:00:00 2001 From: christianalfoni Date: Mon, 4 Feb 2019 18:55:50 +0100 Subject: [PATCH] fix(proxy-state-tree): remove optimization that causes issue with addMutationListener --- .../proxy-state-tree/src/Proxyfier.ts | 70 +++++++------------ .../proxy-state-tree/src/index.test.ts | 40 ----------- 2 files changed, 27 insertions(+), 83 deletions(-) diff --git a/packages/node_modules/proxy-state-tree/src/Proxyfier.ts b/packages/node_modules/proxy-state-tree/src/Proxyfier.ts index 1986d74d..c51697ad 100644 --- a/packages/node_modules/proxy-state-tree/src/Proxyfier.ts +++ b/packages/node_modules/proxy-state-tree/src/Proxyfier.ts @@ -90,15 +90,6 @@ export class Proxifier { } } - shouldTrackMutations(path) { - return ( - this.tree.master.options.devmode || - // We need the !! to avoid weird types for shouldTrackMutations that - // actually break (because they contain references to 'src') - !!(path && this.tree.master.pathDependencies[path]) - ) - } - ensureMutationTrackingIsEnabled(path) { if (this.tree.master.options.devmode && !this.tree.canMutate()) { throw new Error( @@ -183,10 +174,7 @@ export class Proxifier { const method = String(prop) - if ( - arrayMutations.has(method) && - proxifier.shouldTrackMutations(nestedPath) - ) { + if (arrayMutations.has(method)) { // On POP we can optimally remove cached proxy by removing the specific one // that was removed. If it is a PUSH, we do not have to remove anything, as // existing proxies stays the same @@ -318,24 +306,22 @@ export class Proxifier { proxifier.tree.master.removeProxy(nestedPath) } - if (proxifier.shouldTrackMutations(nestedPath)) { - let objectChangePath + let objectChangePath - if (!(prop in target)) { - objectChangePath = path - } + if (!(prop in target)) { + objectChangePath = path + } - const mutationTree = proxifier.getMutationTree() + const mutationTree = proxifier.getMutationTree() - mutationTree.addMutation( - { - method: 'set', - path: nestedPath, - args: [value], - }, - objectChangePath - ) - } + mutationTree.addMutation( + { + method: 'set', + path: nestedPath, + args: [value], + }, + objectChangePath + ) if (typeof value === 'function') { return Reflect.set(target, prop, () => value) @@ -352,23 +338,21 @@ export class Proxifier { proxifier.tree.master.removeProxy(nestedPath) } - if (proxifier.shouldTrackMutations(nestedPath)) { - let objectChangePath - if (prop in target) { - objectChangePath = path - } + let objectChangePath + if (prop in target) { + objectChangePath = path + } - const mutationTree = proxifier.getMutationTree() + const mutationTree = proxifier.getMutationTree() - mutationTree.addMutation( - { - method: 'unset', - path: nestedPath, - args: [], - }, - objectChangePath - ) - } + mutationTree.addMutation( + { + method: 'unset', + path: nestedPath, + args: [], + }, + objectChangePath + ) delete target[prop] diff --git a/packages/node_modules/proxy-state-tree/src/index.test.ts b/packages/node_modules/proxy-state-tree/src/index.test.ts index ef33da14..50e7f315 100644 --- a/packages/node_modules/proxy-state-tree/src/index.test.ts +++ b/packages/node_modules/proxy-state-tree/src/index.test.ts @@ -829,46 +829,6 @@ describe('ITERATIONS', () => { }) }) -describe('PRODUCTION', () => { - it('should track mutations for observed paths', () => { - const tree = new ProxyStateTree( - { - items: [ - { - title: 'foo', - }, - { - title: 'bar', - }, - ], - }, - { - devmode: false, - } - ) - - const accessTree = tree.getTrackStateTree().track(() => {}) - const mutationTree = tree.getMutationTree() - accessTree.state.items[0].title - - mutationTree.state.items[0].title = 'foo1' - delete mutationTree.state.items[0].title - mutationTree.state.items[1].title = 'bar2' // this mutation should not be tracked - expect(mutationTree.mutations).toEqual([ - { - method: 'set', - path: 'items.0.title', - args: ['foo1'], - }, - { - method: 'unset', - path: 'items.0.title', - args: [], - }, - ]) - }) -}) - describe('RESCOPING', () => { it('should be able to change scope of state', () => { const tree = new ProxyStateTree({