Skip to content

Commit

Permalink
change docs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
davideast committed Jul 12, 2023
1 parent 97aafbc commit 280c6b6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
22 changes: 11 additions & 11 deletions docs/firestore.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,29 +231,29 @@ deleteDoc(davidDocRef);
*/
```

### `collectionCount$()`
### `collectionCount()`

Create an observable that emits the server-calculated number of documents in a collection or query. [Learn more about count queries in the Firebase docs](https://firebase.google.com/docs/firestore/query-data/aggregation-queries).

| | |
|-----------------|------------------------------------------|
| **function** | `collectionCount$()` |
| **function** | `collectionCount()` |
| **params** | query: `import('firebase/firestore').CollectionReference \| import('firebase/firestore').Query`|
| **import path** | `rxfire/firestore` or `rxfire/firestore/lite` |
| **return** | `Observable<number>` |

#### TypeScript Example
```ts
import { collectionCount$ } from 'rxfire/firestore';
import { collectionCount } from 'rxfire/firestore';
// Also available in firestore/lite
import { collectionCount$ } from 'rxfire/firestore/lite';
import { collectionCount } from 'rxfire/firestore/lite';

import { getFirestore, collection } from 'firebase/firestore';

const db = getFirestore();
const likesCol = collection(db, 'posts/post_id_123/likes');

collectionCount$(likesCol).subscribe(count => {
collectionCount(likesCol).subscribe(count => {
console.log(count);
});
```
Expand All @@ -263,13 +263,13 @@ Note that the observable will complete after the first fetch. This is not a long
```ts
import { repeat } from 'rxjs';

import { collectionCount$} from 'rxfire/firestore';
import { collectionCount} from 'rxfire/firestore';
import { getFirestore, collection } from 'firebase/firestore';

const db = getFirestore();
const likesCol = collection(db, 'posts/post_id_123/likes');

collectionCount$(likesCol)
collectionCount(likesCol)
.pipe(
// re-fetch every 30 seconds.
// Stop fetching after 100 re-fetches so we don't do too many reads
Expand All @@ -280,22 +280,22 @@ collectionCount$(likesCol)
});
```

### `collectionCountSnap$()`
### `collectionCountSnap()`

Create an observable that emits the server-calculated number of documents in a collection or query. [Learn more about count queries in the Firebase docs](https://firebase.google.com/docs/firestore/query-data/aggregation-queries).

| | |
|-----------------|------------------------------------------|
| **function** | `collectionCountSnap$()` |
| **function** | `collectionCountSnap()` |
| **params** | query: `import('firebase/firestore').CollectionReference \| import('firebase/firestore').Query`|
| **import path** | `rxfire/firestore` or `firebase/firestore/lite` |
| **return** | `Observable<CountSnapshot>` |

#### TypeScript Example
```ts
import { collectionCountSnap$ } from 'rxfire/firestore';
import { collectionCountSnap } from 'rxfire/firestore';
// Also available in firestore/lite
import { collectionCountSnap$ } from 'rxfire/firestore/lite';
import { collectionCountSnap } from 'rxfire/firestore/lite';
import { getFirestore, collection } from 'firebase/firestore';

const db = getFirestore();
Expand Down
8 changes: 4 additions & 4 deletions test/firestore-lite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import {
collection,
docData,
collectionData,
collectionCountSnap$,
collectionCount$,
collectionCountSnap,
collectionCount,
} from '../dist/firestore/lite';
import {map} from 'rxjs/operators';
import {default as TEST_PROJECT, firestoreEmulatorPort} from './config';
Expand Down Expand Up @@ -235,7 +235,7 @@ describe('RxFire firestore/lite', () => {
];
await Promise.all(entries);

collectionCountSnap$(colRef).subscribe((snap) => {
collectionCountSnap(colRef).subscribe((snap) => {
expect(snap.data().count).toEqual(entries.length);
done();
});
Expand All @@ -252,7 +252,7 @@ describe('RxFire firestore/lite', () => {
];
await Promise.all(entries);

collectionCount$(colRef).subscribe((count) => {
collectionCount(colRef).subscribe((count) => {
expect(count).toEqual(entries.length);
done();
});
Expand Down
8 changes: 4 additions & 4 deletions test/firestore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ import {
auditTrail,
docData,
collectionData,
collectionCountSnap$,
collectionCount$,
collectionCountSnap,
collectionCount,
} from '../dist/firestore';
import {map, take, skip} from 'rxjs/operators';
import {default as TEST_PROJECT, firestoreEmulatorPort} from './config';
Expand Down Expand Up @@ -434,7 +434,7 @@ describe('RxFire Firestore', () => {
];
await Promise.all(entries);

collectionCountSnap$(colRef).subscribe((snap) => {
collectionCountSnap(colRef).subscribe((snap) => {
expect(snap.data().count).toEqual(entries.length);
done();
});
Expand All @@ -451,7 +451,7 @@ describe('RxFire Firestore', () => {
];
await Promise.all(entries);

collectionCount$(colRef).subscribe((count) => {
collectionCount(colRef).subscribe((count) => {
expect(count).toEqual(entries.length);
done();
});
Expand Down

0 comments on commit 280c6b6

Please sign in to comment.