自动合并
Autommerge 是用于构建协作的数据结构库 应用程序,此软件包是 javascript 执行 .
详细文件见 自动合并.org 但请看下面的简短的开始guid.
快速启动
首先,安装库.
npm install @automerge/automerge
如果你正在写一个 node 应用程序,您可以直接跳转到 来点吧
数据。如果你在浏览器中,你需要一个捆绑器
Bundler 设置
@automerge/automerge 是一个围绕一个核心库的包装器,它被写入
生锈后编译为WebAssembly,并作为单独的套件分发,称为
@automerge/automerge-wasm。浏览器目前不支持 WebAssembly
模块参与无害环境管理模块的导入,所以您必须使用捆绑器来导入
@automerge/automerge 在浏览器中。 外面有很多混混,我们
在 examples 文件夹。 这是短篇
使用 Webpack 5 的示例.
假设新网络包项目的标准设置,则需要启用
asyncWebAssembly 实验 在典型的网络包装项目中
像这样的东西 webpack.config.js
module.exports = {
...
experiments: { asyncWebAssembly: true },
performance: { // we dont want the wasm blob to generate warnings
hints: false,
maxEntrypointSize: 512000,
maxAssetSize: 512000
}
};
制作一些数据
自动合并允许将执行的线程分开来修改一些数据 并永远能够 合并他们的改变后.
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 },
],
})
发展
见 开机了
元数据
版权2017–现在,自发贡献. 根据《任择议定书》的规定释放
麻省理工学院许可证(见 LICENSE) (中文(简体) ).