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

Splice for with Object elements #102

Open
lightsprint09 opened this issue Jan 21, 2024 · 1 comment
Open

Splice for with Object elements #102

lightsprint09 opened this issue Jan 21, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@lightsprint09
Copy link
Member

Splice is very useful to build all kinds of functionality (append, remove, ...). How would I splice elements which are objects/codable objects.

@heckj heckj added the question Further information is requested label Jan 21, 2024
@heckj heckj self-assigned this Jan 21, 2024
@heckj
Copy link
Collaborator

heckj commented Jan 21, 2024

I'm assuming you're talking about splice and not spliceText. Assuming you are, it applies to any sequence (List) CRDT - so it's a matter of how you'd like to map that back into the base Document.

You can use the custom Codable pieces enabled in Swift Automerge to encode an array into place, or if you want to control the lower-level access, you can convert your own objects into something and drop them into place manually. The Codable conformance was the way I spotted to make that possible. If you want the object itself represented as "schema" in the Automerge document, then using the custom encoder is probably the way to go. If you want to encode something yourself into, say, a binary representation (using protobuf or whatever), then you can do the encoding yourself and then add that as Value type into a List using a binary/data Value representation.

Look through the relevant methods under "Updating lists" at https://automerge.org/automerge-swift/documentation/automerge/document for the controls you have to update/manage lists yourself. (As you know, Automerge lists aren't strictly typed - but standard Swift arrays are - they're all of the same time. That constraint was built into the Codable encoder/decoder - so if you want a dynamic list, I'm afraid you'll have to assume the burden to assemble things yourself and handle the "what if it's not the type I expect" scenarios)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants