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

RealmCollection interface #1363

Closed
3 tasks
cmelchior opened this issue Aug 6, 2015 · 10 comments · Fixed by #2345
Closed
3 tasks

RealmCollection interface #1363

cmelchior opened this issue Aug 6, 2015 · 10 comments · Fixed by #2345
Assignees
Milestone

Comments

@cmelchior
Copy link
Contributor

We need a RealmCollection to be able to parse different lists into UI components.

v1 Needs to support RealmResults and RealmList /cc #972
v2 Support for RealmSet when it becomes available #759
v3 Support for RealmMap. Will most likely require its own interface. #759

@bmunkholm
Copy link
Contributor

Align with Cocoa on this.

@cmelchior
Copy link
Contributor Author

I think we could split this into possible 2 interfaces. The reason being that our observer pattern is being reused across all our primary classes.

public interface RealmObservable {
  void addChangeListener(ChangeListener listener);
  void removeChangeListener(ChangeListener listener);
  void removeAllChangeListeners();
}

public interface RealmCollection<E> extends List<E>, RealmObservable {
  boolean isLoaded();
  E load();
}

What do you think? @realm/java

@dalinaum
Copy link
Contributor

dalinaum commented Nov 6, 2015

I am worry about little confusing between RxJava's Observable and proposed Observable.

@saket
Copy link

saket commented Nov 7, 2015

I so need this for an adapter that is capable for handling both RealmList and RealmResults :D

@cmelchior
Copy link
Contributor Author

@dalinaum True, Observable was just my initial suggestion. RealmObservable could probably also work. I updated the proposal

@cmelchior
Copy link
Contributor Author

Looking at RLMCollection: https://realm.io/docs/objc/latest/api/Protocols/RLMCollection.html, it seems our RealmCollection interface should be the following:

// All collections are Lists. This won't work with Sets, problem?
public interface RealmCollection<E> extends List<E>, RealmObservable {
  E first()
  E last() // we don't have this currently
  RealmQuery<E> where()
  Number min(String field)
  Number max(String field)
  Number sum(String field)
  Number average(String field)
  Date maxDate(String field)
  Date minDate(String field)

  // Async methods
  boolean isLoaded();
  E load();

  // These are kinda new. Didn't we remove those for some reason?
  RealmCollection<E> sort(String field, Sort sortOrder)
  RealmCollection<E> sort(String field1, Sort sortOrder1, String field2, Sort sortOrder2)
  RealmCollection<E> sort(String[] fields, Sort[] sortOrders)
}

@cmelchior
Copy link
Contributor Author

@kneth / @emanuelez Didn't we remove RealmResults.sort() for some reason?

@jpsim
Copy link
Contributor

jpsim commented Dec 17, 2015

This is an area where the Swift API has gotten a little further ahead than the ObjC one: https://realm.io/docs/swift/latest/api/Protocols/RealmCollectionType.html

We expose aggregate operations on all RealmCollectionTypes: min, max, sum, average.

Otherwise, judging by what you inherit when you extend List, it seems to cover everything.

@beeender
Copy link
Contributor

And maybe try to align the behaviour of clear and removeFromRealm in the interface

@cmelchior
Copy link
Contributor Author

Yes, having a unified RealmCollection interface means we have to find the same semantics for all methods as realmCollection.clear() should work the same way regardless if it a RealmResults or a RealmList.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants