Remote / foldkit-remote/outbox

outbox

function · packages/remote/src/outbox.ts:111

function outbox<AppModel>(
  domain: OutboxDomain<AppModel>,
  options: OutboxOptions<AppModel>,
): OutboxWiring<AppModel>

Keeps a domain's durable writes (mutate's durable) across a reload and sends them, as a wiring beside Data.wiring: the queue is written to key before a write is sent, sent oldest first by one tab (a Web Lock), sent again after a failure that nothing answered with a backoff, and read back by every tab. Start init from its restore, or a page resumed from a server render from its session. A change of principal should forget in update, and name another key. Each write is sent naming whom the server last said it answered as when it was queued, and the server runs it for no one else: one made for someone other than whom an answer names is held (OutboxHeld), and a visitor's is stamped as, and moved to the queue of, whoever signs in first (OutboxMoved, #405). Whom the page heard is saved with the queue, for a reload.