nikolalsvk / render_async

render_async lets you include pages asynchronously with AJAX
https://rubygems.org/gems/render_async/
MIT License
1.08k stars 75 forks source link

Start and stop polling #78

Closed nikolalsvk closed 5 years ago

nikolalsvk commented 5 years ago

Add options to be able to start polling. Let's say you want to start polling after the user clicks a button and you emit an event "render-async-start-polling", it would be cool to do that.

Also, have render_async stop polling when you emit a certain event, e.g. "stop-polling-now".

Idea rose from this comment https://github.com/renderedtext/render_async/issues/67#issuecomment-490540519

weavermedia commented 5 years ago

Stop polling option will be great! 🎉

nikolalsvk commented 5 years ago

Hey y'all, I've released version 2.1.1 which solves this issue!

If you have time, please try it out and see if it brings any bugs with it, thanks 🍰

pivotal-pmital commented 5 years ago

@nikolalsvk I am not seeing how to use this magical feature that you are referring to in version 2.1.1. The PR that is associated with this issue is also closed. Can you help me understand how to use it? Previously I was using this gem at commit 9d9e8edce8e7ab6ba9a169ef1fe70257ca6aacba but the feature seems to be gone now. Can you help me out with this?? Thanks!

nikolalsvk commented 5 years ago

I'm really sorry about this @pivotal-pmital. I don't see the commit you've mentioned in the master commits, it never got merged actually :(

Anyways, you can start and stop polling using toggle feature of the gem. I should have made this more clear in the Polling section of the README. If you take a look at Toggle section you will see this:

Also, you can mix interval and toggle features. This way, you can turn polling on, and off by clicking the "Detail" button. In order to do this, you need to pass toggle and interval arguments to render_async call like this:

<a href='#' id='detail-button'>Detail</a>
<%= render_async comments_path, toggle: { selector: '#detail-button', event: :click }, interval: 2000 %>

TLDR

You can pass in interval option together with toggle and start and stop polling that way.