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
[WIP] Add selected to choice #142
[WIP] Add selected to choice #142
Conversation
@piotrmurach just a note: It seems that an immutable entity which describes the choice (name, value, disabled etc) and a mutable entity which describes a presence of a choice in a collection (selected, maybe index etc) are separate entities, though I didn't find a good name for the latter yet they probably need to be separated. |
Apologies for the failed test, something must've been wrong while rebasing, I'll double chek |
1174faa
to
10d88f7
Compare
Yes, default help has been changed recent, therefore the test has failed after rebasing. Fixed it now. |
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.
Again I'm reluctant to lose the 'immutability' guarantee for the Choice
class. There are few ideas anyhow that I'd like to port over to the gem whether or not we go with this solution.
@@ -2,7 +2,7 @@ | |||
|
|||
module TTY | |||
class Prompt | |||
# An immutable representation of a single choice option from select menu | |||
# A representation of a single choice option from select menu |
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.
Same observation here, I do like the 'immutability' guarantee here. This is especially important when you may want to call the prompt recursively and 'loop' the choice selection.
# Scope of choices which are not disabled | ||
# | ||
# @api public | ||
def enabled | ||
reject(&:disabled?) | ||
end |
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.
This is a good addition regardless.
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.
Great, will cherry-pick this chunk too 👍
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.
Done in #144
Describe the change
Add
selected
property toChoice
Why are we doing this?
In PR #141 Piotr suggested
Benefits
It also allows to pre-select default options by passing
selected: true
option tomenu.choice
Drawbacks
Requirements
Put an X between brackets on each line if you have done the item:
[X] Tests written & passing locally?
[X] Code style checked?
[X] Rebased with
master
branch?[X] Documentation updated?