Skip to content
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

[RFC][LiveComponent] Add options on polling feature (max/multiplier) #2448

Open
94noni opened this issue Dec 12, 2024 · 6 comments
Open

[RFC][LiveComponent] Add options on polling feature (max/multiplier) #2448

94noni opened this issue Dec 12, 2024 · 6 comments

Comments

@94noni
Copy link
Contributor

94noni commented Dec 12, 2024

Hi, I would like to know if a feature like that can be implemented (with ux live internal state/code)

If so, I would like to contribute if its accepted, any hint appreciated

https://symfony.com/bundles/ux-live-component/current/index.html#polling

<div
    {{ attributes }}
    data-poll="delay(500)|max(3)|$render"
>

as well, as this may open the way, perhaps a feature similar to messenger retry can be implemented ? (delay/max/multiplier)

Thanks,

@smnandre
Copy link
Member

Seems interesting

Could you explain a bit more the feature, like how the max value would work, what "thing" the "retry" would handle / catch, etc etc ?

@94noni
Copy link
Contributor Author

94noni commented Dec 13, 2024

for the retry its not like the case of messenger for failure, but more the same config idea but here for an element
having a component that know how it needs to be refresh (poll) at which interval (delay) and until when (max)

each new polling will increment the max value until it reaches and no more add the poll
as well as having the delay configured and the multiplier to make it exponential (recent data are refreshed more frequently than old data)

the state of such config could be saved into the payload and handled back and fort between server and client I suppose

@smnandre
Copy link
Member

I'm wondering if this should be a generic attribute, or if we should add a "ComponentWithTimerTrait" or something like this.

That sort of time manipulation is what i've been doing for the LiveMemory Timer component

<div {{ attributes.defaults({
class: 'LiveMemory-Timer' ~ (this.blinking ? ' LiveMemory-Timer--blinking' : '')
}) }}
{% if this.remainingTime > (this.warningThreshold * 1000) %}
data-poll="delay({{ this.remainingTime - (this.warningThreshold * 1000) }})|tick"
{% elseif this.remainingTime > 0 %}
data-poll="delay({{ this.remainingTime + 50 }})|tick"
{% endif %}
>

And i had in mind (before i forgot) to write about it and see if this could be improved / integrated in LiveComponent codebase

@94noni
Copy link
Contributor Author

94noni commented Dec 13, 2024

nice one, did know about such demo
i will have a look into it to get inspiration somehow
but yes this feature config can be controller on php side instead of twig side I agree

@smnandre
Copy link
Member

Right now, i'm thinking delay/multiplier/etc seems very "retry" related for now.

But the overall "time / activity" management seem something we could/should be able to improve and offer (someone on slack recently wanted it's component to refresh when user reoopen tab, i remember an issue about page with live component needed to render at specific time, etc etc)

So maybe a way could be (thinking outloud here)

  • add some JS code to handle "time" events on the browser part
  • add some helper trait to ease DX for people with custom need

On the JS part we would need to handle some activity / page event we do not listen for now (device lock, freezes, background, user away, backward forward cache, etc etc)

On the PHP side we probably specific event listeners for time... but nothing much here except some required time functions i suppose.

In your case described in this issue: you would probably just need to add a trait and implement a method to compute the "next" polling time ... or something in that spirit.

What do you think ?

@94noni
Copy link
Contributor Author

94noni commented Dec 16, 2024

I think the helper on php side would be wise and relevant (aka a trait)
in order to config this behavior in a more granular way, and give more option on that poll feature

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants