Skip to content

Commit

Permalink
fix: Fix edit on native Map
Browse files Browse the repository at this point in the history
  • Loading branch information
Azurewarth0920 committed Feb 3, 2024
1 parent 8f4c545 commit 61d03a8
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions packages/devtools-kit/src/core/component/state/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export class StateEditor {
const markRef = false
while (sections.length > 1) {
const section = sections.shift()!
object = object[section] as Recordable
if (object instanceof Map)
object = object.get(section) as Recordable
else
object = object[section] as Recordable
if (this.refEditor.isRef(object))
object = this.refEditor.get(object)
}
Expand All @@ -42,7 +45,10 @@ export class StateEditor {
get(object: Recordable, path: PropPath) {
const sections = Array.isArray(path) ? path : path.split('.')
for (let i = 0; i < sections.length; i++) {
object = object[sections[i]] as Recordable
if (object instanceof Map)
object = object.get(sections[i]) as Recordable
else
object = object[sections[i]] as Recordable
if (this.refEditor.isRef(object))
object = this.refEditor.get(object)
if (!object)
Expand Down Expand Up @@ -70,17 +76,18 @@ export class StateEditor {
if (state.remove || state.newKey) {
if (Array.isArray(object))
object.splice(field as number, 1)
else if (toRaw(object) instanceof Map && typeof value === 'object' && value && 'key' in value)
object.delete(value.key)
else if (toRaw(object) instanceof Map)
object.delete(field)
else if (toRaw(object) instanceof Set)
object.delete(value)
else
Reflect.deleteProperty(object, field)
else Reflect.deleteProperty(object, field)
}
if (!state.remove) {
const target = object[state.newKey || field]
if (this.refEditor.isRef(target))
this.refEditor.set(target, value)
else if (toRaw(object) instanceof Map)
object.set(state.newKey || field, value)
else
object[state.newKey || field] = value
}
Expand Down

0 comments on commit 61d03a8

Please sign in to comment.