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 list not firing subscriptions on push #55

Closed tja4472 closed 7 years ago

tja4472 commented 7 years ago

internal-list-observable.ts

Replace

this.previousValue = this.newValue;

with

this.previousValue = Object.assign([], newValue);
  uniqueNext(newValue) { 
    // Sort
    if (this.previousValue) { this.previousValue.sort((a, b) => a.$key - b.$key); }
    if (newValue) { newValue.sort((a, b) => a.$key - b.$key); }

    if (this.updated > 1 || (stringify(this.previousValue) !== stringify(newValue)) ) {
      this.previousValue = Object.assign([], newValue); //<====
      this.next(newValue);
      this.updated++;
    }
  }

hth Tim

adriancarriger commented 7 years ago

Hi @tja4472, this should be fixed in version 4.2.2 and looks related to issue #46. Let me know if it's different and still present. Thanks! 👍

tja4472 commented 7 years ago

Hi @adriancarriger

I'm afraid it's still present.

write-list.component.ts

export class WriteListComponent {
  groceries: AfoListObservable<any[]>;
  constructor(private afoDatabase: AngularFireOfflineDatabase) {
    this.groceries = this.afoDatabase.list('/groceries');

    this.groceries.subscribe(x => {
      console.log('this.groceries.subscribe', x);
    });
  }

If you go offline then run the example the subscribe only gets called once.

Does not get called when adding items.

adriancarriger commented 7 years ago

Hi @tja4472, thanks for the example!

I'll be taking a look at this in greater detail soon!

adriancarriger commented 7 years ago

Hi @tja4472, this is now fixed in version 4.2.3. Your code change fixed it! Thank you! 🎉 🎉 🎉

Here is the updated demo which now correctly triggers the .subscribe for pushes to lists while offline.

Thanks! 👍

AhabweEmmanuel commented 6 years ago

Hi everyone, this issue is still there. Am using version 4.3.1. When the app starts offline, nothing displays until I connect to the internet. Thanks alot for any help in advance