[LiveComponent] Advanced Polling Features #2965
Open
+862
−127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added support for poll lifecycle hooks and pollingDirector control in UX LiveComponent
This PR introduces the following updates to the LiveComponent polling system:
limit(n)
modifier to limit the number of poll iterations.poll:started
,poll:running
,poll:paused
,poll:stopped
, andpoll:error
.pollingDirector
API to start, stop, pause, or resume polling via JavaScript.This enhancement introduces support for limiting polling cycles using the
limit
modifier. Once the limit is reached, the polling will automatically stop.Additionally, new lifecycle hooks (
poll:started
,poll:running
,poll:paused
,poll:stopped
,poll:error
) provide full control over the polling process via JavaScript (e.g. Stimulus controllers).Developers can now track the polling
count
value to build dynamic UI components such as counters, countdown timers, or progress bars.Preview:
aaa.mp4
Basic usage
By default, polling runs the
$render
action every 2000 milliseconds (2 seconds).Available Modifiers
delay(ms)
— The delay between polls in milliseconds (default:2000
)limit(n)
— Maximum number of times to run the poll (default: unlimited)actionName
— The component action to call (default:$render
)Poll Hooks
The component emits lifecycle hooks during polling. You can listen to these using JavaScript, for example:
Handling Poll Actions (Start, Stop, Pause, Resume)
Polling can be programmatically managed using the
pollingDirector
API.This allows you to start, pause, resume, or stop polling dynamically for a given action.
Available Methods
The
pollingDirector
API exposes the following methods:component.pollingDirector.start(actionName)
— Starts polling for the given action (if previously stopped).component.pollingDirector.pause(actionName)
— Temporarily pauses polling. Can be resumed later.component.pollingDirector.resume(actionName)
— Resumes a previously paused poll.component.pollingDirector.stop(actionName)
— Stops polling entirely. Usestart()
to restart.