automerge / automerge-classic

A JSON-like data structure (a CRDT) that can be modified concurrently by different users, and merged again automatically.
http://automerge.org/
MIT License
14.75k stars 466 forks source link

Lack of a set type, best to use map? #346

Open jeffa5 opened 3 years ago

jeffa5 commented 3 years ago

There isn't a set type in automerge at the moment. I suppose we can implement this by using a map with null values. Is this the intended method or is there a plan to add a set type?

ept commented 3 years ago

Yes, if you have a set of strings (or values that can be converted into strings), using a map with null values should work. If you have an unordered collection of objects, you could use the Automerge.Table datatype.

It might be worth adding an explicit set datatype further down the line; so far we haven't really had a strong need for it, but I'd be curious to hear more about your use case. A set containing primitive values should be fairly straightforward. A set of objects would be harder, since Automerge objects are mutable, and so it's not clear how one would enforce the property that a set should not contain the same element more than once. Automerge.Table is essentially a multiset in which each occurrence of an element is identified by a primary key.

raffomania commented 2 years ago

My use case for this is a tagging system where users can attach a set of strings to an object to help with filtering those objects. Using a Map with null values seems to work fine at the moment.