Skip to content

Commit 8aea60d

Browse files
fix(proxy-state-tree): properly fix indexOf issue
1 parent 63ee693 commit 8aea60d

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export class Proxifier {
4747
}"`
4848
)
4949
}
50+
51+
return value
5052
}
5153

5254
trackPath(path: string) {
@@ -102,7 +104,9 @@ export class Proxifier {
102104
if (prop === IS_PROXY) return true
103105
if (prop === PATH) return path
104106
if (prop === VALUE) return value
105-
107+
if (prop === 'indexOf') {
108+
return (arg) => value.indexOf(arg && arg[IS_PROXY] ? arg[VALUE] : arg)
109+
}
106110
if (
107111
prop === 'length' ||
108112
(typeof target[prop] === 'function' &&
@@ -112,10 +116,6 @@ export class Proxifier {
112116
return target[prop]
113117
}
114118

115-
if (prop === 'indexOf') {
116-
return (arg) => value.indexOf(arg && arg[IS_PROXY] ? arg[VALUE] : arg)
117-
}
118-
119119
const trackingTree = proxifier.getTrackingTree()
120120
const nestedPath = proxifier.concat(path, prop)
121121
const currentTree = trackingTree || proxifier.tree
@@ -137,7 +137,11 @@ export class Proxifier {
137137
hasChangedValue: true,
138138
})
139139

140-
return target[prop](...args)
140+
return target[prop](
141+
...args.map((arg) =>
142+
proxifier.ensureValueDosntExistInStateTreeElsewhere(arg)
143+
)
144+
)
141145
}
142146
}
143147

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -367,16 +367,6 @@ describe('ARRAYS', () => {
367367
mutationTree.flush()
368368
expect(currentProxy).not.toBe(newProxy)
369369
})
370-
371-
test('should track with indexOf', () => {
372-
const state = {
373-
foo: ['bar'],
374-
}
375-
const tree = new ProxyStateTree(state)
376-
const accessTree = tree.getTrackStateTree().track(() => {})
377-
expect(accessTree.state.foo.indexOf('bar')).toBe(0)
378-
expect(accessTree.pathDependencies).toEqual(new Set(['foo', 'foo.0']))
379-
})
380370
})
381371

382372
describe('MUTATIONS', () => {

0 commit comments

Comments
 (0)