DEV Community

Discussion on: How to Stop requestAnimationFrame in Vuejs / Javascript

Collapse
 
timkor profile image
Timkor

Just curious: what situations require cancelling a requested animation on destroy just a few milliseconds after creation?

I don't get it.

Collapse
 
coolgoose profile image
Alexandru Bucur

I don't understand what you mean unfortunately.

Destroy is the vue method for when the component isn't active on the page. And we are just doing cleanup, it's not a few milliseconds after.

Collapse
 
timkor profile image
Timkor • Edited

No exactly. You are now cancelling an on create requested animation frame on destroy. But the animation frame will pretty much all the times already being fired.

I was just wondering if you could provide a scenario where a Vue component is created and deleted within a few milliseconds.

Thread Thread
 
elliott_regan profile image
Elliott Regan • Edited

The benefit could be when this.fancyFunctionHere kicks off a recursive loop, like an animation.

fancyFunctionHere() {
    this.id = requestAnimationFrame(this.fancyFunctionHere);
}