@abrovink/abmedium-automerge

A graph medium

Usage no npm install needed!

<script type="module">
  import abrovinkAbmediumAutomerge from 'https://cdn.skypack.dev/@abrovink/abmedium-automerge';
</script>

README

abmedium-automerge

This package combines Abmedium with Automerge. Abmedium will handle alternative views of the content (with the help of layers). Automerge will handle the complexity around distributed editing. It will also handle serialization.

Document creation

Create a document.

let docA = document({ 0: seq(1, 2, 3), 1: sym("+"), 2: num(100), 3: num(200) });

Create an empty document.

let docB = document();

Merge documents as you do in Automerge.

docB = merge(docB, docA);

console.log("1.", docB);
// 1. {
//     '0': [ 'seq', [ 1, 2, 3 ] ],
//     '1': [ 'sym', '+' ],
//     '2': 100,
//     '3': 200
// }

Simultaneities

Let's update a document concurrently. (In a more realistic example this will of course happen in different processes.)

docA = change(docA, (doc) => {
  doc[2] = 110;
  doc[3] = 220;
});

docB = change(docB, (doc) => {
  doc[2] = 111;
});

docB = merge(docB, docA);

In the background Automerge kept track of the causality and registered a conflict: node 2 has been edited concurrently. Therefore a simultaneity has been created.

console.log("2.", docB);
// 2. {
//   '0': [ 'seq', [ 1, 2, 3 ] ],
//   '1': [ 'sym', '+' ],
//   '2': [ 'sim', [ 111, 110 ] ],
//   '3': 220
// }

Txt

The str type in Abmedium is not suitable for collaborative work on longer content. Fortunately Automerge offers a data type that is: Text.

Let's create a Text value.

let docC = document({ 0: txt("Hello!") });

It can be handled as other values in Abmedium. For example, valtype fully support it.

console.log(
  "3. ",
  treeOf(proj(docC), (value) => valtype(value, { txt: () => value.toString() }))
);
// 3. Hello!

For further information, read about Text in Automerge.

Examples

Inspect the examples directory for more examples. from-readme.js contains all the examples in this document.

Maturity Status

This package is not mature. It is not stable and will change a lot. It would be wonderful if you want to use it, but prepare for a bumpy ride. Maybe you want to contribute in that case?