mirror of
https://github.com/cudr/slate-collaborative.git
synced 2025-06-10 03:14:06 +00:00
fix: call onError for errors during applyOperation
This commit is contained in:
parent
2917c98010
commit
c3425096e2
@ -57,29 +57,25 @@ export const AutomergeEditor = {
|
||||
operations: Operation[],
|
||||
cursorData?: CursorData
|
||||
) => {
|
||||
try {
|
||||
const doc = e.docSet.getDoc(docId)
|
||||
const doc = e.docSet.getDoc(docId)
|
||||
|
||||
if (!doc) {
|
||||
throw new TypeError(`Unknown docId: ${docId}!`)
|
||||
}
|
||||
|
||||
let changed
|
||||
|
||||
for await (let op of operations) {
|
||||
changed = Automerge.change<SyncDoc>(changed || doc, d =>
|
||||
applyOperation(d.children, op)
|
||||
)
|
||||
}
|
||||
|
||||
changed = Automerge.change(changed || doc, d => {
|
||||
setCursor(e.clientId, e.selection, d, operations, cursorData || {})
|
||||
})
|
||||
|
||||
e.docSet.setDoc(docId, changed as any)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
if (!doc) {
|
||||
throw new TypeError(`Unknown docId: ${docId}!`)
|
||||
}
|
||||
|
||||
let changed
|
||||
|
||||
for await (let op of operations) {
|
||||
changed = Automerge.change<SyncDoc>(changed || doc, d =>
|
||||
applyOperation(d.children, op)
|
||||
)
|
||||
}
|
||||
|
||||
changed = Automerge.change(changed || doc, d => {
|
||||
setCursor(e.clientId, e.selection, d, operations, cursorData || {})
|
||||
})
|
||||
|
||||
e.docSet.setDoc(docId, changed as any)
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -10,6 +10,7 @@ export interface AutomergeOptions {
|
||||
docId: string
|
||||
cursorData?: CursorData
|
||||
preserveExternalHistory?: boolean
|
||||
onError?: (msg: string | Error) => void
|
||||
}
|
||||
|
||||
/**
|
||||
@ -24,7 +25,12 @@ const withAutomerge = <T extends Editor>(
|
||||
|
||||
const { onChange } = e
|
||||
|
||||
const { docId, cursorData, preserveExternalHistory } = options || {}
|
||||
const {
|
||||
docId,
|
||||
cursorData,
|
||||
preserveExternalHistory,
|
||||
onError = (err: string | Error) => console.log('AutomergeEditor error', err)
|
||||
} = options || {}
|
||||
|
||||
e.docSet = new Automerge.DocSet()
|
||||
|
||||
@ -77,7 +83,9 @@ const withAutomerge = <T extends Editor>(
|
||||
const operations: any = e.operations
|
||||
|
||||
if (!e.isRemote) {
|
||||
AutomergeEditor.applySlateOps(e, docId, operations, cursorData)
|
||||
AutomergeEditor.applySlateOps(e, docId, operations, cursorData).catch(
|
||||
onError
|
||||
)
|
||||
|
||||
onChange()
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ export interface SocketIOPluginOptions {
|
||||
onConnect?: () => void
|
||||
onDisconnect?: () => void
|
||||
|
||||
onError?: (msg: string) => void
|
||||
onError?: (msg: string | Error) => void
|
||||
}
|
||||
|
||||
export interface WithSocketIOEditor {
|
||||
|
Loading…
Reference in New Issue
Block a user