pagy icon indicating copy to clipboard operation
pagy copied to clipboard

Docs: Update AJAX doc

Open ddnexus opened this issue 3 years ago • 6 comments

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.

ddnexus avatar Feb 22 '23 09:02 ddnexus

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_nav helper.
  • user clicks on page 2.
  • new records are fetched and the nav_js is 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_js helper is re-initialized.

Pls confirm whether this is incorrect (or correct)?

benkoshy avatar Feb 25 '23 08:02 benkoshy

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.

ddnexus avatar Feb 26 '23 02:02 ddnexus

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.

ddnexus avatar Feb 26 '23 05:02 ddnexus

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.

benkoshy avatar Feb 26 '23 21:02 benkoshy

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.)

anitagraham avatar Apr 03 '23 02:04 anitagraham

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

ddnexus avatar Apr 03 '23 09:04 ddnexus