Polling#
Demo#
Count:
Explanation#
<div
data-signals-count="0"
data-on-interval__duration.1s.leading="@get('/endpoint')"
>
Count: <span data-text="$count"></span>
</div>
You can use the data-on-interval
attribute to execute an expression at a regular interval. In this example, we are sending a get
request to the backend that increments the $count
signal every 1 second. Adding .leading
to the __duration
modifier executes the first interval immediately.
An alternative approach is use the data-on-load
attribute with the __delay
modifier to control the polling frequency from the backend. Using this method, you can control back-pressure.
<div
data-signals-count="0"
data-on-load__delay.1s="@get('/endpoint')"
>
Count: 0
</div>
The backend endpoint can merge the same fragment but with a different delay value to determine the polling frequency.