Make watch be triggered immediately (#15758)

* Make watch be triggered immediately

* Fix linter warning

Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
Nitwel
2022-10-15 04:52:13 +02:00
committed by GitHub
parent 64901d736c
commit 924b4199e6

View File

@@ -59,26 +59,30 @@ export function useCustomSelectionMultiple(
): UsableCustomSelectionMultiple {
const otherValues = ref<OtherValue[]>([]);
watch(currentValues, (newValue) => {
if (newValue === null) return;
if (Array.isArray(newValue) === false) return;
if (items.value === null) return;
(newValue as string[]).forEach((value) => {
watch(
currentValues,
(newValue) => {
if (newValue === null) return;
if (Array.isArray(newValue) === false) return;
if (items.value === null) return;
const values = items.value.map((item) => item.value);
const existsInValues = values.includes(value) === true;
if (existsInValues === false) {
const other = otherValues.value.map((o) => o.value);
const existsInOtherValues = other.includes(value) === true;
(newValue as string[]).forEach((value) => {
if (items.value === null) return;
const values = items.value.map((item) => item.value);
const existsInValues = values.includes(value) === true;
if (existsInOtherValues === false) {
addOtherValue(value);
if (existsInValues === false) {
const other = otherValues.value.map((o) => o.value);
const existsInOtherValues = other.includes(value) === true;
if (existsInOtherValues === false) {
addOtherValue(value);
}
}
}
});
});
});
},
{ immediate: true }
);
return { otherValues, addOtherValue, setOtherValue };