Skip to content

RxFire: Api Change and documentation #1066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions packages/rxfire/docs/storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# RxFire Storage

## Task Observables

### `fromTask()`
The `fromTask()` function creates an observable that emits progress changes.

| | |
|-----------------|--------------------------------------------|
| **function** | `fromTask()` |
| **params** | `storage.UploadTask` |
| **import path** | `rxfire/storage` |
| **return** | `Observable<firestore.UploadTaskSnapshot>` |

#### TypeScript Example
```ts
import { fromTask } from 'rxfire/firestore';
import * as firebase from 'firebase';
import 'firebase/storage';

// Set up Firebase
const app = initializeApp({ /* config */ });
const storage = app.storage();
const davidRef = storage.ref('users/david.png');

// Upload a transparent 1x1 pixel image
const task = davidRef.putString('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64');

fromTask(task)
.subscribe(snap => { console.log(snap.bytesTransferred); });
```

### `percentage()`
The `percentage()` function creates an observable that emits percentage of the uploaded bytes.

| | |
|-----------------|--------------------------------------------|
| **function** | `fromTask()` |
| **params** | `storage.UploadTask` |
| **import path** | `rxfire/storage` |
| **return** | `Observable<number>` |

#### TypeScript Example
```ts
import { percentage } from 'rxfire/firestore';
import * as firebase from 'firebase';
import 'firebase/storage';

// Set up Firebase
const app = initializeApp({ /* config */ });
const storage = app.storage();
const davidRef = storage.ref('users/david.png');

// Upload a transparent 1x1 pixel image
const task = davidRef.putString('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64');

percentage(task)
.subscribe(uploadProgress => { console.log(uploadProgress); });
```

## Reference Observables

### `getDownloadURL()`
The `getDownloadURL()` function creates an observable that emits the URL of the file.

| | |
|-----------------|------------------------------------------|
| **function** | `getDownloadURL()` |
| **params** | `storage.Reference` |
| **import path** | `rxfire/storage` |
| **return** | `Observable<string>` |

#### TypeScript Example
```ts
import { getDownloadURL } from 'rxfire/storage';
import * as firebase from 'firebase';
import 'firebase/storage';

// Set up Firebase
const app = initializeApp({ /* config */ });
const storage = app.storage();

// Assume this exists
const davidRef = storage.ref('users/david.png');

getDownloadURL(davidRef)
.subscribe(url => { console.log(url) });
```

### `getMetadata()`
The `getMetadata()` function creates an observable that emits the URL of the file's metadta.

| | |
|-----------------|------------------------------------------|
| **function** | `getMetadata()` |
| **params** | `storage.Reference` |
| **import path** | `rxfire/storage` |
| **return** | `Observable<Object>` |

#### TypeScript Example
```ts
import { getMetadata } from 'rxfire/storage';
import * as firebase from 'firebase';
import 'firebase/storage';

// Set up Firebase
const app = initializeApp({ /* config */ });
const storage = app.storage();

// Assume this exists
const davidRef = storage.ref('users/david.png');

getMetadata(davidRef)
.subscribe(meta => { console.log(meta) });
```

### `put()`
The `put()` function creates an observable that emits the upload progress of a file.

| | |
|-----------------|------------------------------------------|
| **function** | `put()` |
| **params** | ref: `storage.Reference`, data: `any`, metadata?: `storage.UploadMetadata` |
| **import path** | `rxfire/storage` |
| **return** | `Observable<storage.UploadTaskSnapshot>` |

#### TypeScript Example
```ts
import { put } from 'rxfire/storage';
import * as firebase from 'firebase';
import 'firebase/storage';

// Set up Firebase
const app = initializeApp({ /* config */ });
const storage = app.storage();
const dataRef = storage.ref('users/david.json');

const blob = new Blob(
[JSON.stringify({ name: 'david'}, null, 2)],
{ type : 'application/json' }
);

put(davidRef, blob, { type : 'application/json' })
.subscribe(snap => { console.log(snap.bytesTransferred) });
```

### `putString()`
The `putString()` function creates an observable that emits the upload progress of a file.

| | |
|-----------------|------------------------------------------|
| **function** | `putString()` |
| **params** | ref: `storage.Reference`, data: `string`, metadata?: `storage.UploadMetadata` |
| **import path** | `rxfire/storage` |
| **return** | `Observable<storage.UploadTaskSnapshot>` |

#### TypeScript Example
```ts
import { putString } from 'rxfire/storage';
import * as firebase from 'firebase';
import 'firebase/storage';

// Set up Firebase
const app = initializeApp({ /* config */ });
const storage = app.storage();
const davidRef = storage.ref('users/david.png');

const base64 = 'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';

putString(davidRef, base64, { type : 'application/json' })
.subscribe(snap => { console.log(snap.bytesTransferred) });
```
6 changes: 3 additions & 3 deletions packages/rxfire/firestore/collection/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function processDocumentChanges(
* order of occurence.
* @param query
*/
export function docChanges(
export function collectionChanges(
query: firestore.Query,
events: firestore.DocumentChangeType[] = ALL_EVENTS
) {
Expand All @@ -144,7 +144,7 @@ export function sortedChanges(
query: firestore.Query,
events?: firestore.DocumentChangeType[]
) {
return docChanges(query, events).pipe(
return collectionChanges(query, events).pipe(
scan(
(
current: firestore.DocumentChange[],
Expand All @@ -163,7 +163,7 @@ export function auditTrail(
query: firestore.Query,
events?: firestore.DocumentChangeType[]
): Observable<firestore.DocumentChange[]> {
return docChanges(query, events).pipe(
return collectionChanges(query, events).pipe(
scan((current, action) => [...current, ...action], [])
);
}
Expand Down