Skip to content

Commit

Permalink
slight optimization
Browse files Browse the repository at this point in the history
`stringifyObject` does not need to be re-run for every selected value.

Co-authored-by: Laila Los <[email protected]>
  • Loading branch information
ahmedhamidawan and ElectronicBlueberry committed Oct 18, 2024
1 parent d2f7f07 commit b672e4a
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,11 @@ export function main(options: UnwrapNestedRefs<UseSelectManyOptions>): UnwrapNes
if (options.maintainSelectionOrder) {
const selectedValuesArray = Array.from(selectedValues);
selectedOptionsFiltered.sort((a, b) => {
const aIndex = selectedValuesArray.findIndex((v) => v === stringifyObject(a.value));
const bIndex = selectedValuesArray.findIndex((v) => v === stringifyObject(b.value));
const aAsString = stringifyObject(a.value);
const bAsString = stringifyObject(b.value);

const aIndex = selectedValuesArray.findIndex((v) => v === aAsString);
const bIndex = selectedValuesArray.findIndex((v) => v === bAsString);
return aIndex - bIndex;
});
}
Expand Down

0 comments on commit b672e4a

Please sign in to comment.