Skip to content

Commit a80a597

Browse files
authored
RxFire: Api Change and documentation (#1066)
* api changes and doc updates * fixes
1 parent f86d8c9 commit a80a597

File tree

2 files changed

+175
-3
lines changed

2 files changed

+175
-3
lines changed

packages/rxfire/docs/storage.md

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# RxFire Storage
2+
3+
## Task Observables
4+
5+
### `fromTask()`
6+
The `fromTask()` function creates an observable that emits progress changes.
7+
8+
| | |
9+
|-----------------|--------------------------------------------|
10+
| **function** | `fromTask()` |
11+
| **params** | `storage.UploadTask` |
12+
| **import path** | `rxfire/storage` |
13+
| **return** | `Observable<firestore.UploadTaskSnapshot>` |
14+
15+
#### TypeScript Example
16+
```ts
17+
import { fromTask } from 'rxfire/firestore';
18+
import * as firebase from 'firebase';
19+
import 'firebase/storage';
20+
21+
// Set up Firebase
22+
const app = initializeApp({ /* config */ });
23+
const storage = app.storage();
24+
const davidRef = storage.ref('users/david.png');
25+
26+
// Upload a transparent 1x1 pixel image
27+
const task = davidRef.putString('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64');
28+
29+
fromTask(task)
30+
.subscribe(snap => { console.log(snap.bytesTransferred); });
31+
```
32+
33+
### `percentage()`
34+
The `percentage()` function creates an observable that emits percentage of the uploaded bytes.
35+
36+
| | |
37+
|-----------------|--------------------------------------------|
38+
| **function** | `fromTask()` |
39+
| **params** | `storage.UploadTask` |
40+
| **import path** | `rxfire/storage` |
41+
| **return** | `Observable<number>` |
42+
43+
#### TypeScript Example
44+
```ts
45+
import { percentage } from 'rxfire/firestore';
46+
import * as firebase from 'firebase';
47+
import 'firebase/storage';
48+
49+
// Set up Firebase
50+
const app = initializeApp({ /* config */ });
51+
const storage = app.storage();
52+
const davidRef = storage.ref('users/david.png');
53+
54+
// Upload a transparent 1x1 pixel image
55+
const task = davidRef.putString('R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7', 'base64');
56+
57+
percentage(task)
58+
.subscribe(uploadProgress => { console.log(uploadProgress); });
59+
```
60+
61+
## Reference Observables
62+
63+
### `getDownloadURL()`
64+
The `getDownloadURL()` function creates an observable that emits the URL of the file.
65+
66+
| | |
67+
|-----------------|------------------------------------------|
68+
| **function** | `getDownloadURL()` |
69+
| **params** | `storage.Reference` |
70+
| **import path** | `rxfire/storage` |
71+
| **return** | `Observable<string>` |
72+
73+
#### TypeScript Example
74+
```ts
75+
import { getDownloadURL } from 'rxfire/storage';
76+
import * as firebase from 'firebase';
77+
import 'firebase/storage';
78+
79+
// Set up Firebase
80+
const app = initializeApp({ /* config */ });
81+
const storage = app.storage();
82+
83+
// Assume this exists
84+
const davidRef = storage.ref('users/david.png');
85+
86+
getDownloadURL(davidRef)
87+
.subscribe(url => { console.log(url) });
88+
```
89+
90+
### `getMetadata()`
91+
The `getMetadata()` function creates an observable that emits the URL of the file's metadta.
92+
93+
| | |
94+
|-----------------|------------------------------------------|
95+
| **function** | `getMetadata()` |
96+
| **params** | `storage.Reference` |
97+
| **import path** | `rxfire/storage` |
98+
| **return** | `Observable<Object>` |
99+
100+
#### TypeScript Example
101+
```ts
102+
import { getMetadata } from 'rxfire/storage';
103+
import * as firebase from 'firebase';
104+
import 'firebase/storage';
105+
106+
// Set up Firebase
107+
const app = initializeApp({ /* config */ });
108+
const storage = app.storage();
109+
110+
// Assume this exists
111+
const davidRef = storage.ref('users/david.png');
112+
113+
getMetadata(davidRef)
114+
.subscribe(meta => { console.log(meta) });
115+
```
116+
117+
### `put()`
118+
The `put()` function creates an observable that emits the upload progress of a file.
119+
120+
| | |
121+
|-----------------|------------------------------------------|
122+
| **function** | `put()` |
123+
| **params** | ref: `storage.Reference`, data: `any`, metadata?: `storage.UploadMetadata` |
124+
| **import path** | `rxfire/storage` |
125+
| **return** | `Observable<storage.UploadTaskSnapshot>` |
126+
127+
#### TypeScript Example
128+
```ts
129+
import { put } from 'rxfire/storage';
130+
import * as firebase from 'firebase';
131+
import 'firebase/storage';
132+
133+
// Set up Firebase
134+
const app = initializeApp({ /* config */ });
135+
const storage = app.storage();
136+
const dataRef = storage.ref('users/david.json');
137+
138+
const blob = new Blob(
139+
[JSON.stringify({ name: 'david'}, null, 2)],
140+
{ type : 'application/json' }
141+
);
142+
143+
put(davidRef, blob, { type : 'application/json' })
144+
.subscribe(snap => { console.log(snap.bytesTransferred) });
145+
```
146+
147+
### `putString()`
148+
The `putString()` function creates an observable that emits the upload progress of a file.
149+
150+
| | |
151+
|-----------------|------------------------------------------|
152+
| **function** | `putString()` |
153+
| **params** | ref: `storage.Reference`, data: `string`, metadata?: `storage.UploadMetadata` |
154+
| **import path** | `rxfire/storage` |
155+
| **return** | `Observable<storage.UploadTaskSnapshot>` |
156+
157+
#### TypeScript Example
158+
```ts
159+
import { putString } from 'rxfire/storage';
160+
import * as firebase from 'firebase';
161+
import 'firebase/storage';
162+
163+
// Set up Firebase
164+
const app = initializeApp({ /* config */ });
165+
const storage = app.storage();
166+
const davidRef = storage.ref('users/david.png');
167+
168+
const base64 = 'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
169+
170+
putString(davidRef, base64, { type : 'application/json' })
171+
.subscribe(snap => { console.log(snap.bytesTransferred) });
172+
```

packages/rxfire/firestore/collection/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ function processDocumentChanges(
117117
* order of occurence.
118118
* @param query
119119
*/
120-
export function docChanges(
120+
export function collectionChanges(
121121
query: firestore.Query,
122122
events: firestore.DocumentChangeType[] = ALL_EVENTS
123123
) {
@@ -144,7 +144,7 @@ export function sortedChanges(
144144
query: firestore.Query,
145145
events?: firestore.DocumentChangeType[]
146146
) {
147-
return docChanges(query, events).pipe(
147+
return collectionChanges(query, events).pipe(
148148
scan(
149149
(
150150
current: firestore.DocumentChange[],
@@ -163,7 +163,7 @@ export function auditTrail(
163163
query: firestore.Query,
164164
events?: firestore.DocumentChangeType[]
165165
): Observable<firestore.DocumentChange[]> {
166-
return docChanges(query, events).pipe(
166+
return collectionChanges(query, events).pipe(
167167
scan((current, action) => [...current, ...action], [])
168168
);
169169
}

0 commit comments

Comments
 (0)