reflex
reflex copied to clipboard
Add on_view functions to Base Event Triggers (Intersection Observer)
on_view would be called when the element is rendered on screen. on_load would be called when the window is initially loaded/reloaded.
We already had an on_load event trigger, you can use it like app.add_page(my_page, '/my_route', on_load=MyState.fetch_data)
We already had an on_load event trigger, you can use it like
app.add_page(my_page, '/my_route', on_load=MyState.fetch_data)
Alright then, an on_element basis would (imo) fit more the current architecture, but that works,
But I feel the on_view idea still stands.
I'd like to chime in an on_focus
would also be nice to refresh background tasks when they're complete after a tab or window switch for example. Not really an issue on desktop, but for mobile it would be nice.
on_view
should be fairly simple to implement using the Intersection Observer API, which is now supported in all major browsers.
@advo-kat I created a separate issue for your request, you can track as #1314
there's a third-party library by @masenf that supports this https://github.com/masenf/reflex-intersection-observer. Will go ahead and close this issue for now