Skip to content

Commit

Permalink
fix: only consider the binding value of string type as stringified JS…
Browse files Browse the repository at this point in the history
…ON under text mode
  • Loading branch information
cloydlau committed Apr 13, 2024
1 parent 9e79ff7 commit c71b567
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ export default defineComponent({
const preventUpdatingContent = ref(false)

const onChange = debounce((updatedContent: Content) => {
const computedMode = computed(() => conclude([props.mode, globalProps.mode], {
type: String as PropType<Mode>,
}))
const onChangeMode = (mode: Mode) => {
emit('update:mode', mode)
}
// Synchronize the local `mode` with the global one
if (globalProps.mode !== undefined && props.mode === undefined) {
onChangeMode(globalProps.mode)
}
preventUpdatingContent.value = true
emit(
updateModelValue,
Expand All @@ -70,9 +80,6 @@ export default defineComponent({
)
}, 100)

const onChangeMode = (mode: Mode) => {
emit('update:mode', mode)
}

const mergeFunction = (previousValue: (...args: any) => unknown, currentValue: (...args: any) => unknown) => (...args: any) => {
previousValue(...args)
Expand All @@ -86,13 +93,6 @@ export default defineComponent({
})

onMounted(() => {
const initialMode = conclude([props.mode, globalProps.mode], {
type: String as PropType<Mode>,
})
if (globalProps.mode !== undefined && props.mode === undefined) {
// will trigger watch
onChangeMode(globalProps.mode)
}
const initialValue = conclude([props[modelValueProp], globalProps[modelValueProp]])
const initialBoolAttrs = Object.fromEntries(
Array.from(boolAttrs, boolAttr => [boolAttr, conclude([props[boolAttr], globalProps[boolAttr]])]).filter(
Expand All @@ -107,9 +107,9 @@ export default defineComponent({
{
onChange,
onChangeMode,

Check failure on line 109 in src/Component.ts

View workflow job for this annotation

GitHub Actions / unit-test

test/index.test.ts > text mode

ReferenceError: onChangeMode is not defined ❯ src/Component.ts:109:13 ❯ node_modules/.pnpm/@VUE+runtime-core@3.4.21/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:2861:88 ❯ callWithErrorHandling node_modules/.pnpm/@VUE+runtime-core@3.4.21/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:195:19 ❯ callWithAsyncErrorHandling node_modules/.pnpm/@VUE+runtime-core@3.4.21/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:202:17 ❯ Array.hook.__weh.hook.__weh node_modules/.pnpm/@VUE+runtime-core@3.4.21/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:2841:19 ❯ flushPostFlushCbs node_modules/.pnpm/@VUE+runtime-core@3.4.21/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:368:41 ❯ render node_modules/.pnpm/@VUE+runtime-core@3.4.21/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6613:7 ❯ mount node_modules/.pnpm/@VUE+runtime-core@3.4.21/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3913:13 ❯ Object.app.mount node_modules/.pnpm/@VUE+runtime-dom@3.4.21/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.js:1453:19 ❯ Proxy.mount node_modules/.pnpm/@VUE+test-utils@2.4.5/node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8385:18

Check failure on line 109 in src/Component.ts

View workflow job for this annotation

GitHub Actions / unit-test

test/index.test.ts > tree mode

ReferenceError: onChangeMode is not defined ❯ src/Component.ts:109:13 ❯ node_modules/.pnpm/@VUE+runtime-core@3.4.21/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:2861:88 ❯ callWithErrorHandling node_modules/.pnpm/@VUE+runtime-core@3.4.21/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:195:19 ❯ callWithAsyncErrorHandling node_modules/.pnpm/@VUE+runtime-core@3.4.21/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:202:17 ❯ Array.hook.__weh.hook.__weh node_modules/.pnpm/@VUE+runtime-core@3.4.21/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:2841:19 ❯ flushPostFlushCbs node_modules/.pnpm/@VUE+runtime-core@3.4.21/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:368:41 ❯ render node_modules/.pnpm/@VUE+runtime-core@3.4.21/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:6613:7 ❯ mount node_modules/.pnpm/@VUE+runtime-core@3.4.21/node_modules/@vue/runtime-core/dist/runtime-core.cjs.js:3913:13 ❯ Object.app.mount node_modules/.pnpm/@VUE+runtime-dom@3.4.21/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.js:1453:19 ❯ Proxy.mount node_modules/.pnpm/@VUE+test-utils@2.4.5/node_modules/@vue/test-utils/dist/vue-test-utils.cjs.js:8385:18
mode: initialMode,
mode: computedMode.value,
...(initialValue !== undefined && {
content: { [typeof initialValue === 'string' ? 'text' : 'json']: initialValue },
content: { [(typeof initialValue === 'string' && computedMode.value === 'text') ? 'text' : 'json']: initialValue },
}),
},
],
Expand Down Expand Up @@ -140,7 +140,7 @@ export default defineComponent({
jsonEditor.value.set(
[undefined, ''].includes(newModelValue)
? { text: '' }
: { [typeof newModelValue === 'string' ? 'text' : 'json']: newModelValue },
: { [(typeof newModelValue === 'string' && computedMode.value === 'text') ? 'text' : 'json']: newModelValue },
)
}
},
Expand Down

0 comments on commit c71b567

Please sign in to comment.