realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.81k stars 578 forks source link

Realm.Set doesn't implement .length property #4637

Open sdandois opened 2 years ago

sdandois commented 2 years ago

Problem

Realm.Set extends Realm.Collection but doesn't implement the length property. It's true that you can access the size of a Set with size, but still this breaks the polymorphism contract with the parent class.

Also, documentation is lacking in the reference: https://www.mongodb.com/docs/realm-sdks/js/latest/Realm.Set.html#length.

Solution

Option 1: Implement length just by delegating to size.

Option 2: Extend the documentation.

How important is this improvement for you?

I'd like to see it, but have a workaround

takameyer commented 2 years ago

Hello @sdandois, thank you for the enhancement request. We tried to model Set similar to a JavaScript Set. This uses size to get the length of the data structure.
But I also understand your point that a Realm.Set extends a Realm.Collection and doesn't implement length. We will consider this.

tomduncalf commented 2 years ago

We believe the correct solution here is to fix the inheritance hierarchy for the collection types, so that Set only inherits relevant properties. We've created RJS-1751 to track this.