Skip to content

Commit

Permalink
fix(storage): Update to rxjs pipeable operators (#1624)
Browse files Browse the repository at this point in the history
  • Loading branch information
jymdman authored and jamesdaniels committed May 11, 2018
1 parent 3fbbb7d commit 014be21
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/storage/observable/fromTask.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UploadTask, UploadTaskSnapshot } from '@firebase/storage-types';
import { Observable } from 'rxjs/Observable';
import { Observable } from 'rxjs';

export function fromTask(task: UploadTask) {
return new Observable<UploadTaskSnapshot>(subscriber => {
Expand Down
6 changes: 3 additions & 3 deletions src/storage/ref.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { SettableMetadata, UploadMetadata, Reference, StringFormat } from '@firebase/storage-types';
import { createUploadTask, AngularFireUploadTask } from './task';
import { Observable } from 'rxjs/Observable';
import { Observable } from 'rxjs';
import { from } from 'rxjs/observable/from';
import { FirebaseZoneScheduler } from 'angularfire2';

Expand Down Expand Up @@ -31,9 +31,9 @@ export function createStorageRef(ref: Reference, scheduler: FirebaseZoneSchedule
from(ref.getMetadata())
)
),
delete: () => from(ref.delete()),
delete: () => Observable.from(ref.delete()),
child: (path: string) => createStorageRef(ref.child(path), scheduler),
updateMetatdata: (meta: SettableMetadata) => from(ref.updateMetadata(meta)),
updateMetatdata: (meta: SettableMetadata) => Observable.from(ref.updateMetadata(meta)),
put: (data: any, metadata?: UploadMetadata) => {
const task = ref.put(data, metadata);
return createUploadTask(task);
Expand Down
45 changes: 26 additions & 19 deletions src/storage/storage.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Observable } from 'rxjs/Observable'
import { Observable } from 'rxjs'
import { forkJoin } from 'rxjs/observable/forkJoin';
import { map, mergeMap, tap } from 'rxjs/operators';
import { TestBed, inject } from '@angular/core/testing';
import { FirebaseApp, FirebaseAppConfig, AngularFireModule, FirebaseAppName } from 'angularfire2';
import { AngularFireStorageModule, AngularFireStorage, AngularFireUploadTask, StorageBucket } from 'angularfire2/storage';
Expand Down Expand Up @@ -90,12 +91,14 @@ describe('AngularFireStorage', () => {
const task = ref.put(blob);
// Wait for the upload
const sub = forkJoin(task.snapshotChanges())
// get the url download
.mergeMap(() => ref.getDownloadURL())
// assert the URL
.do(url => expect(url).toBeDefined())
// Delete the file
.mergeMap(url => ref.delete())
.pipe(
// get the url download
mergeMap(() => ref.getDownloadURL()),
// assert the URL
tap(url => expect(url).toBeDefined()),
// Delete the file
mergeMap(url => ref.delete())
)
// finish the test
.subscribe(done, done.fail);
});
Expand All @@ -107,12 +110,14 @@ describe('AngularFireStorage', () => {
const task = ref.put(blob, { customMetadata: { blah: 'blah' } });
// Wait for the upload
const sub = forkJoin(task.snapshotChanges())
// get the metadata download
.mergeMap(() => ref.getMetadata())
// assert the URL
.do(meta => expect(meta.customMetadata).toEqual({ blah: 'blah' }))
// Delete the file
.mergeMap(meta => ref.delete())
.pipe(
// get the metadata download
mergeMap(() => ref.getMetadata()),
// assert the URL
tap(meta => expect(meta.customMetadata).toEqual({ blah: 'blah' })),
// Delete the file
mergeMap(meta => ref.delete())
)
// finish the test
.subscribe(done, done.fail);
});
Expand Down Expand Up @@ -180,12 +185,14 @@ describe('AngularFireStorage w/options', () => {
const task = ref.put(blob);
// Wait for the upload
const sub = forkJoin(task.snapshotChanges())
// get the url download
.mergeMap(() => ref.getDownloadURL())
// assert the URL
.do(url => expect(url).toMatch(new RegExp(`https:\\/\\/firebasestorage\\.googleapis\\.com\\/v0\\/b\\/${FIREBASE_STORAGE_BUCKET}\\/o\\/af\\.json`)))
// Delete the file
.mergeMap(url => ref.delete())
.pipe(
// get the url download
mergeMap(() => ref.getDownloadURL()),
// assert the URL
tap(url => expect(url).toMatch(new RegExp(`https:\\/\\/firebasestorage\\.googleapis\\.com\\/v0\\/b\\/${FIREBASE_STORAGE_BUCKET}\\/o\\/af\\.json`))),
// Delete the file
mergeMap(url => ref.delete())
)
// finish the test
.subscribe(done, done.fail);
});
Expand Down
2 changes: 1 addition & 1 deletion src/storage/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Injectable, Inject, Optional, InjectionToken, NgZone, PLATFORM_ID } fro
import { FirebaseStorage, UploadMetadata } from '@firebase/storage-types';
import { createStorageRef, AngularFireStorageReference } from './ref';
import { createUploadTask, AngularFireUploadTask } from './task';
import { Observable } from 'rxjs/Observable';
import { Observable } from 'rxjs';
import { FirebaseAppConfig, FirebaseAppName, FirebaseZoneScheduler, _firebaseAppFactory } from 'angularfire2';
import { FirebaseOptions } from '@firebase/app-types';

Expand Down
2 changes: 1 addition & 1 deletion src/storage/task.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UploadTaskSnapshot, UploadTask } from '@firebase/storage-types';
import { fromTask } from './observable/fromTask';
import { Observable } from 'rxjs/Observable';
import { Observable } from 'rxjs';
import { map, filter } from 'rxjs/operators';
import { from } from 'rxjs/observable/from';

Expand Down

0 comments on commit 014be21

Please sign in to comment.