Comments (9)
Wait, it turns out WebIDL has overloading. Good, then we should simply be able to define it like this:
// Set badge to "flag".
static void set();
// Set badge to a number, optionally giving an options dictionary.
static void set([EnforceRange] unsigned long long contents,
optional BadgeOptions options);
// Set badge to "flag", with an options dictionary.
static void set(BadgeOptions options);
But we have to read this very carefully to see how the type matching would work. Thanks @g-ortuno .
from badging.
Note: When we've made the changes in #55 this will no longer be relevant.
from badging.
FWIW
set(optional unsigned long long contents, optional BageOptions options);
seems to work in Chromium
As to style, I think you're right, we should talk to the TAG folks.
from badging.
In bluetooth we do:
typedef (DOMString or unsigned long) BluetoothServiceUUID;
getPrimaryServices(optional BluetoothServiceUUID);
Couldn't you do something similar?
typedef (unsigned long long or BadgeOptions) SetParam;
set(optional SetParam);
from badging.
There might be a way to avoid the typedef
depending on how we parse the IDL.
from badging.
FWIW
set(optional unsigned long long contents, optional BageOptions options);
seems to work in Chromium
It compiles but it doesn't work as intended.
Uncaught TypeError: Failed to execute 'set' on 'ExperimentalBadge': Value is not of type 'unsigned long long'.
Both parameters are optional (as in, you can pass 0 arguments), but if you do pass one, it always goes to the contents parameter. I assume this is correct according to WebIDL (it would be a bit crazy to expect this to automatically decide which parameter to fill based on the type).
from badging.
@g-ortuno Yes, you can certainly have an "or" as a parameter (and the typedef is not required). But it's more complex than simply allowing one of two types in the first parameter slot, since you also need to prevent the dictionary from being passed as the first and second parameter. The closest approximation is:
static void set(optional (([EnforceRange] unsigned long long) or BadgeOptions) contentsOrOptions,
optional BadgeOptions options);
Statically, this would allow:
set()
set(num)
set({scope: url})
set(num, {scope: url})
set({scope: url1}, {scope: url2})
And then we need code inside the method to throw an error if contentsOrOptions is an object and options is supplied. It can be done, but it's a bit messy.
from badging.
Interesting, on the alternative approach where we ask for an explicit value in the first argument position, I think undefined
should "just work":
Badge.set(undefined, {scope: url});
Based on a cursory reading of the (admittedly very long) JS-to-IDL overload resolution algorithm (which is the algorithm responsible for converting a JS argument list into WebIDL types), undefined
should just select the default value when passed to an optional parameter, so the above should set a flag badge with a scope. But it doesn't work. Same as above:
Uncaught TypeError: Failed to execute 'set' on 'ExperimentalBadge': Value is not of type 'unsigned long long'.
This might be a bug in Chrome's IDL parser? (Edit: Filed bug on Chrome.)
Badge.set(undefined)
sets a flag badge, but Badge.set(undefined, {scope: url})
gives a TypeError converting undefined
to a long long
, so ... maybe there's a bug in Chrome's overload resolution algorithm.
Nevertheless, I would prefer to allow you to pass the dictionary to the first parameter if that's possible.
from badging.
Scope has been removed.
from badging.
Related Issues (20)
- Feature: Get current badge value HOT 2
- Publish FWPD? HOT 9
- Not working on PWA HOT 3
- Would the browser icon also show a badge for "badged tabs"? HOT 2
- TPAC planning and specification status report HOT 1
- Hide the badge or setting count to 0 HOT 6
- Has anything changed with the badge API? HOT 2
- Does this extend to badges in extensions? HOT 6
- What's the status with Badge API for iOS? HOT 6
- App badging supposed to work while PWA is not open? HOT 2
- [Browsers Extensions]: Silent Badge updates should be supported in browser extensions
- badging without installing pwa HOT 2
- Android support, at least HOT 4
- TPAC 2022 status report
- Broken references in Badging API
- Deal with non-fully active documents HOT 2
- Should third-parties be allowed to use the API? HOT 2
- Disassociate badging from manifest
- Selectively exposing the API could be a fingerprinting vector HOT 3
- A means to associate a badge with an installed application HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from badging.