Sync / foldkit-sync

The model in one equation

what the user sees = committed snapshot + pending local edits, replayed

The server has committed A B C; this device has typed D E since:

server:    A  B  C
pending:            D  E
visible:   replay(A, B, C, D, E)

Another device gets X in before D reaches the server. After the next exchange:

server:    A  B  C  X
pending:               D  E
visible:   replay(A, B, C, X, D, E)

D and E never waited. The base moved underneath them and they were replayed on top. That one move, rebase, is also how a rejection rolls back: drop the rejected edit from pending and replay the rest.

An edit passes three milestones, and each means something different:

MilestoneWhereWhat it proves
visiblethe Model, at oncenothing yet: the user saw it
savedthe local outboxa reload or a dropped connection cannot lose it
committedthe server journalevery other device will see it in this order

A UI that says "saved" should read the second, and one that says "shared" the third. Both are observable; see what to show the user.

Install

bash
pnpm add foldkit-sync

foldkit and effect are peer dependencies; foldkit-surface comes with the package. The browser storage is IndexedDB. The server needs foldkit-durable or your own implementation of the exchange.