Skip to content

Commit e6c388f

Browse files
author
Kilisei
committed
Use shallowRef instead of ref in .vue files where possible
reference: https://vuejs.org/api/reactivity-advanced.html#shallowref
1 parent 7436c62 commit e6c388f

File tree

9 files changed

+32
-32
lines changed

9 files changed

+32
-32
lines changed

web_src/js/components/ActivityHeatmap.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts" setup>
22
// TODO: Switch to upstream after https://github.com/razorness/vue3-calendar-heatmap/pull/34 is merged
33
import {CalendarHeatmap} from '@silverwind/vue3-calendar-heatmap';
4-
import {onMounted, ref} from 'vue';
4+
import {onMounted, shallowRef} from 'vue';
55
import type {Value as HeatmapValue, Locale as HeatmapLocale} from '@silverwind/vue3-calendar-heatmap';
66
77
defineProps<{
@@ -24,7 +24,7 @@ const colorRange = [
2424
'var(--color-primary-dark-4)',
2525
];
2626
27-
const endDate = ref(new Date());
27+
const endDate = shallowRef(new Date());
2828
2929
onMounted(() => {
3030
// work around issue with first legend color being rendered twice and legend cut off

web_src/js/components/ContextPopup.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
import {SvgIcon} from '../svg.ts';
33
import {GET} from '../modules/fetch.ts';
44
import {getIssueColor, getIssueIcon} from '../features/issue.ts';
5-
import {computed, onMounted, ref} from 'vue';
5+
import {computed, onMounted, ref, shallowRef, useTemplateRef} from 'vue';
66
import type {IssuePathInfo} from '../types.ts';
77
88
const {appSubUrl, i18n} = window.config;
99
10-
const loading = ref(false);
10+
const loading = shallowRef(false);
1111
const issue = ref(null);
12-
const renderedLabels = ref('');
12+
const renderedLabels = shallowRef('');
1313
const i18nErrorOccurred = i18n.error_occurred;
14-
const i18nErrorMessage = ref(null);
14+
const i18nErrorMessage = shallowRef(null);
1515
1616
const createdAt = computed(() => new Date(issue.value.created_at).toLocaleDateString(undefined, {year: 'numeric', month: 'short', day: 'numeric'}));
1717
const body = computed(() => {
@@ -22,7 +22,7 @@ const body = computed(() => {
2222
return body;
2323
});
2424
25-
const root = ref<HTMLElement | null>(null);
25+
const root = useTemplateRef('root');
2626
2727
onMounted(() => {
2828
root.value.addEventListener('ce-load-context-popup', (e: CustomEventInit<IssuePathInfo>) => {

web_src/js/components/DiffFileTreeItem.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<script lang="ts" setup>
22
import {SvgIcon, type SvgName} from '../svg.ts';
3-
import {ref} from 'vue';
3+
import {shallowRef} from 'vue';
44
import {type DiffStatus, type DiffTreeEntry, diffTreeStore} from '../modules/diff-file.ts';
55
66
const props = defineProps<{
77
item: DiffTreeEntry,
88
}>();
99
1010
const store = diffTreeStore();
11-
const collapsed = ref(props.item.IsViewed);
11+
const collapsed = shallowRef(props.item.IsViewed);
1212
1313
function getIconForDiffStatus(pType: DiffStatus) {
1414
const diffTypes: Record<DiffStatus, { name: SvgName, classes: Array<string> }> = {

web_src/js/components/PullRequestMergeForm.vue

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
<script lang="ts" setup>
2-
import {computed, onMounted, onUnmounted, ref, watch} from 'vue';
2+
import {computed, onMounted, onUnmounted, ref, shallowRef, watch} from 'vue';
33
import {SvgIcon} from '../svg.ts';
44
import {toggleElem} from '../utils/dom.ts';
55
66
const {csrfToken, pageData} = window.config;
77
88
const mergeForm = ref(pageData.pullRequestMergeForm);
99
10-
const mergeTitleFieldValue = ref('');
11-
const mergeMessageFieldValue = ref('');
12-
const deleteBranchAfterMerge = ref(false);
13-
const autoMergeWhenSucceed = ref(false);
10+
const mergeTitleFieldValue = shallowRef('');
11+
const mergeMessageFieldValue = shallowRef('');
12+
const deleteBranchAfterMerge = shallowRef(false);
13+
const autoMergeWhenSucceed = shallowRef(false);
1414
15-
const mergeStyle = ref('');
15+
const mergeStyle = shallowRef('');
1616
const mergeStyleDetail = ref({
1717
hideMergeMessageTexts: false,
1818
textDoMerge: '',
@@ -21,10 +21,10 @@ const mergeStyleDetail = ref({
2121
hideAutoMerge: false,
2222
});
2323
24-
const mergeStyleAllowedCount = ref(0);
24+
const mergeStyleAllowedCount = shallowRef(0);
2525
26-
const showMergeStyleMenu = ref(false);
27-
const showActionForm = ref(false);
26+
const showMergeStyleMenu = shallowRef(false);
27+
const showActionForm = shallowRef(false);
2828
2929
const mergeButtonStyleClass = computed(() => {
3030
if (mergeForm.value.allOverridableChecksOk) return 'primary';

web_src/js/components/RepoActivityTopAuthors.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts" setup>
22
// @ts-expect-error - module exports no types
33
import {VueBarGraph} from 'vue-bar-graph';
4-
import {computed, onMounted, ref} from 'vue';
4+
import {computed, onMounted, ref, useTemplateRef} from 'vue';
55
66
const colors = ref({
77
barColor: 'green',
@@ -41,8 +41,8 @@ const graphWidth = computed(() => {
4141
return activityTopAuthors.length * 40;
4242
});
4343
44-
const styleElement = ref<HTMLElement | null>(null);
45-
const altStyleElement = ref<HTMLElement | null>(null);
44+
const styleElement = useTemplateRef('styleElement');
45+
const altStyleElement = useTemplateRef('altStyleElement');
4646
4747
onMounted(() => {
4848
const refStyle = window.getComputedStyle(styleElement.value);

web_src/js/components/RepoCodeFrequency.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
import {chartJsColors} from '../utils/color.ts';
2424
import {sleep} from '../utils.ts';
2525
import 'chartjs-adapter-dayjs-4/dist/chartjs-adapter-dayjs-4.esm';
26-
import {onMounted, ref} from 'vue';
26+
import {onMounted, ref, shallowRef} from 'vue';
2727
2828
const {pageData} = window.config;
2929
@@ -47,8 +47,8 @@ defineProps<{
4747
};
4848
}>();
4949
50-
const isLoading = ref(false);
51-
const errorText = ref('');
50+
const isLoading = shallowRef(false);
51+
const errorText = shallowRef('');
5252
const repoLink = ref(pageData.repoLink || []);
5353
const data = ref<DayData[]>([]);
5454

web_src/js/components/RepoRecentCommits.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
import {chartJsColors} from '../utils/color.ts';
2222
import {sleep} from '../utils.ts';
2323
import 'chartjs-adapter-dayjs-4/dist/chartjs-adapter-dayjs-4.esm';
24-
import {onMounted, ref} from 'vue';
24+
import {onMounted, ref, shallowRef} from 'vue';
2525
2626
const {pageData} = window.config;
2727
@@ -43,8 +43,8 @@ defineProps<{
4343
};
4444
}>();
4545
46-
const isLoading = ref(false);
47-
const errorText = ref('');
46+
const isLoading = shallowRef(false);
47+
const errorText = shallowRef('');
4848
const repoLink = ref(pageData.repoLink || []);
4949
const data = ref<DayData[]>([]);
5050

web_src/js/components/ViewFileTree.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<script lang="ts" setup>
22
import ViewFileTreeItem from './ViewFileTreeItem.vue';
3-
import {onMounted, ref} from 'vue';
3+
import {onMounted, useTemplateRef} from 'vue';
44
import {createViewFileTreeStore} from './ViewFileTreeStore.ts';
55
6-
const elRoot = ref<HTMLElement | null>(null);
6+
const elRoot = useTemplateRef('elRoot');
77
88
const props = defineProps({
99
repoLink: {type: String, required: true},

web_src/js/components/ViewFileTreeItem.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script lang="ts" setup>
22
import {SvgIcon} from '../svg.ts';
33
import {isPlainClick} from '../utils/dom.ts';
4-
import {ref} from 'vue';
4+
import {ref, shallowRef} from 'vue';
55
import {type createViewFileTreeStore} from './ViewFileTreeStore.ts';
66
77
type Item = {
@@ -20,9 +20,9 @@ const props = defineProps<{
2020
}>();
2121
2222
const store = props.store;
23-
const isLoading = ref(false);
23+
const isLoading = shallowRef(false);
2424
const children = ref(props.item.children);
25-
const collapsed = ref(!props.item.children);
25+
const collapsed = shallowRef(!props.item.children);
2626
2727
const doLoadChildren = async () => {
2828
collapsed.value = !collapsed.value;

0 commit comments

Comments
 (0)