Skip to content

Commit 1f21530

Browse files
committed
refactor(desk)!: remove watchers from i-value components
1 parent 23db28d commit 1f21530

File tree

13 files changed

+83
-489
lines changed

13 files changed

+83
-489
lines changed

package-lock.json

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

packages/desktop/modules/item/components/IValue.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default {
44
}
55
</script>
66
<script setup lang="ts">
7-
import { computed, useAttrs, defineAsyncComponent } from 'vue'
7+
import { useAttrs, defineAsyncComponent } from 'vue'
88
99
import { ColumnType } from '@core/entities/column'
1010
import { createBindings } from '@/composables/binding'
@@ -40,7 +40,9 @@ defineProps({
4040
4141
// bindings
4242
43-
const bindings = computed(() => createBindings(useAttrs(), ['input', 'select']))
43+
const attrs = useAttrs()
44+
45+
const bindings = createBindings(attrs, ['input', 'select'])
4446
</script>
4547

4648
<template>

packages/desktop/modules/item/components/IValueDate.vue

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ const props = defineProps({
1818
},
1919
})
2020
21-
const { payload, load, column, loading } = createValue()
22-
23-
watch(props, load, {
24-
deep: true,
25-
immediate: true,
26-
})
21+
const { payload, column, loading, save } = createValue(props)
2722
2823
const edit = ref(false)
2924
@@ -45,13 +40,13 @@ const display = computed(() => {
4540

4641
<template>
4742
<v-input
48-
v-if="loading.all"
43+
v-if="loading"
4944
:model-value="`${$t('loading')}...`"
5045
class="text-t-secondary text-sm"
5146
readonly
5247
/>
5348

54-
<v-input v-else-if="edit" v-model="payload">
49+
<v-input v-else-if="edit" v-model="payload" @update:model-value="save">
5550
<template #append>
5651
<v-btn size="sm" color="b-secondary" @click="edit = false">
5752
<v-icon name="check" />

packages/desktop/modules/item/components/IValueEntry.vue

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export default {
44
}
55
</script>
66
<script setup lang="ts">
7-
import { watch } from 'vue'
87
import template from 'lodash/template'
98
import uuid from 'uuid-random'
109
@@ -28,12 +27,7 @@ const props = defineProps({
2827
},
2928
})
3029
31-
const { payload, load, column, item, loading } = createValue<string | null>()
32-
33-
watch(props, load, {
34-
deep: true,
35-
immediate: true,
36-
})
30+
const { payload, column, item, save, loading } = createValue<string | null>(props)
3731
3832
// upload
3933
const store = useStore()
@@ -84,6 +78,8 @@ function upload() {
8478
}
8579
8680
payload.value = path
81+
82+
await save()
8783
}
8884
8985
input.click()
@@ -92,7 +88,7 @@ function upload() {
9288

9389
<template>
9490
<v-input
95-
v-if="loading.all"
91+
v-if="loading"
9692
:model-value="`${$t('loading')}...`"
9793
class="text-t-secondary text-sm"
9894
readonly

packages/desktop/modules/item/components/IValueLink.vue

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,7 @@ const props = defineProps({
1818
},
1919
})
2020
21-
const { payload, load, loading } = createValue()
22-
23-
watch(props, load, {
24-
deep: true,
25-
immediate: true,
26-
})
21+
const { payload, loading, save } = createValue(props)
2722
2823
const edit = ref(false)
2924
@@ -52,13 +47,13 @@ const display = computed(() => {
5247

5348
<template>
5449
<v-input
55-
v-if="loading.all"
50+
v-if="loading"
5651
:model-value="`${$t('loading')}...`"
5752
class="text-t-secondary text-sm"
5853
readonly
5954
/>
6055

61-
<v-input v-else-if="edit" v-model="payload">
56+
<v-input v-else-if="edit" v-model="payload" @update:model-value="save">
6257
<template #append>
6358
<v-btn size="text-xs px-2 " text @click="edit = false">
6459
<v-icon name="check" />
Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<script setup lang="ts">
2-
import { watch } from 'vue'
3-
42
import { createValue } from '@/modules/item/composables/value'
53
64
const props = defineProps({
@@ -18,21 +16,16 @@ const props = defineProps({
1816
},
1917
})
2018
21-
const { payload, load, loading } = createValue()
22-
23-
watch(props, load, {
24-
deep: true,
25-
immediate: true,
26-
})
19+
const { payload, loading, save } = createValue(props)
2720
</script>
2821

2922
<template>
3023
<v-input
31-
v-if="loading.all"
24+
v-if="loading"
3225
:model-value="`${$t('loading')}...`"
3326
class="text-t-secondary text-sm"
3427
readonly
3528
/>
3629

37-
<v-input v-else v-model="payload" type="number" />
30+
<v-input v-else v-model="payload" type="number" @update:model-value="save" />
3831
</template>

packages/desktop/modules/item/components/IValueRelation.vue

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ const props = defineProps({
2323
2424
// value
2525
26-
const { payload, load, column, loading } = createValue()
27-
28-
watch(props, load, {
29-
deep: true,
30-
immediate: true,
31-
})
26+
const { payload, column, loading, save } = createValue(props)
3227
3328
// options
3429
const store = useStore()
@@ -46,7 +41,7 @@ watch(column, setOptions)
4641

4742
<template>
4843
<v-input
49-
v-if="loading.all"
44+
v-if="loading"
5045
:model-value="`${$t('loading')}...`"
5146
class="text-t-secondary text-sm"
5247
readonly
@@ -63,8 +58,9 @@ watch(column, setOptions)
6358
v-else
6459
v-model="payload"
6560
:options="options"
66-
value-key="id"
67-
:label-key="column.displayField"
6861
:clear-value="() => null"
62+
:label-key="column.displayField"
63+
value-key="id"
64+
@update:model-value="save"
6965
/>
7066
</template>

packages/desktop/modules/item/components/IValueScript.vue

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { watch, ref } from 'vue'
2+
import { ref } from 'vue'
33
44
import { createValue } from '@/modules/item/composables/value'
55
import EvaluationOutput from '@/../core/entities/evaluation-output'
@@ -20,11 +20,10 @@ const props = defineProps({
2020
},
2121
})
2222
23-
const { load, column, item, loading } = createValue()
24-
25-
watch(props, load, {
26-
deep: true,
27-
immediate: true,
23+
const { loading, column, item, onLoaded } = createValue({
24+
collectionId: props.collectionId,
25+
columnId: props.columnId,
26+
itemId: props.itemId,
2827
})
2928
3029
// execute script
@@ -44,13 +43,12 @@ function setResult() {
4443
.then((r) => (output.value = r))
4544
.catch(() => (output.value = undefined))
4645
}
47-
48-
watch([column, item], setResult)
46+
onLoaded(setResult)
4947
</script>
5048

5149
<template>
5250
<v-input
53-
v-if="loading.all"
51+
v-if="loading"
5452
:model-value="`${$t('loading')}...`"
5553
class="text-t-secondary text-sm"
5654
readonly

packages/desktop/modules/item/components/IValueSelect.vue

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { watch, computed } from 'vue'
2+
import { computed } from 'vue'
33
44
import { createValue } from '@/modules/item/composables/value'
55
@@ -18,11 +18,10 @@ const props = defineProps({
1818
},
1919
})
2020
21-
const { payload, load, column, loading } = createValue()
22-
23-
watch(props, load, {
24-
deep: true,
25-
immediate: true,
21+
const { payload, loading, column, save } = createValue({
22+
collectionId: props.collectionId,
23+
columnId: props.columnId,
24+
itemId: props.itemId,
2625
})
2726
2827
const options = computed(() => {
@@ -34,11 +33,17 @@ const options = computed(() => {
3433

3534
<template>
3635
<v-input
37-
v-if="loading.all"
36+
v-if="loading"
3837
:model-value="`${$t('loading')}...`"
3938
class="text-t-secondary text-sm"
4039
readonly
4140
/>
4241

43-
<v-select v-else v-model="payload" :options="options" :clear-value="() => null" />
42+
<v-select
43+
v-else
44+
v-model="payload"
45+
:options="options"
46+
:clear-value="() => null"
47+
@update:model-value="save"
48+
/>
4449
</template>

packages/desktop/modules/item/components/IValueText.vue

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
<script setup lang="ts">
2-
import { watch } from 'vue'
3-
42
import { createValue } from '@/modules/item/composables/value'
53
64
const props = defineProps({
@@ -18,21 +16,20 @@ const props = defineProps({
1816
},
1917
})
2018
21-
const { payload, load, loading } = createValue()
22-
23-
watch(props, load, {
24-
deep: true,
25-
immediate: true,
19+
const { payload, loading, save } = createValue({
20+
collectionId: props.collectionId,
21+
columnId: props.columnId,
22+
itemId: props.itemId,
2623
})
2724
</script>
2825

2926
<template>
3027
<v-input
31-
v-if="loading.all"
28+
v-if="loading"
3229
:model-value="`${$t('loading')}...`"
3330
class="text-t-secondary text-sm"
3431
readonly
3532
/>
3633

37-
<v-input v-else v-model="payload" />
34+
<v-input v-else v-model="payload" @update:model-value="save" />
3835
</template>

packages/desktop/modules/item/components/IValueTimestamp.vue

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,7 @@ const props = defineProps({
1919
},
2020
})
2121
22-
const { load, column, item, loading } = createValue()
23-
24-
watch(props, load, {
25-
deep: true,
26-
immediate: true,
27-
})
22+
const { column, item, loading } = createValue(props)
2823
2924
// display
3025
const display = computed(() => {
@@ -40,7 +35,7 @@ const display = computed(() => {
4035

4136
<template>
4237
<v-input
43-
v-if="loading.all"
38+
v-if="loading"
4439
:model-value="`${$t('loading')}...`"
4540
class="text-t-secondary text-sm"
4641
readonly

0 commit comments

Comments
 (0)