New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature idleDelay/delayOnVisibilityChange and stopOnVisibilityChange #23
Conversation
20ff874
to
522f03e
Compare
@gugiserman Thanks for the pull request! Is there any reason why you want to increase the interval when user leaves the tab instead of completely pausing all pollers by using |
@emmaguo I was stopping all pollers at first, but then we had the need to display the progress (%) of a progress-bar in the favicon (using favicon.js for ex). With the poller completely frozen I couldn't update the progress there. Now I can continue to display it (and take it easy on the servers as well) by increasing the delay when visibility changes. Also, if you set idleDelay to 0 it disables the poller without removing it, just preventing the request to start until the user comes back to the page. Which is also in use in my application, because for some pollers I could just disable it while idle. We were actually doing the polling thing with $interval everywhere in applications services, and then intercepting/delaying the requests using angular interceptor I built that watches page visibility. But it was just complicating things, so we found your project and I already switched all old poller services with yours. Awesome job, btw! |
@gugiserman I see! That makes total sense. Also I am so happy that you guys find this library useful! |
@gugiserman Let me know if those comments make sense to you. :-) |
@emmaguo I'll make some changes right away. I think I put I actually implemented So, I would enable both configurations and decide the priority somehow? Or throw some error because there can't be the two features enabled at the same time. Totally agree on setting default edit: the example above, about the two pollers, is actually a real scenario in one of the SPAs I'm working on edit2: I think I put |
I was thinking I do not like using |
522f03e
to
da1a9f6
Compare
@emmaguo just made the changes we talked about around If things look good, I can implement |
77eedf4
to
2c88057
Compare
@gugiserman I see you already implemented |
} | ||
}; | ||
|
||
handleDelayOnVisibilityChange(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you call handleDelayOnVisibilityChange
here? Is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I've tested in current use in my application, if you leave the tab before angular fully started, it won't catch visibilitychange
event, so you are actually idle but never triggered stopAll/delayAll. So I just check right away for document.hidden
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Ok. Then let's keep it there:)
@emmaguo yeah, got a little excited lol Missing tests, though. I don't know how to trigger visibilitychange in unit tests |
@gugiserman I'm not sure how to trigger |
@emmaguo awesome! I googled for a while and couldn't find much, but tomorrow I'll dig some more. Thanks a lot! |
with tests and updated README
2c88057
to
00ac1fe
Compare
I needed to increase the delay of some of my pollers when the user leaves the page/tab, and switch it back once visibility changes again.