automerge / hypermerge

Build p2p collaborative applications without any server infrastructure in Node.js
MIT License
1.28k stars 66 forks source link

Subscribing to changes for fields / sub-documents #12

Closed pvh closed 1 year ago

pvh commented 5 years ago

It is often useful to only subscribe to the part of a document that interests a particular component and receive changes when they arrive. The VSCode hypermerge editor allows opening & saving sub-documents but doesn't filter updates accordingly.

To determine who to notify, I propose the following strategy: 1) Create a copy of the automerge document that is inverted such that child nodes have links to their parents. Create a dictionary that associates the list with the relevant internal tracking IDs 1b) Change subscribers get attached to particular nodes in this inverted document. 2) When a change arrives, traverse the list of change ops and for each changed ID collect any listeners to that node or to any ancestor nodes. 3) Send a notification to each unique subscriber about the change.

pvh commented 5 years ago

@orionz talking to martin, I think the patch to the frontend might be the perfect solution here. I'll take a stab at it this morning.