How to save document to database #316
Answered
by
BitPhinix
karthikcodes6
asked this question in
Q&A
-
I see there is an onChange event in the server-side code. But I'm not sure how to parse the Ydoc to slate JSON format. const server = Server.configure({
port: 1234,
extensions: [new Logger()],
onChange: async (data) => {
},
async onLoadDocument(data) {
if (data.document.isEmpty('content')) {
const insertDelta = slateNodesToInsertDelta(initialValue);
const sharedRoot = data.document.get('content', Y.XmlText) as Y.XmlText;
sharedRoot.applyDelta(insertDelta);
}
return data.document;
},
}); Any thoughts? |
Beta Was this translation helpful? Give feedback.
Answered by
BitPhinix
Feb 2, 2022
Replies: 1 comment 1 reply
-
You can convert the root Y.XmlText to a slate element using Something along the lines of const server = Server.configure({
port: 1234,
extensions: [new Logger()],
onChange: async (data) => {
const sharedRoot = data.document.get('content', Y.XmlText) as Y.XmlText
const slateContents = yTextToSlateElement(sharedRoot).children
// ....
},
async onLoadDocument(data) {
if (data.document.isEmpty('content')) {
const insertDelta = slateNodesToInsertDelta(initialValue)
const sharedRoot = data.document.get('content', Y.XmlText) as Y.XmlText
sharedRoot.applyDelta(insertDelta)
}
return data.document
},
}) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
BitPhinix
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can convert the root Y.XmlText to a slate element using
yTextToSlateElement
.Something along the lines of