Skip to content

Commit 8b9beab

Browse files
fix(proxy-state-tree): allow untracking paths in different order
1 parent f0a599c commit 8b9beab

File tree

3 files changed

+5
-14
lines changed

3 files changed

+5
-14
lines changed

packages/node_modules/proxy-state-tree/jest.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
module.exports = {
22
collectCoverage: true,
3+
testEnvironment: 'node',
34
collectCoverageFrom: ['src/**/*.{t,j}s?(x)', '!src/**/*.d.ts'],
45
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
56
transform: {

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

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,15 +150,6 @@ describe('ARRAYS', () => {
150150
const pathsA = tree.clearPathsTracking(trackIdA)
151151
expect(pathsA).toEqual(new Set(['foo', 'foo.0']))
152152
})
153-
test('should throw when stopping outer nested tracking before inner', () => {
154-
const tree = new ProxyStateTree({})
155-
156-
const trackIdA = tree.startPathsTracking()
157-
tree.startPathsTracking()
158-
expect(() => {
159-
tree.clearPathsTracking(trackIdA)
160-
}).toThrow()
161-
})
162153
test('should correctly keep track of changing indexes', () => {
163154
expect.assertions(4)
164155
let listener

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,11 @@ class ProxyStateTree {
129129
return this.paths.push(new Set()) - 1
130130
}
131131
clearPathsTracking(index: number) {
132-
if (index !== this.paths.length - 1) {
133-
throw new Error(
134-
'Nested path tracking requires you to stop the nested path tracker before the outer'
135-
)
132+
const pathSet = this.paths.splice(index, 1, null)[0]
133+
134+
while (this.paths[this.paths.length - 1] === null) {
135+
this.paths.pop()
136136
}
137-
const pathSet = this.paths.pop()
138137

139138
if (!this.paths.length) {
140139
this.status = STATUS.IDLE

0 commit comments

Comments
 (0)