refactor: replace find method for improved readability (#13395)

This commit is contained in:
inottn
2025-03-16 07:56:14 +08:00
committed by GitHub
parent 567c3bf40b
commit ad085a4c99
3 changed files with 4 additions and 5 deletions

View File

@@ -49,7 +49,7 @@ export const isOptionExist = (
fields: Required<PickerFieldNames>, fields: Required<PickerFieldNames>,
) => ) =>
value !== undefined && value !== undefined &&
!!options.find((option) => option[fields.value] === value); options.some((option) => option[fields.value] === value);
export function findOptionByValue( export function findOptionByValue(
options: PickerOption[], options: PickerOption[],

View File

@@ -59,7 +59,7 @@ export default defineComponent({
const { $route } = vm; const { $route } = vm;
const { to } = props; const { to } = props;
const config = isObject(to) ? to : { path: to }; const config = isObject(to) ? to : { path: to };
return !!$route.matched.find((val) => { return $route.matched.some((val) => {
const pathMatched = 'path' in config && config.path === val.path; const pathMatched = 'path' in config && config.path === val.path;
const nameMatched = 'name' in config && config.name === val.name; const nameMatched = 'name' in config && config.name === val.name;
return pathMatched || nameMatched; return pathMatched || nameMatched;

View File

@@ -267,12 +267,11 @@ export default defineComponent({
name: Numeric, name: Numeric,
skipScrollIntoView?: boolean, skipScrollIntoView?: boolean,
) => { ) => {
const matched = children.find( const index = children.findIndex(
(tab, index) => getTabName(tab, index) === name, (tab, index) => getTabName(tab, index) === name,
); );
const index = matched ? children.indexOf(matched) : 0; setCurrentIndex(index === -1 ? 0 : index, skipScrollIntoView);
setCurrentIndex(index, skipScrollIntoView);
}; };
const scrollToCurrentContent = (immediate = false) => { const scrollToCurrentContent = (immediate = false) => {