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

store.watch<Entity> - return changes instead of void

Open Chris1234567899 opened this issue 3 years ago • 2 comments

I try to hook up a custom REST synchronization service to entity changes and have something like this to listen to model changes:

final objectBox = await ObjectBox.create();
...
final stream = objectBox.store.watch<FormAnswer>();
stream.listen((event) {
    print('answers changed');
    // sync the changed model with server
});

Describe the solution you'd like

I actually would expect the stream to return the entity that changed. Returning a Stream with void does not make too much sense in my opinion. You get informed that 'something' changed, without knowing what... I've seen there is also the option to subscribe to objectBox.store.entityChanges which kinda does, what I want. It's just not as convenient as the first one, since you'd have to switch through all Entity types first, to handle them accordingly.

Just an idea for a future version ;-)

Chris1234567899 avatar Aug 10 '22 13:08 Chris1234567899

Thanks! As an alternative you could update a timestamp in FormAnswer and then run a query to get objects with a timestamp greater than last checked whenever the Box has changes (or watch that query directly).

This is related to the feature request #203 for our Java library.

greenrobot-team avatar Aug 16 '22 12:08 greenrobot-team

Thanks for the suggestion, yes, that's pretty much what I implemented in the meanwhile: Listening to a query on an "SyncStatus"-enum... Working well so far and looking forward when in some future version, dart model inheritance will be implemented. I've seen there is already an issue for that :)

Chris1234567899 avatar Aug 16 '22 14:08 Chris1234567899