Skip to content

Commit 5ce3a00

Browse files
authoredFeb 4, 2024
feat(client): improve inspector UI of Map data type (#220)
1 parent 03c816e commit 5ce3a00

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed
 

‎packages/devtools-kit/src/core/component/state/custom.ts

+1-7
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,7 @@ export function getBigIntDetails(val: bigint | bigint) {
4040
}
4141

4242
export function getMapDetails(val: Map<string, unknown>) {
43-
const list: Array<Record<string, unknown>> = []
44-
val.forEach(
45-
(value, key) => list.push({
46-
key,
47-
value,
48-
}),
49-
)
43+
const list: Record<string, unknown> = Object.fromEntries(val)
5044
return {
5145
_custom: {
5246
type: 'map',

‎packages/devtools-kit/src/core/component/state/editor.ts

+13-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ export class StateEditor {
2020
const markRef = false
2121
while (sections.length > 1) {
2222
const section = sections.shift()!
23-
object = object[section] as Recordable
23+
if (object instanceof Map)
24+
object = object.get(section) as Recordable
25+
else
26+
object = object[section] as Recordable
2427
if (this.refEditor.isRef(object))
2528
object = this.refEditor.get(object)
2629
}
@@ -42,7 +45,10 @@ export class StateEditor {
4245
get(object: Recordable, path: PropPath) {
4346
const sections = Array.isArray(path) ? path : path.split('.')
4447
for (let i = 0; i < sections.length; i++) {
45-
object = object[sections[i]] as Recordable
48+
if (object instanceof Map)
49+
object = object.get(sections[i]) as Recordable
50+
else
51+
object = object[sections[i]] as Recordable
4652
if (this.refEditor.isRef(object))
4753
object = this.refEditor.get(object)
4854
if (!object)
@@ -70,17 +76,18 @@ export class StateEditor {
7076
if (state.remove || state.newKey) {
7177
if (Array.isArray(object))
7278
object.splice(field as number, 1)
73-
else if (toRaw(object) instanceof Map && typeof value === 'object' && value && 'key' in value)
74-
object.delete(value.key)
79+
else if (toRaw(object) instanceof Map)
80+
object.delete(field)
7581
else if (toRaw(object) instanceof Set)
7682
object.delete(value)
77-
else
78-
Reflect.deleteProperty(object, field)
83+
else Reflect.deleteProperty(object, field)
7984
}
8085
if (!state.remove) {
8186
const target = object[state.newKey || field]
8287
if (this.refEditor.isRef(target))
8388
this.refEditor.set(target, value)
89+
else if (toRaw(object) instanceof Map)
90+
object.set(state.newKey || field, value)
8491
else
8592
object[state.newKey || field] = value
8693
}

0 commit comments

Comments
 (0)
Please sign in to comment.