Giter Site home page Giter Site logo

Comments (9)

mgiuca avatar mgiuca commented on June 28, 2024 2

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.

fallaciousreasoning avatar fallaciousreasoning commented on June 28, 2024 1

Note: When we've made the changes in #55 this will no longer be relevant.

from badging.

fallaciousreasoning avatar fallaciousreasoning commented on June 28, 2024

FWIW

set(optional unsigned long long contents, optional BageOptions options);

seems to work in Chromium

https://cs.chromium.org/chromium/src/third_party/blink/renderer/modules/badging/experimental_badge.idl?q=f:badge.idl&sq=package:chromium&g=0&l=15.

As to style, I think you're right, we should talk to the TAG folks.

from badging.

g-ortuno avatar g-ortuno commented on June 28, 2024

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.

g-ortuno avatar g-ortuno commented on June 28, 2024

There might be a way to avoid the typedef depending on how we parse the IDL.

from badging.

mgiuca avatar mgiuca commented on June 28, 2024

FWIW

set(optional unsigned long long contents, optional BageOptions options);

seems to work in Chromium

It compiles but it doesn't work as intended.

https://crbug.com/1000968

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.

mgiuca avatar mgiuca commented on June 28, 2024

@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:

  1. set()
  2. set(num)
  3. set({scope: url})
  4. set(num, {scope: url})
  5. 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.

mgiuca avatar mgiuca commented on June 28, 2024

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.

mgiuca avatar mgiuca commented on June 28, 2024

Scope has been removed.

from badging.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.