Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/devtools-kit/__tests__/component/editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,20 @@ describe('editor: StateEditor.set', () => {
stateEditor.set(target, path, '', defaultCallback)
expect(target).toEqual(new Map([['bar', 'baz']]))
})

it('modify nested value in map', () => {
const target = { foo: new Map([['bar', {
baz: 1,
}]]) }
const state = { newKey: '', type: '', value: 2 }
const path = ['foo', 'bar', 'baz']
const defaultCallback = stateEditor.createDefaultSetCallback(state)
stateEditor.set(target, path, 2, defaultCallback)
expect(target).toEqual({
foo: new Map([['bar', {
baz: 2,
}]]),
})
})
})
})
2 changes: 1 addition & 1 deletion packages/devtools-kit/src/core/component/state/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class StateEditor {
const section = sections.shift()!
if (object instanceof Map)
object = object.get(section) as Recordable
if (object instanceof Set)
else if (object instanceof Set)
object = Array.from(object.values())[section] as Recordable
else object = object[section] as Recordable
if (this.refEditor.isRef(object))
Expand Down
Loading