gampleman/elm-crdt/1.0.0

Crdt.Id

The two identity types the library hands back to you.

Every replica — every independent copy of a document, such as one browser tab — has a stable ReplicaId, a string you choose (typically a random per-tab token). You pass one to Crdt.init so the library knows which replica it is editing on behalf of.

Every edit the library records is stamped with an OpId, a globally-unique operation id. You never mint these yourself, but they surface as stable handles to things inside a document: the id of an item in a Crdt.Tree, or the identity a Crdt.Cursor is pinned to. An OpId can be compared and turned into a string, which is all you need to use one as a dictionary key or to look a value up.

Replicas

type alias ReplicaId =
ReplicaId

A stable per-replica identifier. Two browser tabs, two ReplicaIds. Build one with replica.

replica : String -> ReplicaId

Build a ReplicaId from a string. Use something unique per replica — a random per-tab token, a device id, a signed-in user id.

Crdt.init (Crdt.Id.replica "alice-tab-1") schema
replicaToString : ReplicaId -> String

The underlying string of a ReplicaId, e.g. to show who made a change.

Operation ids

type alias OpId =
OpId

A globally-unique id for a single recorded operation. You get these back as handles to things inside a document (tree item ids, cursor anchors); the library mints them, you read and compare them.

opIdCounter : OpId -> Int

The counter part of an OpId.

opIdReplica : OpId -> ReplicaId

The replica that minted an OpId.

compareOpId : OpId -> OpId -> Order

A total order on OpIds — by counter, then replica as a tiebreak. Handy if you keep your own sorted structure keyed by id.

opIdToString : OpId -> String

A stable string form of an OpId, suitable as a Dict key ("3@alice").