Learn R Programming

automerge (version 0.3.0)

am_apply_changes: Apply changes to a document

Description

Applies a list of changes (obtained from am_get_changes()) to a document. This is useful for manually syncing changes or for applying changes received over a custom network protocol.

Usage

am_apply_changes(doc, changes)

Value

The document doc (invisibly, for chaining)

Arguments

doc

An Automerge document

changes

A list of am_change objects (from am_get_changes(), am_get_changes(), or am_change_from_bytes())

Examples

Run this code
# Create two documents
doc1 <- am_create()
doc2 <- am_create()

# Make changes in doc1
am_put(doc1, AM_ROOT, "x", 1)
am_commit(doc1)

# Get changes and apply to doc2
changes <- am_get_changes(doc1, NULL)
am_apply_changes(doc2, changes)

# Now doc2 has the same data as doc1

am_close(doc1)
am_close(doc2)

Run the code above in your browser using DataLab