Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'Both are online.', () => {
alice1 = Automerge.change(Automerge.init('alice'), doc => {
doc.x0y0 = 'w'
doc.x0y1 = 'w'
doc.x1y0 = 'w'
doc.x1y1 = 'w'
})
assert.deepEqual(alice1, {
_objectId: '00000000-0000-0000-0000-000000000000',
x0y0: 'w',
x0y1: 'w',
x1y0: 'w',
x1y1: 'w'
})
bob1 = Automerge.merge(Automerge.init('bob'), alice1)
assert.deepEqual(bob1, {
_objectId: '00000000-0000-0000-0000-000000000000',
x0y0: 'w',
combineFile() {
console.log("Starting the saving process...")
console.log(this.state.team);
this.setState({ hideMain: "", updateTeammateModal: "hide", teammateName: "", newUserRole: "" });
//Take loaded states and combine them into a single file
let object = Automerge.init();
object = Automerge.change(object, file => {
file.team = this.state.team;
file.integrations = this.state.integrations;
file.lastUpdated = this.state.lastUpdated;
if(this.state.updatedAccountName && this.state.updatedAccountName !== "") {
file.accountSettings = this.state.updatedAccountName;
this.setState({ accountSettings: this.state.updatedAccountName})
} else {
file.accountSettings = this.state.accountSettings;
}
file.editorView = this.state.editorView;
file.editorName = this.state.editorName;
file.editorPermissions = this.state.editorPermissions || false;
file.editorIntegrations = this.state.editorIntegrations;
file.editorPublish = this.state.editorPublish;
file.journoView = this.state.journoView;
async safeLoad() {
if (this.crdtFile.isPersisted()) {
await this.load()
} else {
this.crdt = AutoMerge.change(AutoMerge.init(), (doc: any) => {
doc.content = new AutoMerge.Text()
});
}
}
() => {
const watchableDocs = createConnectedDocs(2, 'someid')
watchableDocs[0].set(
change(
init(),
(draft: Sheet) =>
(draft.grid = [
[{ value: 'A' }, { value: 'BBB' }],
[{ value: 'CCC' }, { value: 'DDD' }],
])
)
)
return (
<div>
{watchableDocs.map((watchableDoc, n) => (
))}
</div>
)
}
if (id) {
item = await client.get(table, {
id
});
if (!item) {
return Promise.reject(new Error('Could not find item with id ' + id));
}
}
const originalChanges = parseInt((item ? item.changes : 0) || 0);
const wasDel = item ? item.isRemoved : undefined;
let doc;
if (item && item.automerge) {
doc = Automerge.load(item.automerge);
}
if (!doc) {
doc = Automerge.init();
}
doc = Automerge.change(doc, (doc: any) => {
if (item && !item.automerge) {
Object.keys(item).forEach(key => {
if (key === 'id' || key === 'rev' || key === 'rem') {
return;
}
if (item[key] !== undefined && item[key] !== null) {
doc[key] = item[key];
}
});
}
if (cb) {
cb(doc);
}
});
public static create(embeddedOutlineFile: EmbeddedCRDTFile, repository: Repository) {
const outline = AutoMerge.change(AutoMerge.init(), (doc: any) => {
doc.id = uuid()
doc.title = "Untitled"
const defaultNode = createDefaultNode()
doc.allNodes = {}
doc.allNodes[defaultNode.id] = defaultNode
doc.children = [defaultNode.id]
return doc
})
embeddedOutlineFile.crdt = outline
embeddedOutlineFile.save()
debug("Creating outline", outline)
return new this(embeddedOutlineFile, repository)
}
const createNewDocument = function(docId) {
let doc = Automerge.init(`server-1234`);
const initialSlateValue = Value.fromJSON(initialValue);
doc = Automerge.change(doc, "Initialize Slate state", doc => {
doc.note = slateCustomToJson(initialSlateValue.document);
})
docSet.setDoc(docId, doc);
}
_empty(actorId) {
return this.immutableApi
? Automerge.initImmutable(actorId)
: Automerge.init(actorId)
}
openDocument(state, action) {
if (action.file) return Automerge.load(action.file)
if (action.docId) {
let doc = this.docSet.getDoc(action.docId)
if (doc) return doc
return Automerge.change(Automerge.init(), { action: action }, (doc) => {
doc.docId = action.docId
})
}
}