Skip to content

Commit

Permalink
fix(transport-commons): Properly delete route data (#3433)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitamorozov committed Feb 25, 2024
1 parent c9511d9 commit af01bdb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/transport-commons/src/routing/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export class RouteNode<T = any> {

remove(path: string[]) {
if (path.length === this.depth) {
delete this.data
return
}

Expand Down
18 changes: 18 additions & 0 deletions packages/transport-commons/test/routing/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,22 @@ describe('router', () => {
r.remove('/hello/here/thing')
assert.ok(!r.root.hasChildren)
})

it('re-initialize a service with children. (#3432)', () => {
const r = new Router<string>()

r.insert('/hello', 'one')
r.insert('/hello/world', 'else')

assert.deepStrictEqual(r.lookup('hello'), { params: { }, data: 'one' })

r.remove('/hello')

assert.deepStrictEqual(r.lookup('hello/world'), { params: {}, data: 'else' })

r.insert('/hello', 'two')

assert.deepStrictEqual(r.lookup('hello'), { params: { }, data: 'two' })
assert.deepStrictEqual(r.lookup('hello/world'), { params: {}, data: 'else' })
})
})

0 comments on commit af01bdb

Please sign in to comment.