Can I associate Firebase with local storage?

I read a lot about SO about autonomous (local) storage and AngularFire, and I understand that AngularFire is designed for three way binding with the Angular and DOM model.

With special reference to How to synchronize a standalone database with Firebase when the device is online? I see that this is not a trivial matter introducing local storage into the mix. I did not quite understand the concept of "filling" Firebase in this thread.

However, I need to run the application offline. Here is my scenario:

  • I am creating a guest list application that can run on multiple devices simultaneously, using Firebase as the internal storage for the guest list.
  • If the device checks the guest, it applies to the FB and, therefore, to other devices. It should contain an updated copy of the guest list in local storage.
  • Where I live, 3G coverage is a serious problem, so someone can download the application when it is connected, close it, move it to another place and then try to open the application when there is no signal.
  • In this case, the application should use the local storage list.
  • When the device reconnects to the network, connect to Firebase and upload the local storage changes to Firebase.

I know that Kato also mentioned that there might be standalone data storage capabilities in a future release of AngularFire, what else is possible? Otherwise, I have to do this:

  • Assuming the application is running offline, update the local storage every time a guest is checked. Also track this change in your local local repository.
  • When / if the device returns to the Internet, use AngularFire to pull the Firebase guest list into the $ scope.guestList variable.
  • Scroll through the list of "made changes" from the local storage and make these changes to the variable $ scope.guestList var.

This does not seem like a good approach, but I do not know another way. Is there a way to directly associate Firebase with local storage?

+6
source share
1 answer

I decided it was probably best not to use AngularFire in this scenario, but rather to use the Firebase SDK directly. AngularFire 3-way bindings make it very difficult to capture changes in $ scope for local storage. Using the SDK allows you to intercept FB changes and save them directly to local storage, as well as update the $ scope.

Similarly, making changes to the FB using ref.update () is trivial and can be done along with updating the local storage.

If the application starts offline (found from .firebasio.com / .info / connected), just use local storage, as well as Kato suggested a โ€œsimpleโ€ Firebase connection. I do this by simply calling empty ref.update({}); . Then, when making changes to the data in the local storage, also perform regular FB / push / save updates. Then, when the application connects, a copy of the FB in memory will be synchronized with the server.

+5
source

Source: https://habr.com/ru/post/984006/


All Articles