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

Spread list props to suggestion #17001

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions awesomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ function Suggestion(data) {
? { label: data[0], value: data[1] }
: typeof data === "object" && "label" in data && "value" in data ? data : { label: data, value: data };

Choose a reason for hiding this comment

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

  • As @vlazar mentioned, you don't need this unless data is an object. Since there is another check about whether this is the case, we should convert it to a proper block if and do it in there.
Suggested change
: typeof data === "object" && "label" in data && "value" in data ? data : { label: data, value: data };
if (Array.isArray(data)) {
o = { label: data[0], value: data[1] }
} else if (typeof data === "object") {
for (var property in data) {
this[property] = data[property];
}
} else if (typeof data === "object" && !("label" in data && "value" in data)) {
o = { label: data, value: data }
}


for (var attr in data) { this[attr] = data[attr]; }

Choose a reason for hiding this comment

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

  • Please follow the style of the rest of the code, with blocks being on separate lines even if they only have one line.
  • Please rename attr to prop or (better) property. These are not attributes, they are properties. Attributes can be confused with HTML attributes.
Suggested change
for (var attr in data) { this[attr] = data[attr]; }
if (typeof data === "object") {
for (var property in data) {
this[property] = data[property];
}
}


this.label = o.label || o.value;
this.value = o.value;
}
Expand Down