adriancarriger / angularfire2-offline

🔌 A simple wrapper for AngularFire2 to read and write to Firebase while offline, even after a complete refresh.
https://angularfire2-offline.firebaseapp.com/
MIT License
207 stars 48 forks source link

Offline Promise doesn't seem to work #67

Closed savaryt closed 7 years ago

savaryt commented 7 years ago

Offline Promises doesn't seem to work:

Example code Service

  updateCustomer(customerKey: string, customer: Customer | any) {
    return this._auth.authState
      .switchMap(({ uid }) => {
        const { street, zip, city, region, country } = customer.address
        if (navigator.onLine) {
          return this._geocoderService
            .geocode(street, zip, city, region, country)
            .switchMap(latlng => {
              customer.latlng = latlng
              return this._db
                .object(`customers/${uid}/${customerKey}`)
                .set(customer)
            })
        } else {
          return this._db.object(`customers/${uid}/${customerKey}`).set(customer)
        }
      })
      .first()
      .toPromise()

Component

  updateCustomer(customerKey: string, customer: Customer) {
    return this._dataService
      .updateCustomer(customerKey, customer)
      .then(() => this._router.navigate(['../read'], { relativeTo: this._route }))
  }

When online, promise complete and navigation is tiggered. When offline, promise never complete, but data is updated locally and then sync with firebase on reconnect, however since the promise never completes, navigation isn't triggered.

AF2O: 4.3.0
AF2 v4.0.0-rc1
Angular 4.3.3
Angular-cli 1.3.0

It is the expected behavior ? (Seems not since 4.3.0 changelog says that offline promises are supported) If yes, do you have a recommended work-around ?

Thanks for your amazing work on this package !

savaryt commented 7 years ago

hm, hm, my excuses, didn't see the updated readme... (leave in silence...)