The Iterator (Infinite Scroll)
Sequentially traversing a massive dataset via continuous appending and triggered fetching.
<!-- The Iterator pattern is realized through Infinite Scrolling -->
<tbody id="data-matrix">
<!-- Initial rows are loaded here -->
<tr><td>Record 001</td></tr>
<tr><td>Record 002</td></tr>
<!-- The final row acts as the Iterator's "next()" trigger -->
<tr hx-get="/api/records?page=2"
hx-trigger="revealed"
hx-swap="afterend">
<td>Record 003</td>
</tr>
</tbody>
The Iterator pattern provides a way to access elements of an aggregate object sequentially without exposing its underlying representation. In a hypermedia application, this manifests as Pagination or Infinite Scrolling.
Instead of loading a massive grimoire of data all at once, the client traverses it sequentially. The final element in a batch contains an HTMX directive (hx-trigger="revealed"). When the user scrolls to this element, it automatically acts as the iterator’s next() function, calling the server for the next page and appending the new data (hx-swap="afterend"). The server ensures the new payload contains the next trigger, creating an infinite, seamless traversal of data.