-
Notifications
You must be signed in to change notification settings - Fork 610
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
base: gh-pages
Are you sure you want to change the base?
Conversation
Thanks for your contribution! I think Array and non label/value Object cases can be skipped. No need to copy properties when Also we shouldn't probably copy all properties from objects. We inherited Suggestion object from String and re-defined some properties. Probably not all String features currently work for Suggestion, but overriding all properties on Suggestion blindly can probably lead to more potential issues. @LeaVerou cares a lot about backward API compatibility. We should not break Awesomplete API. |
@vlazar Good point. I didn't even realize Suggestion inherits from String. Perhaps a better solution then is to namespace the passed object as a prop, ie |
I was thinking about having suggestion.label
suggestion.value
suggestion.data.everythingElse Of course you can just use: suggestion.data.label
suggestion.data.value
suggestion.data.everythingElse But once introduced, this API would probably have to stay forever. Lea, what do you think? |
+1 for suggestion.data.label
suggestion.data.value
suggestion.data.whatever On Thu, Nov 10, 2016, 09:31 Vladislav Zarakovsky [email protected]
|
Any updates on this? |
@LeaVerou What do you think? |
To be clear, it's not backwards compatibility I care so much about, it's usability. Awesomplete's main use case is people using it with a list of strings. Allowing more complex use cases should NEVER complicate the simple, common case. That's how people end up with terrible APIs that are a pain to use: They design the API based on the most complicated cases they want to support, and its gets in the way of the majority of their users with simpler use cases. Good APIs make the complex possible and the simple easy, not just one of the two. That said, I can't see how this PR could break anything. Unless the properties of the object passed in happen to have the same name as string methods that are used, there shouldn't be any issue. I would have some stylistic comments though:
|
@LeaVerou How about this idea? #17001 (comment) |
Any updates on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LeaVerou if this is something still worth adding I'm happy to take it over the finish line. It fits a use-case that's coming up for me!
I think I'll need to open a new PR, but I've put comment suggestions here as well.
@@ -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 }; | |||
|
|||
for (var attr in data) { this[attr] = data[attr]; } |
There was a problem hiding this comment.
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.
for (var attr in data) { this[attr] = data[attr]; } | |
if (typeof data === "object") { | |
for (var property in data) { | |
this[property] = data[property]; | |
} | |
} |
@@ -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 }; |
There was a problem hiding this comment.
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.
: 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 } | |
} |
Spread all props of list object to Suggestions object.
Super direct way and not sure if it breaks backwards compat/works in all browsers
Adresses #16976, #16938, #16888