Hacker News new | ask | show | jobs
by skilgarriff 3434 days ago
If you happen to use React, I built a React component that helps you manage this! :) Hopefully it helps a bit! It also reports whether or not a user is idle, such that you can reduce cpu usage during that as well.

https://github.com/Skilgarriff/react-user-focus

1 comments

i don't know anything about React, but why can't react itself try to manage this?
React is in the business of limiting its API surface, not increasing it. I think they have done a great job of it - libraries like this should exist in userland.
It seems like React could listen for visibilitychange itself to throttle its own events or virtual DOM processing. It wouldn't necessarily need to expose visibilitychange as a library API.
Because there is no sufficient magic for that. App developers have to think about when they do work, how much work they do, and if and when it should be rendered. For any rule you can give, I can give you an example of an app that would break.

In general, the mantra for people who find this tough to fix should be, "Why didn't I use MVC, what a cretin I was!"