2.2.8 • Published 9 months ago

@automerge/automerge v2.2.8

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Automerge

Automerge is a library of data structures for building collaborative applications, this package is the javascript implementation.

Detailed documentation is available at automerge.org but see the following for a short getting started guid.

Quickstart

First, install the library.

yarn add @automerge/automerge

If you're writing a node application, you can skip straight to Make some data. If you're in a browser you need a bundler

Bundler setup

@automerge/automerge is a wrapper around a core library which is written in rust, compiled to WebAssembly and distributed as a separate package called @automerge/automerge-wasm. Browsers don't currently support WebAssembly modules taking part in ESM module imports, so you must use a bundler to import @automerge/automerge in the browser. There are a lot of bundlers out there, we have examples for common bundlers in the examples folder. Here is a short example using Webpack 5.

Assuming a standard setup of a new webpack project, you'll need to enable the asyncWebAssembly experiment. In a typical webpack project that means adding something like this to webpack.config.js

module.exports = {
  ...
  experiments: { asyncWebAssembly: true },
  performance: {       // we dont want the wasm blob to generate warnings
     hints: false,
     maxEntrypointSize: 512000,
     maxAssetSize: 512000
  }
};

Make some data

Automerge allows to separate threads of execution to make changes to some data and always be able to merge their changes later.

import * as automerge from "@automerge/automerge"
import * as assert from "assert"

let doc1 = automerge.from({
  tasks: [
    { description: "feed fish", done: false },
    { description: "water plants", done: false },
  ],
})

// Create a new thread of execution
let doc2 = automerge.clone(doc1)

// Now we concurrently make changes to doc1 and doc2

// Complete a task in doc2
doc2 = automerge.change(doc2, d => {
  d.tasks[0].done = true
})

// Add a task in doc1
doc1 = automerge.change(doc1, d => {
  d.tasks.push({
    description: "water fish",
    done: false,
  })
})

// Merge changes from both docs
doc1 = automerge.merge(doc1, doc2)
doc2 = automerge.merge(doc2, doc1)

// Both docs are merged and identical
assert.deepEqual(doc1, {
  tasks: [
    { description: "feed fish", done: true },
    { description: "water plants", done: false },
    { description: "water fish", done: false },
  ],
})

assert.deepEqual(doc2, {
  tasks: [
    { description: "feed fish", done: true },
    { description: "water plants", done: false },
    { description: "water fish", done: false },
  ],
})

Development

See HACKING.md

Meta

Copyright 2017–present, the Automerge contributors. Released under the terms of the MIT license (see LICENSE).

2.2.9-alpha.2

10 months ago

2.2.3-alpha.0

1 year ago

2.2.3

1 year ago

2.2.5

12 months ago

2.2.4

1 year ago

2.2.7

12 months ago

2.2.6

12 months ago

2.2.6-alpha.1

12 months ago

2.2.8

12 months ago

2.2.9-alpha.1

11 months ago

2.2.2

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

2.2.0-rc.2

1 year ago

2.2.0-rc1

1 year ago

2.1.12

1 year ago

2.1.13

1 year ago

2.1.11

1 year ago

2.1.10

2 years ago

2.1.10-alpha.1

2 years ago

2.1.9

2 years ago

2.1.8

2 years ago

2.1.8-alpha.2

2 years ago

2.1.8-alpha.1

2 years ago

2.1.7

2 years ago

2.1.6

2 years ago

2.1.0-alpha.10

2 years ago

2.1.0-alpha.12

2 years ago

2.1.0-alpha.11

2 years ago

2.1.0-alpha.13

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.5

2 years ago

2.1.0

2 years ago

2.1.2-alpha.1

2 years ago

2.1.2-alpha.0

2 years ago

2.1.0-alpha.9

2 years ago

2.1.1-alpha.0

2 years ago

2.1.0-alpha.8

2 years ago

2.1.0-alpha.7

2 years ago

2.1.0-alpha.6

2 years ago

2.1.0-alpha.5

2 years ago

2.1.0-alpha.4

2 years ago

2.1.0-alpha.3

2 years ago

2.1.0-alpha.2

2 years ago

2.0.3

2 years ago

2.1.0-alpha.1

2 years ago

2.0.2

2 years ago

2.0.2-alpha.2

2 years ago

2.0.2-alpha.1

2 years ago

2.0.1-alpha.6

2 years ago

2.0.1-alpha.3

3 years ago

2.0.1-alpha.4

3 years ago

2.0.1-alpha.5

2 years ago

2.0.1

2 years ago

2.0.0-alpha.7

3 years ago

2.0.0-alpha.5

3 years ago

2.0.1-alpha.1

3 years ago

2.0.0-alpha.6

3 years ago

2.0.1-alpha.2

3 years ago

2.0.0-beta.2

3 years ago

2.0.0-beta.1

3 years ago

2.0.0-beta.4

3 years ago

2.0.0

3 years ago

2.0.0-beta.3

3 years ago

2.0.0-alpha.4

3 years ago

2.0.0-alpha.3

3 years ago

2.0.0-alpha.2

3 years ago

2.0.0-alpha.1

3 years ago