Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/UIPSelectSetting: empty option processing #152

Merged
merged 2 commits into from
Nov 18, 2021

Conversation

Sisha0
Copy link
Collaborator

@Sisha0 Sisha0 commented Aug 24, 2021

Fix processing UIPSelectSetting's value when "empty" option (<option value="">None</option>) is present

@github-actions
Copy link

github-actions bot commented Aug 24, 2021

CLA Assistant Lite bot All contributors have signed the CLA ✍️

return Array.from(arrays.reduce((intersect, arr) => {
arr.forEach(val => !intersect.has(val) && intersect.delete(val));
const sets = arrays.map(arr => new Set(arr));
return Array.from(sets.reduce((intersect, set) => {
Copy link
Contributor

@ala-n ala-n Aug 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can try the following snippet, if I remember correctly it has an optimal combination of speed and length

function intersection(a, b, ...rest) {
  if (rest.length) return intersection(a, intersection(b, ...rest));
  return a.filter(Set.prototype.has, new Set(b));
}

@@ -114,8 +114,12 @@ export class UIPSelectSetting extends UIPSetting {

/** Update setting's value for append {@link mode}. */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/** Update setting's value for {@link mode} = "append" */

@@ -114,8 +114,12 @@ export class UIPSelectSetting extends UIPSetting {

/** Update setting's value for append {@link mode}. */
protected updateAppend(attrValues: (string | null)[]): void {
const commonOptions = TokenListUtils.intersection(
...attrValues.map(val => TokenListUtils.split(val)), this.settingOptions);
const optionsIntersections = attrValues.map(val => TokenListUtils.intersection(this.settingOptions, TokenListUtils.split(val)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to store this.settingOptions in the variable instead of creating it on each iteration

@@ -114,8 +114,12 @@ export class UIPSelectSetting extends UIPSetting {

/** Update setting's value for append {@link mode}. */
protected updateAppend(attrValues: (string | null)[]): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically, the main problem with this method is that it's hard to understand what is going on.
Could you please try to add more comments, update variable names, and split the complex actions.

@Sisha0 Sisha0 merged commit 23f315d into main Nov 18, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Nov 18, 2021
@yadamskaya
Copy link
Collaborator

🎉 This PR is included in version 1.0.0-beta.9 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@yadamskaya
Copy link
Collaborator

🎉 This PR is included in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@ala-n ala-n deleted the bugfix/select-empty-option branch September 21, 2023 10:43
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants