Skip to content

Commit 108785e

Browse files
committed
perf: string values won't do JSON.parse anymore
1 parent 084de75 commit 108785e

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Component.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,13 @@ import {
99
unref,
1010
watch,
1111
} from 'vue-demi'
12-
import type {
13-
PropType,
14-
} from 'vue-demi'
12+
import type { PropType } from 'vue-demi'
1513
import { JSONEditor } from 'vanilla-jsoneditor'
1614
import { conclude } from 'vue-global-config'
1715
import { debounce } from 'lodash-es'
1816
import { globalAttrs, globalProps } from './index'
1917

2018
export type Mode = 'tree' | 'text'
21-
type ValueKey = 'json' | 'text'
2219

2320
const modelValueProp = isVue3 ? 'modelValue' : 'value'
2421
const updateModelValue = isVue3 ? 'update:modelValue' : 'input'
@@ -46,8 +43,6 @@ export default defineComponent({
4643
},
4744
emits: [updateModelValue, 'update:mode'],
4845
setup(props, { attrs, emit, expose }) {
49-
const valueToContentKey = (value: any): ValueKey => typeof value === 'string' ? 'text' : 'json'
50-
5146
const currentInstance = getCurrentInstance()?.proxy
5247
const jsonEditor = ref()
5348

@@ -78,7 +73,7 @@ export default defineComponent({
7873
...initialBoolAttrs,
7974
...initialValue !== undefined && {
8075
content: {
81-
[valueToContentKey(initialValue)]: initialValue,
76+
json: initialValue,
8277
},
8378
},
8479
}], {
@@ -100,7 +95,7 @@ export default defineComponent({
10095
preventOnChange.value = true
10196
jsonEditor.value.update([undefined, ''].includes(n)
10297
? { text: '' }
103-
: { [valueToContentKey(n)]: n })
98+
: { json: n })
10499
}, {
105100
deep: true,
106101
})

0 commit comments

Comments
 (0)