-
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
Make setXXXBadge(undefined) set flag instead of clearing #60
Comments
Note: You can also write it like this, which is mildly cleaner: function wrapBadgeSet(...args) {
return navigator.setAppBadge(...args);
} But in general, I agree. |
I think we may be over complicating it. Calling |
Updated the bug report with @fallaciousreasoning's simpler method. |
You seem to be suggesting a fundamentally different API surface than the one we have specced and implemented. Currently:
You're suggesting that passing 0 sets it to something else? (Possibly the number value 0 which is currently not allowed?) And that there be a different method to set the badge to "flag"? Can we not redesign it? (This was litigated in #19 and we came to the soft consensus of the current design.) What I'm proposing here is a very small change to make undefined and null set the badge to "flag" rather than clearing the badge. |
I'm suggesting it throws.
...
Yes... flag is
This feels like we are trying to change type coercion in WebIDL. I don't think we should do that. We could support it explicitly for /null/, by making it nullable... but again, i'm worried about fiddling with coercion WebIDL/JS coercion rules. |
Sorry for no reply on here. I'm still not really getting what you're proposing (if anything) that we change, unless you just mean that 0 should throw (which is a separate issue to what
I understand the concern. We don't want to "go against the grain" of WebIDL / how the web usually works. But we also don't want a "surprising" API, so we have to be careful. Firstly:
So what I am trying to do here (make Having said that, I'm reading WebIDL now and I think actually this should already be working the way I want (no changes to the spec required). That means we possibly we have an implementation bug in Chrome. The §3.5 Overload resolution algorithm is complex and hard to digest, but the summary box below says:
That suggests that our prose algorithm should see a user-supplied Edit: Wait a minute, was I simply wrong the whole time? Chrome's test case shows that I've been thinking of adding this table to the spec (regardless of what we settle on) so it's clear at a glance what the various values set the badge to. This is my expectation of what the current behaviour should be (based on the current Badging spec and WebIDL):
The So with reference to the above table, @marcoscaceres what are you proposing we change?
So you would just change this one row?:
Why do you want to make this change? The reason we specified it as 0 = "nothing" is so that you can do this: function pollForMail() {
// ... Fetch unread mail from server. ...
// Set the document badge. If getUnreadCount() returns 0, this is
// equivalent to navigator.clearClientBadge().
navigator.setClientBadge(getUnreadCount());
} No need to write an |
I guess I don't want two ways of doing the same thing. If
I agree... so is there any use for |
Note: See my edit above. It turns out that Chrome is actually doing the right thing and this whole issue is already working. Sorry for the noise.
Good question! The reason for function showPlayerTurn(playerTurnId) {
if (playerTurnId === localPlayerId)
navigator.setClientBadge();
else
navigator.clearClientBadge();
} It would feel "silly" if we had to write that as " Perhaps even more obnoxious, you might see this: function showPlayerTurn(playerTurnId) {
navigator.setClientBadge(playerTurnId === localPlayerId ? undefined : 0);
} Which I don't want to encourage. Yes,
I believe this is why in #19 there were some proposals to have a separate "set integer" and "set Boolean" method, but those still have the same issue where "set integer 0" and "set Boolean false" produce the same outcome. So I would prefer to keep |
Since the original issue is resolved (WAI), closing this. Feel free to continue discussion about |
Ok, so yes... |
Wow, after all my angsting about this it already works 😆 |
Note: This still shows up in the spec. We should remove it @mgiuca |
Maybe this is just reopening #19 but I think it's a slightly different issue.
We noticed it was quite difficult to write a wrapper around the Badge set methods, like this:
This fails because if
contents
is omitted in the call towrapBadgeSet
, it will passundefined
tosetAppBadge
, which has different semantics to passing no argument (specifically: passing no argument will set the badge state to flag, while passing undefined will coerce to 0 which happens to clear the badge).Instead, to wrap correctly, you must do this:
Which is non-obvious and a bit hard to read.
As a general rule, I think passing
undefined
to an argument should be the same as omitting it. So I propose that we change the IDL to include a "?
" which would make bothundefined
(andnull
, an unintended but unavoidable side effect) set it to flag, the same as omitting an argument altogether.The text was updated successfully, but these errors were encountered: