Skip to content

Commit

Permalink
chore(QSelect): small perf-related improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoenescu committed Sep 12, 2024
1 parent 43100df commit d044fdd
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions ui/src/components/select/QSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ const validateNewValueMode = v => [ 'add', 'add-unique', 'toggle' ].includes(v)
const reEscapeList = '.*+?^${}()|[]\\'
const fieldPropsList = Object.keys(useFieldProps)

function getPropValueFn (userPropName, defaultPropName) {
if (typeof userPropName === 'function') return userPropName

const propName = userPropName !== void 0
? userPropName
: defaultPropName

return opt => ((opt !== null && typeof opt === 'object' && propName in opt) ? opt[ propName ] : opt)
}

export default createComponent({
name: 'QSelect',

Expand Down Expand Up @@ -161,12 +171,7 @@ export default createComponent({

const onComposition = useKeyComposition(onInput)

const virtualScrollLength = computed(() => (
Array.isArray(props.options)
? props.options.length
: 0
))

const virtualScrollLength = computed(() => props.options.length)
const virtualScrollItemSizeComputed = computed(() => (
props.virtualScrollItemSize === void 0
? (props.optionsDense === true ? 24 : 48)
Expand Down Expand Up @@ -195,7 +200,7 @@ export default createComponent({
? (props.multiple === true && Array.isArray(props.modelValue) ? props.modelValue : [ props.modelValue ])
: []

if (props.mapOptions === true && Array.isArray(props.options) === true) {
if (props.mapOptions === true) {
const cache = props.mapOptions === true && innerValueCache !== void 0
? innerValueCache
: []
Expand Down Expand Up @@ -395,7 +400,7 @@ export default createComponent({
// takes into account 'option-disable' prop
const isOptionDisabled = computed(() => getPropValueFn(props.optionDisable, 'disable'))

const innerOptionsValue = computed(() => innerValue.value.map(opt => getOptionValue.value(opt)))
const innerOptionsValue = computed(() => innerValue.value.map(getOptionValue.value))

const inputControlEvents = computed(() => {
const evt = {
Expand Down Expand Up @@ -607,16 +612,6 @@ export default createComponent({
return props.options.find(fn) || valueCache.find(fn) || value
}

function getPropValueFn (propValue, defaultVal) {
const val = propValue !== void 0
? propValue
: defaultVal

return typeof val === 'function'
? val
: opt => (opt !== null && typeof opt === 'object' && val in opt ? opt[ val ] : opt)
}

function isOptionSelected (opt) {
const val = getOptionValue.value(opt)
return innerOptionsValue.value.find(v => isDeepEqual(v, val)) !== void 0
Expand Down

0 comments on commit d044fdd

Please sign in to comment.