Coder Social home page Coder Social logo

react-async-poll's People

Contributors

deepakjois avatar mxstbr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-async-poll's Issues

slow down/stop polling when window is not visible

To reduce load on the system being polled (and the ones doing the polling), it'd be great to be able to slow down/stop polling while the window is not visible.

This should be feasible using the Page Visibility API which is now implemented in modern browsers.

Suggested changes:

  1. asyncPoll now takes a third argument: asyncPoll(intervalDuration, component, hiddenIntervalDuration) where hiddenIntervalDuration is the duration to use when document.visibilityState is hidden.
  2. the tricky part is how to behave when document.visibilityState changes. The important edge case here is that if the page is hidden and we have a slow timeout, but then the page becomes visible, we should either poll immediately or wait a little longer and then poll. The airtight way to do this would include storing a this.lastPolled timestamp, so that when document.visibilityState changes, we can set a timeout with the remaining interval according to the currently correct intervalDuration. In some cases (if we switched from a slower interval to a faster interval, and the faster interval says we should have already polled) the new timeout would fire immediately after which we'd settle back in to the regular setInterval situation.

There could also be a simpler approach to this, where whenever document.visibilityState changes, we simply poll right then and then carry on with the appropriate interval.

Stop polling make unable to restart it

When you want to stop polling and call the "stopPolling" method, your cannot restart it.
The issue comes up because the "interval" property isn't set to undefined (line 29)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.