Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use root YMap #443

Merged
merged 1 commit into from
Aug 13, 2023
Merged

use root YMap #443

merged 1 commit into from
Aug 13, 2023

Conversation

lihebi
Copy link
Collaborator

@lihebi lihebi commented Aug 13, 2023

Instead of using four top-level YMaps (nodesMap, edgesMap, codeMap, richMap), this PR uses a root YMap rootMap, so that all fields are removable for possible future schema updates.

Before:

const nodesMap = ydoc.getMap<ReactflowNode<NodeData>>("nodesMap")
const edgesMap = ydoc.getMap<ReactflowEdge>("edgesMap")
const codeMap = ydoc.getMap<Y.Text>("codeMap")
const richMap = ydoc.getMap<Y.XmlFragment>("richMap")

After:

// rootMap
const rootMap = ydoc.getMap("rootMap");
// nested maps
const nodesMap = rootMap.get("nodesMap") as Y.Map<ReactflowNode<NodeData>>;
const edgesMap = rootMap.get("edgesMap") as Y.Map<ReactflowEdge>;
const codeMap = rootMap.get("codeMap") as Y.Map<Y.Text>;
const richMap = rootMap.get("richMap") as Y.Map<Y.XmlFragment>;

Also added four helper store.functions:

store.getNodesMap() {
  return get().ydoc.getMap("rootMap").get("nodesMap") as Y.Map<Node<NodeData>>;
},
store.getEdgesMap() {...}
store.getCodeMap() {...}
store.getRichMap() {...}

Ref from Yjs document:

Consider using a single top-level YMap: Top-level shared types cannot be deleted, so you may want to structure all your data in a single top-level YMap, eg. yDoc.getMap('data').get('page-1').

@lihebi lihebi marked this pull request as ready for review August 13, 2023 17:39
@lihebi lihebi merged commit 0007e65 into codepod-io:main Aug 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant