mirror of
https://github.com/yjs/yjs.git
synced 2026-08-29 10:09:05 +02:00
add origin to rdt's 'delta' event
This commit is contained in:
@@ -256,6 +256,28 @@ export const testRdtDeltaEvent = () => {
|
||||
t.compare(captured, delta.create().insert('hello').done())
|
||||
}
|
||||
|
||||
/**
|
||||
* The `'delta'` event carries the transaction origin as its second argument.
|
||||
*/
|
||||
export const testRdtDeltaEventOrigin = () => {
|
||||
const ydoc = new Y.Doc()
|
||||
const ytext = ydoc.get()
|
||||
/**
|
||||
* @type {any}
|
||||
*/
|
||||
let capturedOrigin = null
|
||||
ytext.on('delta', (_d, origin) => { capturedOrigin = origin })
|
||||
const myOrigin = {}
|
||||
ydoc.transact(() => {
|
||||
ytext.insert(0, 'hello')
|
||||
}, myOrigin)
|
||||
t.assert(capturedOrigin === myOrigin)
|
||||
// without an explicit origin, `null` is emitted
|
||||
capturedOrigin = myOrigin
|
||||
ytext.insert(5, ' world')
|
||||
t.assert(capturedOrigin === null)
|
||||
}
|
||||
|
||||
/**
|
||||
* `useRenderer` changes the default renderer used by `toDelta` (and friends). Calling `toDelta()`
|
||||
* with no argument afterwards is equivalent to passing the renderer explicitly.
|
||||
|
||||
Reference in New Issue
Block a user