Browse Source

fix/removed unnecassry onmount and getter function in watchers

pull/2946/head
Muhammed Mustafa 2 years ago
parent
commit
7899ee1bfe
  1. 39
      packages/nc-gui-v2/components/cell/Json.vue
  2. 25
      packages/nc-gui-v2/components/monaco/Editor.vue

39
packages/nc-gui-v2/components/cell/Json.vue

@ -3,7 +3,7 @@ import { Modal as AModal } from 'ant-design-vue'
import Editor from '~/components/monaco/Editor.vue'
import FullScreenIcon from '~icons/cil/fullscreen'
import FullScreenExitIcon from '~icons/cil/fullscreen-exit'
import { inject, onMounted } from '#imports'
import { inject } from '#imports'
import { EditModeInj } from '~/context'
interface Props {
@ -58,36 +58,27 @@ const onSave = () => {
vModel = localValue
}
onMounted(() => {
localValue = vModel
})
watch(
() => vModel,
$$(vModel),
(val) => {
localValue = val
},
{ immediate: true },
)
watch(
() => localValue,
(val) => {
try {
JSON.parse(val)
error = undefined
} catch (e: any) {
error = e
}
},
)
watch($$(localValue), (val) => {
try {
JSON.parse(val)
error = undefined
} catch (e: any) {
error = e
}
})
watch(
() => editEnabled,
() => {
isExpanded = false
localValue = vModel
},
)
watch(editEnabled, () => {
isExpanded = false
localValue = vModel
})
</script>
<template>

25
packages/nc-gui-v2/components/monaco/Editor.vue

@ -115,21 +115,18 @@ onMounted(() => {
}
})
watch(
() => vModel,
(v) => {
if (!editor || !v) return
const editorValue = editor?.getValue()
if (!disableDeepCompare) {
if (!editorValue || !deepCompare(JSON.parse(v), JSON.parse(editorValue))) {
editor.setValue(v)
}
} else {
if (editorValue !== v) editor.setValue(v)
watch($$(vModel), (v) => {
if (!editor || !v) return
const editorValue = editor?.getValue()
if (!disableDeepCompare) {
if (!editorValue || !deepCompare(JSON.parse(v), JSON.parse(editorValue))) {
editor.setValue(v)
}
},
)
} else {
if (editorValue !== v) editor.setValue(v)
}
})
</script>
<template>

Loading…
Cancel
Save