dappsnation / akita-ng-fire

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

Firebase v9 modular SDK migration #223

Closed hakimio closed 2 years ago

hakimio commented 2 years ago

This a major library upgrade which not only includes migration to Firebase v9 modular SDK but also documentation updates/proofreading, all dependency updates, and minor refactoring.

Few things to note when going through the PR:

I tried to correct it but I don't quite understand what Meaning if your new state updating the store, the keys that maybe got removed in the new state are still present in the akita store supposed to mean. @GrandSchtroumpf maybe you could rephrase it in some other way?

all tests pass

Thank you @GrandSchtroumpf and @fritzschoff for your hard work. Hope you'll like the changes.

Closes #205

hakimio commented 2 years ago

@GrandSchtroumpf is the schematics project actually used?

GrandSchtroumpf commented 2 years ago

I didn't updated and used it for a while. But I cannot tell if it's used by other or not..

hakimio commented 2 years ago

@GrandSchtroumpf feel free to ask questions when reviewing the PR if it's not clear why I made some of the changes.

GrandSchtroumpf commented 2 years ago

It looks very clean. Congrat on that, and thanks for the good work 👍. I'll publish a new version asap.

hakimio commented 2 years ago

Thanks.

GrandSchtroumpf commented 2 years ago

ok, so for information my computer is still using lockfileVersion@1 of npm. The package-lock as been generated with lockfileVersion@2 so I'll try to update my local npm, but it might take some time because of potential side effects. Worst case scenario I delete package-lock.json and reinstall with lockfileVersion@1. Just to say, don't expect a publish in the next 24h.

hakimio commented 2 years ago

@GrandSchtroumpf No worries. Take your time. Anyway, if, for some reason, you can't use npm v7, older npm might still be able to use v2 lock file.

hakimio commented 2 years ago

@GrandSchtroumpf are you having any other issues with v7 apart from the package lock version?

GrandSchtroumpf commented 2 years ago

@hakimio I finally managed to update npm with nvm windows. You can try it out with npm i akita-ng-fire@7.0.0-beta.2

hakimio commented 2 years ago

@GrandSchtroumpf apart from PR #224 and #225, I also found one issue with the way docData() and collectionData() is implemented in rxfire used by angularfire. Basically, because they use onSnapshot() with includeMetadataChanges set to true, the same values from docData() and collectionData() are emitted twice.

Some solutions I could think of are the following:

What do you think could be a good solution?

GrandSchtroumpf commented 2 years ago

From my point of view, if @angular/fire set includeMetadataChanges to true, then we should keep it like that and let the developer decide if s.he wants to distinctUntilChanged or not. This library was meant to be a wrapper around best practices provided by @angular/fire (even if we consider it's not the best practice for us).

hakimio commented 2 years ago

@GrandSchtroumpf that also means that now things like profile query from FireAuthService will emit twice the same value when user is syncing changes, because selectProfile() now emits the same value twice compared to v6 where it was only emitted once. I think from user perspective that looks like a bug, but, of course, it's your choice if we should do sth about it or not.

GrandSchtroumpf commented 2 years ago

I get your point. But for me it's more a "bug" on rxfire. What you can do is to set includeMetadataChanges as a protected property of the service (set to true by default) and use fromRef instead of collectionData :

protected selectProfile(user: User): Observable<S['profile']> {
  const ref = doc(this.collection, user.uid);
  return fromRef<S['profile']>(ref, { includeMetadataChanges: this.includeMetadataChanges }).pipe(
    map()
  );
}

Like that a service might look like :

class AuthService extends FireAuthService<Profile> {
  includeMetadataChanges = false;
}

Would that work best for you ?

hakimio commented 2 years ago

@GrandSchtroumpf

GrandSchtroumpf commented 2 years ago

Ok, well set it to false by default then. It's your PR ^^