Add YDoc toJSON

This commit is contained in:
Duane Johnson
2020-07-12 09:26:08 -06:00
parent 2151c514e5
commit 368dc6b36a
3 changed files with 53 additions and 3 deletions

View File

@@ -169,6 +169,24 @@ export class Doc extends Observable {
return this.get(name, YXmlFragment)
}
/**
* Converts the entire document into a js object, recursively traversing each yjs type
*
* @return {Object<string, any>}
*/
toJSON () {
/**
* @type {Object<string, any>}
*/
const doc = {}
for (const [k, v] of this.share.entries()) {
doc[k] = v.toJSON()
}
return doc
}
/**
* Emit `destroy` event and unregister all event handlers.
*/