Docs: Update AJAX doc
Consider updating AJAX for the modern day tooling - nobody uses .js.erb anymore - Turbo Streams (and Stimulus JS) are what they use, and it serves much the same purpose.
Supporting Code?
Most people who AJAX Render would need to re-initialize Javascript - somehow: an efficient way of solving this problem is via Stimulus Controllers - which allows for javascript to be initialized as soon as it hits the DOM. We have already alluded to this here: https://ddnexus.github.io/pagy/docs/api/javascript/setup/#stimulus-js
- Does it make sense to add this code to the pagy library?
- Or should we merely document it?
- Or should we produce an installer to dump it in the appropriate directory?
- I imagine it would need very little support, given there are almost zero moving parts. But it will still be there.
AJAX rendering
I feel like i'm not quite understanding the purpose of this AJAX section.
- user has a
js_navhelper. - user clicks on page 2.
- new records are fetched and the
nav_jsis re-rendered in the same controller action (or are pages rendered in one action, and the pagination component rendered in a different action)? - the
nav_jshelper is re-initialized.
Pls confirm whether this is incorrect (or correct)?
Does it make sense to add this code to the pagy library?
Nope. Too many different ways that may be popular just for a few months, depending on the last trend. It's already difficult to keep up with the doc.
Pls confirm whether this is incorrect (or correct)?
The click on page 2 requests the same action, unless you use :request_path. BTW, the url is specifically generated by the pagy_url_for method.
As a general policy, we want to make customization always possible. Hopefully also easy.
When it's already easy - as in the javascript case - we can avoid adding (bloating) more code base, that will need more testing and maintenance without any real need.
The click on page 2 requests the same action, unless you use :request_path. BTW, the url is specifically generated by the pagy_url_for method.
Turbo drive works via AJAX, which most Rails folks use by default. Turbo stream / Frames targets specific dom elements, and renders .js.erb obsolete, so all that really needs to be done is to re-initialize the js helper.
This issue and #451 could probably be addressed the same. i will ponder on how to structure it.
I'd agree @ddnexus - many/most is not all. Different products come and go, and having a documented way to achieve the result without a framework is useful. (Also note that the doc does use jQuery, so it the reader may need to translate to vanilla JS.)
Also note that the doc does use jQuery, so it the reader may need to translate to vanilla JS.
@anitagraham good point @benkoshy that could be addressed very quickly and would be a good start