-
Notifications
You must be signed in to change notification settings - Fork 127
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
Support for Streams from query objects #88
Support for Streams from query objects #88
Conversation
e7e2e87
to
a5d177e
Compare
entity objects have changed, how did java/swift/go do this?
@Buggaboo Thanks. Chiming in here: similar to the other bindings (e.g. Java https://docs.objectbox.io/data-observers-and-rx#data-observers-basics) observers are meant to notify that there was a change to a box (not what has changed) or more importantly return updated query results if there was a change to a box. The internal APIs only provide ways to listen that there was a change to a single box or all boxes, not which changes. The binding should then add wrapper code so the user can subscribe to e.g. the latest query results (if there was a change, re-run the query and return the new results). Again, see the Java binding for examples. Hope this helps. |
Thanks, I'll look into it again, and try to follow the existing syntax. |
All the callbacks and streams work as expected tho.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only had a very quick look, will need to dive deeper and play with the code to understand it fully before reviewing properly.
static final any = <int, Any>{}; // radix? > tree? | ||
|
||
// sync:true -> ObjectBoxException: 10001 TX is not active anymore: #101 | ||
static final controller = StreamController<int>.broadcast(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that comment on an issue that needs looking at?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that requires some attention
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the reference of #101 mean here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was generated here, see nativeCode
.
GitHub issue number was triggered.
### Streams | ||
|
||
Streams can be created from queries. | ||
The streams can be extended with [rxdart](https://github.com/ReactiveX/rxdart); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why rxdart? Are there other alternatives you've considered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to be the most popular one, and it supports Stream which is more idiomatic, by way of extensions. I expose a stream property from an observable query for that reason.
@Buggaboo A general remark: please look at the Dart Analysis issues and resolve them if possible (e.g. compare to changes made to your last PR). |
…d of casting and/or declaring types
Pointer.asFunction complained that the typedef parameter was not proper.
and there is no consensus on entity ids
…its own ViewModel/BLoC
test/stream_test.dart
Outdated
}); | ||
|
||
box.put(TestEntity(tString: 'Hello world')); | ||
await Future.delayed(Duration(seconds: 0)); // ffi explodes without |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The docs for Future.delayed contain
If the duration is 0 or less, it completes no sooner than in the next event-loop iteration, after all microtasks have run.
I don't know much about Dart, but this sounds like the observer callback is held up from executing while this "thread" is active. Might this cause issues in an actual app where the callback execution is held back too long? Is it possible to run them on a separate "thread" so they are not held up by other code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, reading the StreamController.broadcast
docs on using sync
is false mode (recommended) this actually sounds like expected behavior (events may be delivered at any point after the code adding the event has completed). LGTM then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove those ffi explodes without
comments then and clarify regarding delayed event delivery.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I updated this.
|
||
void dispose() { | ||
_query.close(); | ||
_store.unsubscribe(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should be part of close()
. This feels like something very easy to forget.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's called by close
iirc. I didn't want to expose the BLoC/VM's internals to the Widgets. Leaky abstractions and such.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, sorry, should have been more clear: was talking about not even exposing unsubscribe()
to the user and doing it as part of close()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point.
@Buggaboo Thanks for your latest changes and 👍 for also improving our example app! I had some more questions, but this LGTM now. @vaind Can you look at |
Sorry, forgot one thing: look at Dart Analysis issues and run the formatter. |
Squashed and merged. I fixed the analysis and formatting issues myself (0a941a5). Thanks again. |
Should be fine to the best of my knowledge. |
@greenrobot-team Please review.