Architecture decision record · ADR-0010

Row models and block loading

DataSource<Row> is the interface of plan 5.1.

Status
Proposed
Deciders
Joe Gaudet
Created
Updated
PRD
PRD
Related
None

Context

  • Plan: sections 5.1, 5.2 and 5.5 (decisions 13, 14 and 20)
  • Packages: @ember-lattice/data, @ember-lattice/data-fetch, @ember-lattice/ember (grid)

The grid must show more rows than the client can hold. A server sorts, filters, groups and counts them. The grid then asks for the rows in view, and only these rows.

A fast scroll goes past many blocks of rows. If each block loads, the server does work that nobody sees, and old responses come after new ones.

A block of rows has a lifetime: it is not loaded, it loads, it is loaded, it is old, it loads again, or the load failed. Decision 20 says that a Switchyard machine runs such states. The same decision says that scroll and cell render never go through a machine.

The engine (@ember-lattice/core) keeps the sort, filter and group state. It sorts and filters the rows of data on the client. For a server model, the engine must keep the state and do no work on the rows.

@ember-lattice/ember cannot depend on @ember-lattice/data: the grid must also work with only a table.

Decision drivers

Not recorded in the original ADR.

Options considered

Not recorded in the original ADR.

Decision

The DataSource and the row models

DataSource<Row> is the interface of plan 5.1. Its messages are the protocol types. arrayDataSource(rows, allowList) answers each request with the protocol's evaluate, so it acts like a conforming server.

There are five row models. All of them bind to one table, and the table runs in manual mode (manualSorting, manualFiltering, manualGrouping, manualPagination).

Model Rows
loadAllRows The client model. It loads all rows into data; the engine does the rest.
InfiniteRowModel Offset blocks of blockSize rows in an LRU cache of maxBlocks blocks.
CursorRowModel Keyset blocks after the last block and before the first block, from an anchor cursor.
ServerRowModel One block cache for each group node. Group rows expand lazily. Grand total and pivot.
ViewportRowModel The rows in view only. The source pushes changes; the model applies them in place.

The grid contract

LatticeGrid takes @rowModel. The type GridRowModel in @ember-lattice/ember is structural, the same as GridTable. Its members are rowCount (null when not known), displayCount, rowAt(index), setRange(start, end), queryKey, and the optional failedAt, tree, levelAt, groupAt and toggleGroup.

  • A row model makes engine rows with constructRow, so the columns of the table read the values.
  • A row that is not loaded is a skeleton row: aria-busy="true" on the row and empty cells with data-loading. A row of a failed block has data-failed and no aria-busy.
  • aria-rowcount is the known count plus the header rows, or -1 when the count is not known.
  • With tree, the grid is a treegrid. Rows have aria-level. Group rows have aria-expanded and a toggle button in the first cell. Enter on a group row toggles it.
  • A modifier gives the model the rows in view after each render. It also reads queryKey, so a new sort or filter runs it again. The model does its work in a microtask: never during render, and once for many calls.

Blocks and the machine

BlockMachine has the states idle, loading, loaded, stale, reloading and failed. The events are load, resolve, fail, invalidate, reload, retry, cancel and cancelReload. The machine is strict: an event that is not allowed throws.

The machine runs only the load path. A subscription copies the machine state into a @tracked field of the block. Render reads the tracked rows and state fields, never the machine. The data package does not call Switchyard's configure, because that setting is for the full process.

Each load has its own AbortController. When the view moves, a block that loads outside the new range aborts, goes back to idle, and leaves the cache.

The engine state to a request

toRowsRequest(state, options) maps sorting, columnFilters, globalFilter, grouping and pagination to a RowsRequest. It sets an optional key only when it has a value, because the parser rejects a key with no value.

TanStack column filters have no op. The convention is the shape of the value:

Value Leaf
a string contains
a number, boolean eq
an array in
{ op, value? } that op
'', [], null no filter

Aggregates go out with as set to the column id. A group row then has the aggregate under the column id, and the cell of that column shows it.

Transactions

applyTransaction(tx) changes the rows that have the ids of tx.update in place. An add or a remove moves rows between offset blocks, so it makes the blocks stale: they load again and keep their old rows on screen until then. The server model applies a transaction to the node of tx.route. The cursor model adds a row at a loaded end. applyTransactionAsync(tx) applies all the transactions of one animation frame in one update. The viewport model uses it for pushed changes.

data-fetch

fetchDataSource({ url, method, headers, getRowId }) sends the request as a JSON body (POST) or as JSON in the q query parameter (GET). It passes the signal to fetch. An HTTP error, or a body without a rows array, rejects with FetchDataSourceError, and the block fails.

Consequences

  • One grid works with a table or a row model. Without @rowModel, the grid acts as before.
  • The live update gate (plan 9) passes in the test browser: the viewport model applied 2,000 updates in two seconds (1,000 a second) with 0 dropped frames out of 121.
  • Blocks that leave the view abort, so a fast scroll sends few requests that complete.
  • Vitest cannot run the decorated classes of packages/data, because the root Vitest config runs Babel only on core and virtual. The pure modules (LRU, request, batch, client, array source) have Vitest tests; the machine and the models have QUnit tests in test-app.
  • Shortcuts, each marked with shortcut: in packages/data/src:
    • The cursor model keeps every loaded block (no eviction) (cursor.ts).
    • The server model reads the base column defs once. An app setOptions that changes the columns is lost at the next pivot change (server.ts).
    • When the expanded state is true (all expanded), the server model expands only the group rows that it loaded. Rows that are not loaded collapse (server.ts).
  • Done in the M2 polish pass:
    • The server model reads the expanded groups from table.state.expanded. A group row ID has the form group:[…] (the group route as JSON).
    • A sort does not collapse the groups.
    • The Grid renders the grand total (totalRow) as a sticky .lt-footer row.
    • The Grid renders the pivot result columns. They are leaf columns under one header group for each pivot key.
  • Not done yet: tree data (the protocol has no parent key), the client worker, mutate over fetch, and highlightChanges (M7).

Confirmation

Not recorded in the original ADR.

Interview record

Each question of the interview with its answer and its source. A fact from the code or a document, a question that the author did not ask, and an assumption are rows too.

QuestionAnswerSource
Where does the text of this page come from?From the Markdown file docs/adr/0010-row-models.md at commit 4c77ac4. The text of each section is the text of the Markdown file. A section that the Markdown file does not have says so.Document: docs/adr/0010-row-models.md

Changelog

DateAuthorChange
2026-12-01Joe GaudetStatus in the Markdown file: proposed
2026-12-03Joe GaudetCommit 7ce4af2: Lattice 1.0 (#1)
2026-12-04Joe Gaudet (agent)Converted from docs/adr/0010-row-models.md to this page. The text is the text of the Markdown file.

The adr skill of skillsaw wrote this page. The HTML in this file is the source of truth. The diagrams are the Mermaid sources in it.