realm-js icon indicating copy to clipboard operation
realm-js copied to clipboard

Realm.Set doesn't implement .length property

Open sdandois opened this issue 3 years ago • 2 comments

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

sdandois avatar Jun 09 '22 15:06 sdandois

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.

takameyer avatar Jun 10 '22 08:06 takameyer

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.

tomduncalf avatar Jun 20 '22 12:06 tomduncalf