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

get change message(s) from Automerge.getChanges() #534

Open
michaelpalumbo opened this issue Jul 10, 2023 · 1 comment
Open

get change message(s) from Automerge.getChanges() #534

michaelpalumbo opened this issue Jul 10, 2023 · 1 comment

Comments

@michaelpalumbo
Copy link

TLDR: Is it possible to get filter changes returned by getChanges() according to the message in the changeOption? How is this done?

I have change messages assigned to each of the possible edits in my app, i.e.

// message 'update position'
this.document = Automerge.change(this.document, 'update position', doc => {
  doc[posID].position = payload[1]
}) 

// and message 'add cable':
this.document = Automerge.change(this.document, 'add cable', doc => {
  for(let i=0; i<doc[srcID].outputs.length; i++){
    // find the output in the doc matching the cable's src
    if(doc[srcID].outputs[i].name == srcJack){
      if(!doc[srcID].outputs[i].connections[destID]){
        doc[srcID].outputs[i].connections[destID] = {}
      }
      doc[srcID].outputs[i].connections[destID][destJack] = cableType
    }
  }     
})

These two document changes are handled quite differently in the app: the first one results in changes to a visual scene, while the second results in changes to both visuals and what is hear in the audio output.

I recently implemented the Automerge Sync protocol, which is working great. Each time a syncMessage has been received and processed, I want to run Automerge.getChanges() and get the change message per each change so that I can trigger the additional steps related to each edit type.

@ept
Copy link
Member

ept commented Jul 22, 2023

Hi @michaelpalumbo, you can pass a change (the byte array) to Automerge.decodeChange() to get back a JSON representation that includes the message. Does that do what you need?

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

No branches or pull requests

2 participants