[whatwg] Proposal: createImageBitmap should return a "Promise" instead of using a callback

Silvia Pfeiffer silviapfeiffer1 at gmail.com
Wed Jul 17 14:43:41 PDT 2013


On 18 Jul 2013 07:08, "Ian Hickson" <ian at hixie.ch> wrote:
>
> On Wed, 19 Jun 2013, Justin Novosad wrote:
> >
> > I was about to launch the implementation of window.createImageBitmap in
> > Blink, and I received feedback on the blink-dev mailing list that the
> > "Promise" API is the wave of the future for asynchronous JS, and that
> > the new createImageBitmap method should use Promises.
> >
> > Current spec:
> >
http://www.whatwg.org/specs/web-apps/current-work/multipage/timers.html#images
> >
> > The proposal is to change the ImageBitmapFactories IDL to something like
> > this:
> >
> > [NoInterfaceObject]
> > interface ImageBitmapFactories {
> >   Promise createImageBitmap(ImageBitmapSource image, optional long sx,
long
> > sy, long sw, long sh);
> > };
> >
> > The value of the promise would resolve to an ImageBitmap object.
>
> Done.
>
>
> On Thu, 20 Jun 2013, Anne van Kesteren wrote:
> >
> > I think something like
> >
> > interface ImageBitmap {
> >   static Promise create(ImageBitmapSource image, optional long sx,
> > long sy, long sw, long sh);
> > };
> >
> > would be much nicer.
>
> Why?
>
>
> On Thu, 20 Jun 2013, Justin Novosad wrote:
> >
> > I agree it would be nicer, but it seems less consistent with other
> > existing APIs.
>
> Indeed.
>
>
> On Thu, 20 Jun 2013, Tab Atkins Jr. wrote:
> >
> > There's really no consistency here anyway, and the "Interface.create()"
> > idiom is pretty easy and nice.
>
> There are basically two styles:
>
>  - constructors (new Date(), new Function(), etc)
>  - factory methods on the "parent" object (document.createElement(),
>    implementation.createDocument(), context.createLinearGradient(), etc)

Do we have a strategy for moving to Promises for all sync factory methods
across the API?

I.e. are we keeping existing .createXxx() methods and adding .create() for
Promise-based API (which seems to be the way of the future?) Or are we at
the same time as introducing Promises also deprecating the existing factory
methods?

I'm asking because it seems like a big change of programming pattern and
not everyone may be ready to move on from the old one yet (read: this is
next generation technology), so would it be better to keep both interfaces
around for a while?

Silvia.

> I don't think we have anything that uses the interface.create() pattern.
> URL.createObjectURL() is the closest, and it's not a factory.
>
> The constructor pattern is obviously better where possible, but in this
> case it's not, since it has to be async (hence Promises).
>
> --
> Ian Hickson               U+1047E                )\._.,--....,'``.    fL
> http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
> Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'



More information about the whatwg mailing list