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

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

Open
Chris1234567899 opened this issue Aug 10, 2022 · 2 comments
Open

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

Chris1234567899 opened this issue Aug 10, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@Chris1234567899
Copy link

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 Chris1234567899 added the enhancement New feature or request label Aug 10, 2022
@greenrobot-team
Copy link
Member

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 greenrobot-team changed the title store.watch<Entity> - return entity instead of void store.watch<Entity> - return changes instead of void Aug 16, 2022
@Chris1234567899
Copy link
Author

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants