dyo / dyo

Dyo is a JavaScript library for building user interfaces.

Home Page:https://dyo.js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

why use rAF of useEffect but not setTimeout

yisar opened this issue · comments

In fact, useEffect will run until after-paint, but requestAnimationFrame will ru你before it, so can you tell me why use requestAnimationFrame ? where is the better than setTimeout?
Thank you very much.

useEffect will happen after layout but before paint in dyo, this can change in the future: I think React uses requestionAnimationFrame and postMessage*, what did you opt to use in fre?

I use Message Channel in fre, which is equivalent to setTimeout, but it does not waste at least 4ms of time.
here

As far as I know, requestAnimationFrame will be paused when running in background tabs,
but I don't know weather it is a drawback or not.

If you want to execute after "paint" wouldn't you still need to invoke the Message Channel within a requestAnimationFrame?

@thysultan https://github.com/yisar/fre/blob/master/src/scheduler.js#L56

I have modified it. Now it uses the requestAnimationFrame, too.
But I don't have a good reason. It's probably the closest to react. What do you think?

I was thinking more along the lines of:

requestAnimationFrame(() => port2.postMessage(null))

@thysultan #124 From this issue, using the requestanimationframe is just fine.

To be honest, I'm not sure when the effect will be execute. Maybe we need a good summary.