Sync / foldkit-sync
The model in one equation
what the user sees = committed snapshot + pending local edits, replayedThe 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:
| Milestone | Where | What it proves |
|---|---|---|
| visible | the Model, at once | nothing yet: the user saw it |
| saved | the local outbox | a reload or a dropped connection cannot lose it |
| committed | the server journal | every 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
pnpm add foldkit-syncfoldkit 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.