automerge / automerge-swift

Swift language bindings presenting Automerge

Home Page:https://automerge.org/automerge-swift/documentation/automerge/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

heads() as a set looses ordering info of history

heckj opened this issue · comments

While exploring a possible "view history" feature of an example app, I realized that uniffi heads() returns a list, but in converting it to a set - we loose all the ordering of that history to show a sequence of changes.

I believe a better result is either a straight up Array, preserving the ordering from the underlying library - or potentially bringing on Swift Collections OrderedSet to preserve the ordering from the underlying library.

commented

Hmm. I'm not sure this is correct. The heads returned from e.g. Automerge::get_heads are not in any causal order, they are ordered lexicographically. The heads of a document don't really have a causal order as they represent concurrent changes.

Well damn - I was hoping the ordering returned from the Rust layer was something I could use. I'm trying to make a slider that allows scrolling through changes - and in my initial tests with just sequencing through the change sets resulted in all sorts of craziness - I assumed because we ditched the ordering.

Is that something that just isn't feasible? I want to be able to see "changes are ordered in this way" - to scroll back in history without knowing prior changeset collections. Should I bag that idea?

commented

We do have a topologically sorted list of changes in the document internally and that is exposed a little bit in the public Rust API. E.g. https://docs.rs/automerge/latest/automerge/struct.Automerge.html#method.get_changes returns the changes since a given set of heads in a topological order (note that this might be a confusing thing to scrub through a an linearization of a very branchy history will be weird).

So, we can expose that method in swift. It's not a nicely designed API for doing this stuff, but it might be enough to get started with?

I'll go get to reading, but in the meantime I'll revert this change. I got excited, made an assumption, and ran over what the current API exposed, assuming too much.

resolved by #44 - added function changes() in addition to heads() and clarified what heads() actually returns in documentation.