flamelink / flamelink-js-sdk

🦊 Official Flamelink JavaScript SDK for both the Firebase Realtime database and Cloud Firestore
https://flamelink.github.io/flamelink-js-sdk
MIT License
43 stars 5 forks source link

How do I use this with Observables / RxJS? #159

Closed mizzao closed 3 years ago

mizzao commented 3 years ago

Hi there, we're a paying Flamelink user. Is there any way to use this SDK with Observables / RxJS?

Your old SDK seemed to support it, but only for Realtime DB: https://github.com/flamelink/flamelink/blob/master/docs/content.md#subscribe

We're using Firestore now, and it seems like there is no Observable support anymore, at least from the docs I found. Is that true? https://flamelink.github.io/flamelink-js-sdk/#/migration-guide

Happy to be proven wrong and pointed in the right direction if there are any docs!

coenraadf commented 3 years ago

Good day Andrew.

The SDK does not natively support observables, but what I do in Angular is something along these lines:

query(): Observable<Partial<Blog>[]> {
    return from(
      this.flamelink.flApp.content.get({
        schemaKey: 'posts',
        populate: [
          { field: 'author', fields: ['name', 'surname'] },
          {
            field: 'cardImage',
            fields: ['url'],
            size: { path: '375_9999_100' },
          },
        ],
      }) as Promise<Partial<Blog>[]>
    ).pipe(
      untilDestroyed(this),
      map((entries) =>
        Object.keys(entries).map((key) => entries[key])
      )
    );
  }
gitdubz commented 3 years ago

Hi @mizzao, does the answer from @coenraadf above help to resolve your query?

gitdubz commented 3 years ago

Closing this due to inactivity