automerge / automerge-swift

Swift language bindings presenting Automerge
https://automerge.org/automerge-swift/documentation/automerge/
MIT License
216 stars 11 forks source link

Add doc.objectDidChange? #178

Open jessegrosjean opened 1 month ago

jessegrosjean commented 1 month ago

In addition to objectWillChange I often feel myself wanting an objectDidChange event. I know SwiftUI doesn't need it, but generally didChange events seems like the useful default. Does it make sense to add this event to doc. And also fire it outside the sync block so that document state can be read immediately when receiving the event?

heckj commented 1 month ago

There's nothing in the framework integration that use anything like this (ObservableObject is explicitly only a change signal, and 'objectWillChange), so if we were going to add our own "objectDidChange" equivalent kind of thing, I'd be very tempted to do something to include information about _what_ changed - the whole set of data fromheads()` comes to mind. I haven't thought anything out on this front though, and don't have my own specific use case for what this is enabling.

jessegrosjean commented 1 month ago

so if we were going to add our own "objectDidChange" equivalent kind of thing, I'd be very tempted to do something to include information about what changed

That would be preferable to me, just more work. I guess it should include pre change and post change heads? Then later when #148 is available the listener will be able to generate the specific Patches for the change. That would be useful in many scenarios where the goal is to observer an Automerge.Document and process all changes.