Skip to content

Commit f8eed63

Browse files
authored
fix(StateEditor): add isPrimitive helper and support bigint type (#744) (#854)
1 parent 09002d2 commit f8eed63

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/devtools/client/components/StateEditor.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ const colorMode = getColorMode()
2222
const proxy = shallowRef()
2323
const error = shallowRef()
2424
25+
function isPrimitive(value: any): boolean {
26+
return ['number', 'bigint', 'string', 'boolean'].includes(typeof value)
27+
}
28+
2529
function clone() {
2630
error.value = undefined
2731
try {
28-
if (props.state)
29-
proxy.value = JSON.parse(JSON.stringify(props.state || {}))
30-
else if (typeof props.state === 'number' || typeof props.state !== 'string')
31-
proxy.value = props.state
32+
proxy.value = isPrimitive(props.state)
33+
? props.state
34+
: JSON.parse(JSON.stringify(props.state || {}))
3235
}
3336
catch (e) {
3437
console.error(e)
@@ -44,7 +47,7 @@ onMounted(() => {
4447
watch(
4548
() => [props.revision, props.state],
4649
([_, state]) => {
47-
if (typeof state !== 'number' && typeof state !== 'string')
50+
if (!isPrimitive(state))
4851
deepSync(state, props.state)
4952
else
5053
proxy.value = props.state

0 commit comments

Comments
 (0)