Last active
May 8, 2025 10:47
-
-
Save michielbdejong/7987ae65caf2ed0196bd36e9b255a179 to your computer and use it in GitHub Desktop.
automerge patchInfo source
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Repo } from '@automerge/automerge-repo'; | |
import { BroadcastChannelNetworkAdapter } from '@automerge/automerge-repo-network-broadcastchannel'; | |
import { NodeFSStorageAdapter } from '@automerge/automerge-repo-storage-nodefs'; | |
const repo1 = new Repo({ | |
network: [new BroadcastChannelNetworkAdapter()], | |
storage: new NodeFSStorageAdapter('./data1'), | |
}); | |
const docHandle1 = repo1.create(); | |
docHandle1.on('change', ({ patchInfo }) => { | |
console.log(`change on docHandle1, patchInfo:`, patchInfo); | |
}); | |
console.log('docHandle1 created'); | |
const repo2 = new Repo({ | |
network: [new BroadcastChannelNetworkAdapter()], | |
storage: new NodeFSStorageAdapter('./data2'), | |
}); | |
const docHandle2 = repo2.find(docHandle1.documentId); | |
docHandle2.on('change', ({ patchInfo }) => { | |
console.log(`change on docHandle2, patchInfo:`, patchInfo); | |
}); | |
console.log('docHandle2 created'); | |
docHandle1.change(d => { | |
d['foo'] = 'bar'; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Save this file as 'test.mjs', then:
The output will be:
I would have expected the source in the change event on docHandle2 to be 'receiveSyncMessage' instead of 'change'?