Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.map(([id, changes]) => {
if (!changes) {
return;
}
let docOld = undefined;
const isUpdate = map[id + ''] && map[id + ''].merge;
if (isUpdate) {
docOld = Automerge.load(map[id + ''].merge);
updated.push(id);
} else {
docOld = Automerge.init();
}
const docInt =
typeof changes === 'string' ? Automerge.load(changes) : undefined;
const docNew = docInt
? Automerge.merge(docOld, docInt)
: Automerge.applyChanges(docOld, changes);
if (Object.keys(Automerge.getMissingDeps(docNew)).length) {
unsuccessful.push(id);
return;
}
/* if (!history.length) {
return {
...snapshot,
actor: undefined,
id,
merge: Automerge.save(docNew)
};
.map(([id, changes]) => {
if (!changes) {
return;
}
let docOld = undefined;
const isUpdate = map[id + ''] && map[id + ''].merge;
if (isUpdate) {
docOld = Automerge.load(map[id + ''].merge);
updated.push(id);
} else {
docOld = Automerge.init();
}
const docInt =
typeof changes === 'string' ? Automerge.load(changes) : undefined;
const docNew = docInt
? Automerge.merge(docOld, docInt)
: Automerge.applyChanges(docOld, changes);
if (Object.keys(Automerge.getMissingDeps(docNew)).length) {
unsuccessful.push(id);
return;
}
/* if (!history.length) {
const cb = typeof idOrCb === 'string' ? cbOrUndefined : idOrCb;
try {
let item: any;
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) {
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
})
}
}
mergeDocument(state, action) {
return Automerge.merge(state, Automerge.load(action.file))
}
async load() {
this.crdt = AutoMerge.load(await this.crdtFile.read())
}
recieveDocument = data => {
const currentDoc = this.docSet.getDoc(this.docId)
if (!currentDoc) {
const doc = Automerge.load(data)
this.docSet.removeDoc(this.docId)
this.docSet.setDoc(this.docId, doc)
this.editor.controller.setValue(Value.fromJSON(toJS(doc)))
}
this.editor.setFocus()
this.connection.open()
this.onConnect && setTimeout(this.onConnect, 0)
}