News for hackers. Stuff that matters.
Re:Netflix Likes React by svachalek on Wednesday January 28, 2015 @04:49PM (#8962766)
Actually changing the DOM has a lot of implications. Recalculating CSS, layout, possible side effects that generate events, repainting, etc, etc. It's a lot of work to go through for an intermediate state that may not even last long enough to be visible to the user. Buffering and batching those changes can save a lot of that effort. I suppose in theory the browser could optimize this as well but in practice it seems most are still optimized for rendering static pages very quickly rather than for handling rapid changes.
Re:Netflix Likes React by EGreg on Wednesday January 28, 2015 @04:55PM (#8962798)
Yes but WHY don't the browser makers optimize for what seems to be this very common use case? Why does a third party library outperform them?
Re:Netflix Likes React by mynegation on Wednesday January 28, 2015 @05:11PM (#8962879)
Because when your code changes DOM, browser does not know whether you are going to stop at it for now, or do something else, so it has to re-render. In React you explicitly request application of virtual DOM changes to real DOM once you are done.
Re:Netflix Likes React by blktiger on Wednesday January 28, 2015 @06:49PM (#8963362)
In theory they could add some new methods to the DOM api to allow for this, but it would be non-standard and currently none of the browsers have it.

Something like this maybe?

batchDomChanges(); ... dom changes here ... flushDomChanges();

Re:Netflix Likes React by yblu on Wednesday January 28, 2015 @07:54PM (#8963672)
Or use fastdom[1], which batches reads and writes to reduce layout thrashing.

[1]: https://github.com/wilsonpage/fastdom

Re:Netflix Likes React by zkhalique on Thursday January 29, 2015 @12:48AM (#8964550)
Well I thought that is why there is requestAnimationFrame.
Re:Netflix Likes React by jonathancreamer on Wednesday January 28, 2015 @05:50PM (#8963070)
Great explanation.