Skip to content

Commit

Permalink
fix(afs): workarounds for firebase-js-sdk #605 and #608 (#1540)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdaniels authored and davideast committed Apr 1, 2018
1 parent c2df603 commit 14e78ec
Show file tree
Hide file tree
Showing 4 changed files with 1,045 additions and 482 deletions.
5 changes: 3 additions & 2 deletions src/firestore/firestore.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ describe('AngularFirestore', () => {
})();
});

afterEach(async (done) => {
await app.delete();
afterEach(done => {
// can't await here https://github.com/firebase/firebase-js-sdk/issues/605
app.delete();
done();
});

Expand Down
12 changes: 7 additions & 5 deletions src/firestore/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { FirebaseFirestore, CollectionReference, DocumentReference } from '@fire
import { Observable } from 'rxjs/Observable';
import { Subscriber } from 'rxjs/Subscriber';
import { from } from 'rxjs/observable/from';
import { of } from 'rxjs/observable/of';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';

import { FirebaseOptions } from '@firebase/app-types';
import { Injectable, Inject, Optional } from '@angular/core';
Expand Down Expand Up @@ -118,11 +120,11 @@ export class AngularFirestore {
return app.firestore();
});

this.persistenceEnabled$ = zone.runOutsideAngular(() => {
return shouldEnablePersistence ?
from(this.firestore.enablePersistence().then(() => true, () => false)) :
from(new Promise((res, rej) => { res(false); }));
});
this.persistenceEnabled$ = zone.runOutsideAngular(() =>
shouldEnablePersistence ? from(this.firestore.enablePersistence().then(() => true, () => false))
: of(false)
)
.catch(() => of(false)); // https://github.com/firebase/firebase-js-sdk/issues/608
}

/**
Expand Down
1 change: 1 addition & 0 deletions tools/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const GLOBALS = {
'rxjs/operator/take': 'Rx.Observable.prototype',
'rxjs/operator/toArray': 'Rx.Observable.prototype',
'rxjs/operator/toPromise': 'Rx.Observable.prototype',
'rxjs/add/operator/catch': 'Rx.Observable.prototype',
'rxjs/add/operator/first': 'Rx.Observable.prototype',
'rxjs/add/operator/map': 'Rx.Observable.prototype',
'rxjs/add/operator/scan': 'Rx.Observable.prototype',
Expand Down
Loading

0 comments on commit 14e78ec

Please sign in to comment.