-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
7076
-
SDK FY21-Q3.
This issue tracks adding support for a new Set type. Name TBD, but RealmSet seems like the most obvious.
High level API
See https://docs.google.com/document/d/1mvr88l4BAqvLgEaiO41hAfhIhYdVWuu573UaMmVJxlQ/edit
API is not finalized, but this is the first draft:
We will add a new class RealmSet<Object> which implements the standard Set interface in Java
open class Person : RealmObject() { val set: RealmSet<String> = RealmSet() val set: RealmSet<Dog> = RealmSet() // And so on // Illegal types will be detected at compile time and throw an error }
It is an open question which change listeners to expose. In order to render a Set to the UI I suspect most people will convert it to a List, so we should probably expose something like set.toList(“sortingProperty”)
// Set notifications val set: RealmSet<Dog> = getSet() set.addChangeListener { updatedSet -> // No finegrained notifications, since it would be unclear how to identity changes // as primitive types do not have keys and a Set doesn't have indexes. // Maybe the number of inserts, updates, removals would be interesting, but I // cannot come up with a use case } // Assumed use for rendering in the UI set.toList("name").addChangeListener { changes, updatedList -> // By converting to a list, we can expose the standard List fine-grained notifications }
- [ ] Figure out which methods exist on Set
- [ ] Figure out which additional methods make sense in a Realm setting: Change listeners, queries.
- [ ] Sets of Lists, Sets, and Maps are not supported in Phase 1. Only Sets of primitive, boxed, Mixed, and single object references are supported. Embedded object not supported either.
- [ ] Figure out how the notifications should look like. Right now we OrderedCollectionChangeSet, with sets we should probably add UnorderedCollectionChangeSet but it is unclear how that should look like, also when it needs to support both Set and Maps.
TODO
- [ ] Add support in Annotation Processor.
- [ ] Add support in copyToRealm(orUpdate)
- [ ] Add support in insert(OrUpdate)
- [ ] Add support in copyFromRealm
- [ ] Add support in RealmQuery
- [ ] Add support in createFromJson methods
- [ ] Add support in DynamicRealmObject
- [ ] RealmSchema