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

Re: The need to re-subscribe to requestAnimationFrame

From: Jonas Sicking <jonas@sicking.cc>
Date: Fri, 8 Mar 2013 10:43:03 -0800
Message-ID: <CA+c2ei_0U2Nz9DQteiZDY9KPAWiPhAvd8XRyRX9qpWo2CPOFEw@mail.gmail.com>
To: Florian Bösch <pyalot@gmail.com>
Cc: David Bruant <bruant.d@gmail.com>, Glenn Maynard <glenn@zewt.org>, Webapps WG <public-webapps@w3.org>
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:43:35 GMT

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