-
Notifications
You must be signed in to change notification settings - Fork 12
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
Explore removing clear() and possibly change set method? #19
Comments
I typed up a doc yesterday here. (This doc is not meant to circumvent the issue tracker discussions, but summarize them — thanks for filing a separate issue.) To paste what I said there: as I see it there are a number of options:
This isn't just about removing |
Thanks. I vote for the second one! Based on your latest change in #20. It would be great if we could just do: function showPlayerTurn(playerTurnId) {
Badge.set(playerTurnId === localPlayerId);
} instead of function showPlayerTurn(playerTurnId) {
if (playerTurnId === localPlayerId) {
Badge.set();
} else {
Badge.clear();
} |
I'd prefer avoiding overloads; in an untyped language they hurt more than they help. For example, with an integer-boolean overload, you could have I'd propose something like:
|
Yeah I agree with your sentiments @domenic about overloading the set with a boolean, but it seemed that others favored simple overloads. I do like having Your |
I'm kind of partial to option one, where we have a It avoids the overloading concern @domenic raised, and the result of: Badge.set(7); // 7
Badge.clear(); // Clear
Badge.set(): // A bit weird, but Flag is more obvious to me than Badge.setNumber(7); // 7
Badge.toggle(); // Clear? Flag?
Badge.toggle(); // 7? Flag? Clear?
// Explicitly setting flag is better
Badge.setNumber(7); // 7
Badge.toggle(false); // Clear
Badge.toggle(true); // Not sure if toggling restores the last value? 7? Flag? I also think that using That said, I don't feel that strongly about this. I'm sympathetic to @mkay581's argument for overloading set, and agree that coercion has always been a confusing part of JS, so I could be convinced for option 1), 2) or 3) (not 4)). In the interests of deciding something, I'm thinking we pick 1), unless anyone has any significant objections? |
The only issue with that approach is that it leads to code such as Badge[hasMessages ? "set" : "clear"](); instead of Badge.toggle(hasMessages); But I can understand
and, if we want to avoid overloading, I think this is probably the better path. So I am OK with 1). |
The proposal states:
The proposal around the
clear()
method seems a bit unclear here 😄 . Is there any particular reason to have aclear()
method? Wouldn'tset(undefined)
,set(null)
, orset()
all clear the badge count and hide it? Or isclear()
meant to serve some other purpose? Maybe clear the count, but still show the badge (without a number)?The text was updated successfully, but these errors were encountered: