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

Remove duplicated options from radio #230

Merged
merged 5 commits into from
Apr 17, 2019

Conversation

Girbons
Copy link
Contributor

@Girbons Girbons commented Apr 16, 2019

it should fix #213

Copy link
Member

@andydotxyz andydotxyz left a comment

Choose a reason for hiding this comment

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

Great fix thanks, but I think there are some corners for improvement.

func TestRadio_DuplicatedOptions(t *testing.T) {
radio := NewRadio([]string{"Hi", "Hi", "Hi", "Another", "Another"}, nil)

Refresh(radio)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we should rely on this refresh call - there has been no specific change to a field so the developer would not know it is required. Perhaps the deduplication needs to be called from the constructor function as well?


assert.Equal(t, 2, len(radio.Options))
assert.Equal(t, 2, len(Renderer(radio).(*radioRenderer).items))
}
Copy link
Member

Choose a reason for hiding this comment

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

Can you also test what happens if Append is called()?

widget/radio.go Outdated
@@ -20,6 +20,20 @@ type radioRenderer struct {
radio *Radio
}

func removeDuplicatedOptions(options []string) []string {
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure about the naming here. This function takes in, and returns, a slice of strings - it does not really know what "options" are...
Perhaps it should be a function on the radio type? (and then it would not need the input/output variables)?
Of perhaps it should have a name that represents it's generic nature such as "removeDuplicateStrings".
This function is currently available to the whole widget package - this may be a good thing as perhaps CheckBox should have the same filter?

I will leave the solution up to you - or chat on Slack :)

widget/radio.go Outdated
found := make(map[string]bool)

for _, option := range options {
if _, check := found[option]; !check {

Choose a reason for hiding this comment

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

This is more idiomatically if _, ok := found[option]; !ok { (unless "check" has some domain specific meaning)
Also suggesting the function name func dedupe([]string) []string

@Girbons Girbons force-pushed the radio-options-same-text branch from 5e99b34 to 9f31463 Compare April 17, 2019 09:02
andydotxyz
andydotxyz previously approved these changes Apr 17, 2019
@andydotxyz andydotxyz merged commit 37e6e76 into fyne-io:master Apr 17, 2019
@Girbons Girbons deleted the radio-options-same-text branch April 18, 2019 06:54
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.

Two radio options with same text
3 participants