dappsnation / akita-ng-fire

Akita ❤️ Angular 🔥 Firebase
MIT License
131 stars 27 forks source link

Loading state does not work with syncing empty collection #238

Closed randallmeeker closed 1 year ago

randallmeeker commented 2 years ago

If I'm syncing a collection and it is empty the loading state will not revert to false.

The loading state does not turn false till we process individual documents. HERE

It would seem to me that we could reset the store HERE instead of where the results of the sync'd collection is returned.

Thoughts, or am I very wrong here?

hakimio commented 2 years ago

Not sure I understand the problem. Do you mean that collectionChanges never emits anything when collection is empty? Are you setting syncOptions.loading config?

randallmeeker commented 2 years ago

I am, but if the returned result of a sync collection is an empty array then loading never goes from TRUE to FALSE. It is set up to only turn the loading state FALSE in syncStoreFromDocAction which only processes individual items in the store. If an empty array is returned, then nothing is processed and the loading state stays TRUE.

hakimio commented 2 years ago

Can you create a PR with a unit test reproducing the issue?

randallmeeker commented 2 years ago

Sure, will see what I can throw together this week. :+1:

Benny739 commented 2 years ago

Any news here?

hakimio commented 2 years ago

@Benny739 feel free to make a PR. Nobody seems to be working on this one.

randallmeeker commented 2 years ago

@Benny739 @hakimio Wanted to get this done the 9 to 5 is more like 9 to 9 these days. I'm happy to help, but won't get back to this for another week or so when I hop back on the project I was doing this for. I never really used the loading states in this until I had a brand new project to do so and noticed them broken. I almost 100% I have a valid fix by must moving the setLoadingState higher up in the call action.

Benny739 commented 2 years ago

Do you have an idea how to solve this? CollectionChanges doesn't emit anything when there is no data. We switched to CollectionData in our app and then we replace all data in the store every time we get new data, but this is not very beautiful.

There is already an open bug in rxfire: https://github.com/FirebaseExtended/rxfire/issues/55

randallmeeker commented 2 years ago

Yes, my original post shows where a change could be made. I have been a bit underwater as of late, but should be able to work on this next week.

The RxFire bug is interesting as I did not encounter than in this, but In my tests I don't know that I'm syncing with a query. I will say if the RxFire bug is legit, solving this problem here will only solve it for syncing w/o a query. RxFire would still have to be fixed for a full solution.

luke-rogers commented 1 year ago

Opened #270 which should hopefully fix this issue.

@Benny739 be great if you could give it a test in your app and feedback.