render_async v2.1.7 Release Notes
Release Date: 2020-08-01 // over 3 years ago-
๐ฑ ๐ New version of render_async is out! In the new version, there are a couple of new features:
- Retry render_async after some time
- Control polling by dispatching events
- Customize content_for name
๐ฑ ๐พ P.S. There is a
render_async
Discord server, please join and let's make render_async even better!๐ฑ โป๏ธ Retry render_async after some time
If you want to retry requests but with some delay in between the calls, you can pass a retry_delay option together with retry_count like so:
\<%= render\_async users\_path, retry\_count: 5, retry\_delay: 2000 %\>
0๏ธโฃ This will make render_async wait for 2 seconds before retrying after each failure. In the end, if the request is still failing after the 5th time, it will dispatch a default error event.
You can read more about this feature in the README here
โฏ๏ธ Control polling by dispatching events
You can now control polling with by dispatching these 2 events:
- 'async-stop' - this will stop polling
- 'async-start' - this will start polling.
๐ฑ > ๐ก Please note that events need to be dispatched to a render_async container.
An example of how you can do this looks like this:
\<%= render\_async wave\_render\_async\_path, container\_id: 'controllable-interval', # set container\_id so we can get it later easily interval: 3000 %\>\<button id='stop-polling'\>Stop polling\</button\>\<button id='start-polling'\>Start polling\</button\>\<script\>var container = document.getElementById('controllable-interval')var stopPolling = document.getElementById('stop-polling')var startPolling = document.getElementById('start-polling')var triggerEventOnContainer = function(eventName) {var event = new Event(eventName);container.dispatchEvent(event)}stopPolling.addEventListener('click', function() {container.innerHTML = '\<p\>Polling stopped\</p\>'triggerEventOnContainer('async-stop')})startPolling.addEventListener('click', function() {triggerEventOnContainer('async-start')})\</script\>
You can read more about it in the Controlled polling section of the README.
Customize content_for name
The content_for name may be customized by passing the
content_for_name
option torender_async
.
๐ This option is especially useful when doing nested async renders to better control the location of the injected JavaScript.For example:
\<%= render\_async comment\_stats\_path, content\_for\_name: :render\_async\_comment\_stats %\>\<%= content\_for :render\_async\_comment\_stats %\>
This explanation is also available in the README
That's all folks, catch you in the next one!
๐ฑ ๐พ P.S. There is a
render_async
Discord server, please join and let's make render_async even better!