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

feat: add HasInputValue interface #3524

Closed
wants to merge 3 commits into from
Closed

Conversation

yuriy-fix
Copy link
Contributor

@yuriy-fix yuriy-fix commented Jul 28, 2022

Introduces HasInputValue which can be implemented by a component to get the populated state of the internal input's value.

Requires vaadin/web-components#4276

Related to vaadin/platform#3066

@vaadin vaadin deleted a comment from vaadin-bot Jul 28, 2022
@yuriy-fix yuriy-fix marked this pull request as ready for review July 28, 2022 07:35
* <code>false</code> otherwise
*/
@Synchronize(property = "_hasInputValue", value = "has-input-value-changed")
default boolean isInputValuePopulated() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be also renamed to align with the property name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to isInputValue 👌

@sonarcloud
Copy link

sonarcloud bot commented Jul 29, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

* <code>false</code> otherwise
*/
@Synchronize(property = "_hasInputValue", value = "has-input-value-changed")
default boolean isInputValue() {
Copy link
Contributor

Choose a reason for hiding this comment

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

The name feels a bit odd to read, IMO. Could we change it to hasInputValue?

Suggested change
default boolean isInputValue() {
default boolean hasInputValue() {

*
* @author Vaadin Ltd
*/
public interface HasInputValue extends HasElement {
Copy link
Contributor

@knoobie knoobie Jul 29, 2022

Choose a reason for hiding this comment

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

I'm normally a big fan of interfaces and re-usability but I have the feeling that this (as stated in the web component) is a private API and should not be exposed as public methods and therefore not be an interface, instead I would suggest to add this method inside all components as protected or package (private) API so that flow users aren't bothered with it.

The name hasInputValue or isInputValue is so generic that a lot of people probably going to use it just to check if there is something inside the field, expecting that setValue("something") changes it to true even tho the web component states "input element has a non-empty value entered by the user".

Copy link
Contributor Author

@yuriy-fix yuriy-fix Jul 29, 2022

Choose a reason for hiding this comment

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

I have had similar fears.

Hoped that not having specified parameter type (unlike HasValue), documentation mentioned that it's Intended for internal use and not having a setter would discourage users from using this interface instead of the proper one. Initial naming was isInputValuePopulated which is probably more descriptive name in terms of what it is returning.

However, I would agree that it still would be available for the users and somebody could probably use it by mistake.
I do appreciate your feedback as an actual user of our product! 🙇 I will change the approach in the PR in order to avoid confusions.

Copy link
Contributor

@knoobie knoobie Jul 30, 2022

Choose a reason for hiding this comment

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

I would argue that for most people any Java API is public that they can access, even tho there is Javadocs stating otherwise (which most people probably don't read)

Like people typing "textField.value" in their IDE and use the first method that pop ups and works.. with this in mind moving this somewhere else sounds the best to reduce public API cluttering and improve DX.

Another option could be to rename it so something totally technical like "isWebComponentPopulatedByUser" which sounds so obscure that probably less people are going to find (without input or value in it's name) and even use it.. but it perfectly describes it's meaning ;) But that feels like a way of "improved DX by obscurity" 😅

Edit: here is a perfect example why javadoc is "bad" from the weekend vaadin/flow#14240 (comment)

@yuriy-fix
Copy link
Contributor Author

Closing in favour of introducing private methods in individual components. Example: #3550

@yuriy-fix yuriy-fix closed this Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants