mirror of
https://github.com/cudr/slate-collaborative.git
synced 2025-06-13 12:54:04 +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[],
|
operations: Operation[],
|
||||||
cursorData?: CursorData
|
cursorData?: CursorData
|
||||||
) => {
|
) => {
|
||||||
try {
|
const doc = e.docSet.getDoc(docId)
|
||||||
const doc = e.docSet.getDoc(docId)
|
|
||||||
|
|
||||||
if (!doc) {
|
if (!doc) {
|
||||||
throw new TypeError(`Unknown docId: ${docId}!`)
|
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)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
docId: string
|
||||||
cursorData?: CursorData
|
cursorData?: CursorData
|
||||||
preserveExternalHistory?: boolean
|
preserveExternalHistory?: boolean
|
||||||
|
onError?: (msg: string | Error) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -24,7 +25,12 @@ const withAutomerge = <T extends Editor>(
|
|||||||
|
|
||||||
const { onChange } = e
|
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()
|
e.docSet = new Automerge.DocSet()
|
||||||
|
|
||||||
@ -77,7 +83,9 @@ const withAutomerge = <T extends Editor>(
|
|||||||
const operations: any = e.operations
|
const operations: any = e.operations
|
||||||
|
|
||||||
if (!e.isRemote) {
|
if (!e.isRemote) {
|
||||||
AutomergeEditor.applySlateOps(e, docId, operations, cursorData)
|
AutomergeEditor.applySlateOps(e, docId, operations, cursorData).catch(
|
||||||
|
onError
|
||||||
|
)
|
||||||
|
|
||||||
onChange()
|
onChange()
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ export interface SocketIOPluginOptions {
|
|||||||
onConnect?: () => void
|
onConnect?: () => void
|
||||||
onDisconnect?: () => void
|
onDisconnect?: () => void
|
||||||
|
|
||||||
onError?: (msg: string) => void
|
onError?: (msg: string | Error) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface WithSocketIOEditor {
|
export interface WithSocketIOEditor {
|
||||||
|
Loading…
Reference in New Issue
Block a user