You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There's a lot of checks within the component to see if multiple is true, or if we're working with an option that is an object, not a string. Here's the select method:
/** * Select a given option. * @param {Object|String} option * @return {void} */select(option){if(!this.isOptionSelected(option)){if(this.taggable&&!this.optionExists(option)){option=this.createOption(option)}if(this.index){if(!option.hasOwnProperty(this.index)){returnconsole.warn(`[vue-select warn]: Index key "option.${this.index}" does not`+` exist in options object ${JSON.stringify(option)}.`)}option=option[this.index]}if(this.multiple&&!this.mutableValue){this.mutableValue=[option]}elseif(this.multiple){this.mutableValue.push(option)}else{this.mutableValue=option}this.onInput(this.mutableValue);}this.onAfterSelect(option)},
If all options are objects and mutableValue is always an array, we can cut out a whole bunch of conditionals. Additionally, if each option object always has a label and an index, we don't have to check for that either. The code becomes much more concise now:
/** * Select a given option. * @param {Object} option * @return {void} */select(option){if(!this.isOptionSelected(option)){if(this.taggable&&!this.optionExists(option)){option=this.createOption(option);}if(!option.hasOwnProperty(this.index)){returnconsole.warn(`[vue-select warn]: Index key "option.${this.index}" does not`+` exist in options object ${JSON.stringify(option)}.`,);}this.mutableValue.push(option);this.onInput(this.mutableValue);}this.onAfterSelect(option);},
The text was updated successfully, but these errors were encountered:
sagalbot
changed the title
Proposal: Options are always objects – value is always stored as array
V3 Proposal: Options are always objects – value is always stored as array
Feb 20, 2019
There's a lot of checks within the component to see if multiple is true, or if we're working with an option that is an object, not a string. Here's the
select
method:If all options are objects and
mutableValue
is always an array, we can cut out a whole bunch of conditionals. Additionally, if each option object always has alabel
and anindex
, we don't have to check for that either. The code becomes much more concise now:The text was updated successfully, but these errors were encountered: