dappsnation / akita-ng-fire

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

Change.type on doc within - formatFromFirestore, valueChanges, syncCollection #189

Closed mark-at-pieces closed 3 years ago

mark-at-pieces commented 3 years ago

Looking into a way to get these types of changes: View changes between snapshots within akita-ng-fire?

Any thoughts?

Also Akita-ng-fire makes my life 10x easier. Y'all are awesome!

fritzschoff commented 3 years ago

Sorry for the late response. If I understood your question correctly, you get the changes from the hooks. https://github.com/dappsnation/akita-ng-fire/blob/v4.0.0/projects/akita-ng-fire/src/lib/collection/collection.service.ts#L57 So you could check when something is added and then check again when you get something from valueChanges etc.

mark-at-pieces commented 3 years ago

protected onCreate?(entity: EntityType, options: WriteOptions): any; protected onUpdate?(entity: Partial, options: WriteOptions): any; protected onDelete?(id: string, options: WriteOptions): any;

Are really awesome but these unfortunately are just write hooks, I was looking more for something like a read hook so I could filter respectively. I can get these https://firebase.google.com/docs/firestore/query-data/listen#view_changes_between_snapshots changes only if I subscribe to syncCollection, or valueChanges.


assets
.syncCollection((reference) => reference.where(`users.${user}`, '==', true))
.subscribe(async (assets) => {
  // console.log('stream assets!', assets);
  for (const { type, payload } of assets as DocumentChangeAction<ServerAssetInterface>[]) {
    const data = payload.doc.data();
    const uid = payload.doc.id;
    switch (type) {
      case FIRESTORE_ACTION_ENUM.ADDED:
        // do something
        break;
      case FIRESTORE_ACTION_ENUM.MODIFIED:
        // do something
        break;
      case FIRESTORE_ACTION_ENUM.REMOVED:
        // do something
        break;
      default:
        throw new Error('Error Occurred unsupported Firestore action from assets Entity.');
    }
  }
});```
fritzschoff commented 3 years ago

Guess then we need a new hook, something like onSnapshotChanges?

mark-at-pieces commented 3 years ago

That would be extremely helpful. Thank you for your time!

fritzschoff commented 3 years ago

Hey @MD-Widman , I had a talk with @GrandSchtroumpf , which is the founder of this library and the said that this is not really in the scope of a collection service. Since the collection service should only care about functionalities that are in the scope of a collection or document. In the PR that I referenced above you can see I just re exported the functionality from AngularFire which is kinda redundant. So I would suggest that you are using the AngularFire lib directly for your case, does it make sense for you?

mark-at-pieces commented 3 years ago

@fritzschoff thank you for you time