objectbox-java icon indicating copy to clipboard operation
objectbox-java copied to clipboard

Support observing individual objects

Open avestnik opened this issue 8 years ago • 7 comments

Note these related feature requests:

  • #1027
  • #268

while one can easily listen to changes to lists (queries), there is no way to listen to changes of some particular object

avestnik avatar Jun 30 '17 14:06 avestnik

That would be a feature request.

To better understand your use case: how many objects do you want to observe? Are you interested to observe object deletions?

greenrobot avatar Jul 06 '17 11:07 greenrobot

typical use case is following:

  • there is a list of objects (models) I'd like to show on screen
  • list is presented by ListViewModel which exposes some kind of ObserableList <ItemViewModel> Items
  • each ItemViewModel wraps over model object from DAL
  • ItemViewModel exposes some kind of Observable interface to a view
  • ideally ItemViewModel should be able to subscribe to changes in model and translate those changes into changes of ItemViewModel

I would estimate that at the same time there could be up to 100 objects being observed. deletions in my use case are handled in ListViewModel which subscribes to changes in query

avestnik avatar Jul 06 '17 11:07 avestnik

So the source of initial list (entities) is not a query?

greenrobot avatar Jul 06 '17 11:07 greenrobot

quite often it is, but I'd like to decouple ListVM and ItemVM and avoid listening to object changes via query listener

avestnik avatar Jul 06 '17 21:07 avestnik

@avestnik One advantage of list-based observers is that they cover removals and inserts. Wouldn't you still need those? If you do, does it make sense to also observe on the object level?

greenrobot avatar Jul 07 '17 08:07 greenrobot

I need both, ListVM listens to inserts/deletions, ItemVM listens to object changes

avestnik avatar Jul 08 '17 06:07 avestnik

This would be nice to have, but also still doable in the current iteration. I also need to listen to both list and single object changes. For the single object changes I just do a query on the object id and wrap the DataSubscription with an Observable to emmit the only item in the list passed in the DataSubscription.observer.

jarrodholliday avatar Jul 13 '17 17:07 jarrodholliday