Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Add option to run $timeout as an requestAnimationFrame callback #4278

Closed
@cburgdorf

Description

@cburgdorf

I think it's been claimed by a bunch of smart folks that you should avoid using setTimeout at all costs and replace it with requestAnimationFrame.

Even if you know that you want to run some code in 1000ms it's still smarter to schedule the code with setTimeout but then call requestAnimationFrame to actually do the work. At least if your work is rendering related.

To let code speak, this:

setTimeout(function(){
    requestAnimationFrame(function(){
        doWork();
    });
},1000);

So in terms of Angular this could look like this:

//I would advise changing the last parameter to be an option object 
//because currently it's used for invokeApply
$timeout(doWork, 1000, { invokeApply: false, requestAnimationFrame: true});

I wonder if you guys agree that it makes sense to have it baked into the framework. After all, it's just a couple of lines of code for the framework that makes life easier for the developer because it takes care of $apply and returning you a promise etc.

If you think it's a good idea, I'll craft a PR for it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions