W3C home > Mailing lists > Public > public-webapps@w3.org > January to March 2013

Re: The need to re-subscribe to requestAnimationFrame

From: Florian Bösch <pyalot@gmail.com>
Date: Fri, 8 Mar 2013 19:48:26 +0100
Message-ID: <CAOK8ODgWwRGo83O30yO0O9XJLwAcjDmbVPc-XVWiiqSwa-zYCA@mail.gmail.com>
To: Jonas Sicking <jonas@sicking.cc>
Cc: David Bruant <bruant.d@gmail.com>, Glenn Maynard <glenn@zewt.org>, Webapps WG <public-webapps@w3.org>
Btw. just as a sidenote, the document in document.requestAnimationFrame
kind of matters. If you're calling it from the document that the canvas
isn't in, then you'll get flickering. That may sound funny, but it's
actually not that far fetched and is a situation you can run into if you're
transfering a canvas to a popup window or iframe. With a requestInterval
kind of function you're pretty much screwed in that case.


On Fri, Mar 8, 2013 at 7:43 PM, Jonas Sicking <jonas@sicking.cc> wrote:

> On Mar 2, 2013 6:32 AM, "Florian Bösch" <pyalot@gmail.com> wrote:
> >
> > You can also wrap your own requestAnimationFrameInterval like so:
> >
> > var requestAnimationFrameInterval = function(callback){
> >   var runner = function(){
> >     callback();
> >     requestAnimationFrame(runner);
> >   };
> >   runner();
> > }
> >
> > This will still stop if there's an exception thrown by callback, but it
> lets you write a cleaner invocation like so:
> >
> > requestAnimationFrameInterval(function(){
> >   // do stuff
> > });
> >
> > It does not give you a way to stop that interval (except throwing an
> exception), but you can add your own if you're so inclined.
> >
> > Notably, you could not flexibly emulate requestAnimationFrame (single)
> via requestAnimationFrameInterval, so if you're gonna pick one semantic to
> implement, it's the former rather than the latter.
>
> For what it's worth, this would have been another (maybe better) way to
> address the concern that current spec tries to solve by requiring
> reregistration.
>
> I.e. we could have defined a
>
> id = requestAnimationFrameInterval(callback)
> cancelAnimationFrameInterval(id)
>
> Set of functions which automatically cancel the interval if an exception
> is thrown.
>
> That reduces the current risk that people write code that reregister at
> the top, and then has a bug further down which causes an exception to be
> thrown.
>
> / Jonas
>
> >
> >
> > On Sat, Mar 2, 2013 at 3:15 PM, Glenn Maynard <glenn@zewt.org> wrote:
> >>
> >> On Sat, Mar 2, 2013 at 5:03 AM, David Bruant <bruant.d@gmail.com>
> wrote:
> >>>
> >>> If someone wants to reuse the same function for
> requestionAnimationFrame, he/she has to go through:
> >>>     requestAnimationFrame(function f(){
> >>>         requestAnimationFrame(f);
> >>>         // do stuff
> >>>     })
> >>
> >>
> >> FYI, this pattern is cleaner, so you only have to call
> requestAnimationFrame in one place:
> >>
> >> function draw() {
> >>     // render
> >>     requestAnimationFrame(draw);
> >> }
> >> draw();
> >>
> >> --
> >> Glenn Maynard
> >>
> >
>
Received on Friday, 8 March 2013 18:48:59 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 18:49:58 GMT