Ich verwende den folgenden Code, um die Byte[]-Änderungen von den Clients festzulegen – Ydoc ist es eine der Requisiten
Code: Select all
public void ApplyUpdate(byte[] clientUpdate)
{
if (clientUpdate == null || clientUpdate.Length == 0)
return;
lock (_stateLock)
{
using (var transaction = YDoc.WriteTransaction())
{
transaction.ApplyV1(clientUpdate);
transaction.Commit();
}
LastActivity = DateTime.UtcNow;
}
}
Code: Select all
public byte[] GetFullState()
{
lock (_stateLock)
{
using (var transaction = YDoc.ReadTransaction())
{
var stateVector = transaction.StateVectorV1();
if (stateVector == null || stateVector.Length == 0)
{
// Document is empty, return empty array
return Array.Empty();
}
// Get the entire document state
var state = transaction.StateDiffV1(Array.Empty());
return state ?? Array.Empty();
}
}
}
Code: Select all
Value cannot be null. (Parameter 'source')
Code: Select all
const ydocA = useMemo(() => new Y.Doc(), [])
const sharedTypeA = useMemo(
() => ydocA.get('slate', Y.XmlText),
[ydocA]
)
const editorA = useMemo(() => {
const e = withReact(createEditor())
const yEditor = withYjs(e, sharedTypeA)
return withYHistory(yEditor)
}, [sharedTypeA])
useEffect(() => {
YjsEditor.connect(editorA)
return () => {
YjsEditor.disconnect(editorA)
}
}, [editorA])
Mobile version