-
Notifications
You must be signed in to change notification settings - Fork 0
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
Collections and Snapshot modes #3
Comments
Hey thanks for reaching out.
|
Hi Dan,
In short: Certain views in my app need the most recent version of a streamed collection value on init/build and stay with it while shown to the user (e.g. when user input is needed and showing a data update would be not a good idea). Unfortunately i'm in the middle of a Flutter project and do not have spare time to contribute at the moment. Regarding the mentioned Firebase issue i've also thought about creating an additional layer on top of my Firestore requests, where it would then be possible to define per (re)listening start of a stream from which source the first data event has to come (cache or server) including a fallback solution (e.g. if network is not available or if the database doesn't have any newer data than our cache contains). |
Got it, if the issue is that your views are first loading the data from the cache and then from the server moments later, the serverFirst stream policy would be the one that you'd want to use here since it'll block on getting that server response. |
Cool. Today i've built something similar with Query.get and using GetOptions. Interestingly with .get they let you choose from 3 different source modes. With Query.snapshots this is not possible. In your code i see this snippet in streamDocuments:
Is this returned stream capable of receiving further updates from Firestore after the first event, or is it limited to the return value of getDocuments? |
It is currently limited to updates to the documents that were initially returned, as the goal of serverFirst is to read the server once and then only read data from the cache and there is not a way to know when to requery the cache if for example a document that satisfies the query that was not in the initial server response is written at another time. The cacheAndSever policy alternatively will continue listening to both the cache and server so if a new document satisfies the query on the server then that query will automatically update. |
Ah now i understand. |
@rivella50 that makes sense to me. Would this change be what you're looking for then? #4 |
I would say yes - need to test it in my own project though (you remember that i actually work with the snapshots variant and quite often with docChanges there). |
Great, moving forward with that change then. Merged in and available under release 0.1.0. |
Very nice, thank you. |
Ok i was too curious and tried it right now with |
Hey there! I assume you're referring to this block of code: https://github.com/danReynolds/nimbostratus/blob/master/lib/nimbostratus.dart#L602. It's not actually the serverOnly/cacheAndServer combo that is emitting two identical events, since the result from the serverOnly is mapped over the cacheAndServer one, it is not emitted. The double event is instead coming from the fact that the cacheAndServer policy emits two events, first from the cache and then again from the server. This will only occur the first time we get the server result, when we switch from the serverFirst policy to the cacheAndServer one. After thinking it through though I do agree that we can move away from cacheAndFirst for this new policy and have changed the code as shown here: #5. I've pushed that version up as 0.1.2 so feel free to give it a try. |
That looks much better, very nice! |
Although: Does Regarding implementing |
cacheAndServerFirst will provide updates via the cache after the initial server update. Based on how I believe firestore works in offline mode, currently cacheAndServerFirst would not deliver data from the cache if you're offline because it is blocking on getting that event from the server. I haven't worked much with it offline though so I'd have to look into it more. |
Hi Dan, |
Hi there,
great idea, thanks for adding the project.
I have some questions:
I was looking for such a solution and i'm curious if i've found it with your package.
The text was updated successfully, but these errors were encountered: