MishkaGervaz.Table.Web.Renderer (MishkaGervaz v0.0.6)

Copy Markdown View Source

Bridge between LiveComponent and Templates.

This module is a thin orchestrator that:

  • Selects the appropriate template based on state
  • Prepares minimal assigns for the template
  • Delegates rendering to the template

Architecture

LiveComponent → Renderer (bridge) → Template → Shared (components)

Performance Optimization

Renderer passes two key assigns to templates:

  • @static - Same reference always, LiveView skips re-render (O(1) comparison)
  • @state - Changes trigger re-render only for parts using dynamic fields

Templates should use:

  • @static.* for columns, filters, ui_adapter, etc. (no re-render on user interaction)
  • @state.* for page, filter_values, selected_ids, etc. (re-renders when changed)

See MishkaGervaz.Table.Web.Live, MishkaGervaz.Table.Web.State, MishkaGervaz.Table.Templates.Table, MishkaGervaz.Table.Behaviours.Template.

Summary

Functions

Whether the table has nothing to draw yet.

Whether the view is a page past the table's last one: the load that opened page N, past page 1, read no rows, as ?<prefix>_page=999 or a stale link opens it on a numbered or a Load more table.

Renders the table through the template currently in effect.

Functions

first_read_out?(state)

@spec first_read_out?(MishkaGervaz.Table.Web.State.t()) :: boolean()

Whether the table has nothing to draw yet.

True from the component's first render until the first read comes back, and again while a read runs after a first read that failed. Once a read has succeeded it is never true again — a later page, filter or sort keeps the rows on screen and marks them stale instead.

past_last_page?(state)

@spec past_last_page?(MishkaGervaz.Table.Web.State.t()) :: boolean()

Whether the view is a page past the table's last one: the load that opened page N, past page 1, read no rows, as ?<prefix>_page=999 or a stale link opens it on a numbered or a Load more table.

The renderer then passes @empty? true, and the default empty state says the page has no rows and offers a button back to page 1 in place of the table's own empty message.

render(assigns)

@spec render(map()) :: Phoenix.LiveView.Rendered.t()

Renders the table through the template currently in effect.

Until the first read returns, the template's MishkaGervaz.Table.Behaviours.Template.render_loading/1 is drawn instead of its render/1. After that, render/1 is passed @static, @state, the @stream for the resource's stream name, an @empty? flag and a @failed? flag. @empty? is true when the table holds no rows, or when the view is a page past its last one (past_last_page?/1). @failed? is true when no read has succeeded and the last one failed: the table has no rows to show, so the template draws its MishkaGervaz.Table.Behaviours.Template.render_error/1 in their place.