Skip to content

Commit 60fb42d

Browse files
authored
fix: resolve Map nested object modification (#799)
1 parent db154d0 commit 60fb42d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

Diff for: packages/devtools-kit/__tests__/component/editor.test.ts

+15
Original file line numberDiff line numberDiff line change
@@ -176,5 +176,20 @@ describe('editor: StateEditor.set', () => {
176176
stateEditor.set(target, path, '', defaultCallback)
177177
expect(target).toEqual(new Map([['bar', 'baz']]))
178178
})
179+
180+
it('modify nested value in map', () => {
181+
const target = { foo: new Map([['bar', {
182+
baz: 1,
183+
}]]) }
184+
const state = { newKey: '', type: '', value: 2 }
185+
const path = ['foo', 'bar', 'baz']
186+
const defaultCallback = stateEditor.createDefaultSetCallback(state)
187+
stateEditor.set(target, path, 2, defaultCallback)
188+
expect(target).toEqual({
189+
foo: new Map([['bar', {
190+
baz: 2,
191+
}]]),
192+
})
193+
})
179194
})
180195
})

Diff for: packages/devtools-kit/src/core/component/state/editor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class StateEditor {
2323
const section = sections.shift()!
2424
if (object instanceof Map)
2525
object = object.get(section) as Recordable
26-
if (object instanceof Set)
26+
else if (object instanceof Set)
2727
object = Array.from(object.values())[section] as Recordable
2828
else object = object[section] as Recordable
2929
if (this.refEditor.isRef(object))

0 commit comments

Comments
 (0)