Skip to content

Don't implement FirebaseApp, this leads to fragility (requires Firebase 5.0.2) #1630

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

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion src/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class AngularFireAuth {
const scheduler = new FirebaseZoneScheduler(zone, platformId);
this.auth = zone.runOutsideAngular(() => {
const app = _firebaseAppFactory(options, name, config);
return app.auth();
return app.auth!();
});

this.authState = scheduler.keepUnstableUntilFirst(
Expand Down
19 changes: 1 addition & 18 deletions src/core/firebase.app.module.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,9 @@
import { InjectionToken, NgZone, NgModule } from '@angular/core';

import { FirebaseOptionsToken, FirebaseAppNameToken, FirebaseAppConfigToken } from './angularfire2';

import firebase from '@firebase/app';
import { FirebaseApp as _FirebaseApp, FirebaseOptions, FirebaseAppConfig } from '@firebase/app-types';
import { FirebaseAuth } from '@firebase/auth-types';
import { FirebaseDatabase } from '@firebase/database-types';
import { FirebaseMessaging } from '@firebase/messaging-types';
import { FirebaseStorage } from '@firebase/storage-types';
import { FirebaseFirestore } from '@firebase/firestore-types';

export class FirebaseApp implements _FirebaseApp {
name: string;
automaticDataCollectionEnabled: boolean;
options: {};
auth: () => FirebaseAuth;
database: (databaseURL?: string) => FirebaseDatabase;
messaging: () => FirebaseMessaging;
storage: (storageBucket?: string) => FirebaseStorage;
delete: () => Promise<void>;
firestore: () => FirebaseFirestore;
}
export class FirebaseApp extends _FirebaseApp { }

export function _firebaseAppFactory(options: FirebaseOptions, name?: string, appConfig?: FirebaseAppConfig): FirebaseApp {
const config = appConfig || {};
Expand Down
2 changes: 1 addition & 1 deletion src/database-deprecated/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class AngularFireDatabase {
) {
this.database = zone.runOutsideAngular(() => {
const app = _firebaseAppFactory(config, name);
return app.database(databaseURL || undefined);
return app.database!(databaseURL || undefined);
});
}

Expand Down
60 changes: 30 additions & 30 deletions src/database-deprecated/firebase_list_factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('FirebaseListFactory', () => {
describe('<constructor>', () => {

it('should accept a Firebase db ref in the constructor', () => {
const list = FirebaseListFactory(app.database().ref(`questions`));
const list = FirebaseListFactory(app.database!().ref(`questions`));
expect(list instanceof FirebaseListObservable).toBe(true);
});

Expand All @@ -108,7 +108,7 @@ describe('FirebaseListFactory', () => {
it('equalTo - should re-run a query when the observable value has emitted', (done: any) => {

const subject = new Subject();
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByChild: 'height',
equalTo: subject
Expand All @@ -121,7 +121,7 @@ describe('FirebaseListFactory', () => {
it('startAt - should re-run a query when the observable value has emitted', (done: any) => {

const subject = new Subject();
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByChild: 'height',
startAt: subject
Expand All @@ -134,7 +134,7 @@ describe('FirebaseListFactory', () => {
it('endAt - should re-run a query when the observable value has emitted', (done: any) => {

const subject = new Subject();
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByChild: 'height',
endAt: subject
Expand All @@ -146,7 +146,7 @@ describe('FirebaseListFactory', () => {

it('should throw an error if limitToLast and limitToFirst are chained', () => {

const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByChild: 'height',
limitToFirst: 10,
Expand All @@ -158,7 +158,7 @@ describe('FirebaseListFactory', () => {

it('should throw an error if startAt is used with equalTo', () => {

const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByChild: 'height',
equalTo: 10,
Expand All @@ -170,7 +170,7 @@ describe('FirebaseListFactory', () => {

it('should throw an error if endAt is used with equalTo', () => {

const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByChild: 'height',
equalTo: 10,
Expand All @@ -182,7 +182,7 @@ describe('FirebaseListFactory', () => {

it('should throw an error if startAt and endAt is used with equalTo', () => {

const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByChild: 'height',
equalTo: 10,
Expand All @@ -207,7 +207,7 @@ describe('FirebaseListFactory', () => {
it('equalTo - should re-run a query when the observable value has emitted', (done: any) => {

const subject = new Subject();
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByValue: true,
equalTo: subject
Expand All @@ -220,7 +220,7 @@ describe('FirebaseListFactory', () => {
it('startAt - should re-run a query when the observable value has emitted', (done: any) => {

const subject = new Subject();
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByValue: true,
startAt: subject
Expand All @@ -233,7 +233,7 @@ describe('FirebaseListFactory', () => {
it('endAt - should re-run a query when the observable value has emitted', (done: any) => {

const subject = new Subject();
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByValue: true,
endAt: subject
Expand All @@ -257,7 +257,7 @@ describe('FirebaseListFactory', () => {
it('equalTo - should re-run a query when the observable value has emitted', (done: any) => {

const subject = new Subject();
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByKey: true,
equalTo: subject
Expand All @@ -270,7 +270,7 @@ describe('FirebaseListFactory', () => {
it('startAt - should re-run a query when the observable value has emitted', (done: any) => {

const subject = new Subject();
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByKey: true,
startAt: subject
Expand All @@ -283,7 +283,7 @@ describe('FirebaseListFactory', () => {
it('endAt - should re-run a query when the observable value has emitted', (done: any) => {

const subject = new Subject();
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByKey: true,
endAt: subject
Expand All @@ -306,7 +306,7 @@ describe('FirebaseListFactory', () => {
it('equalTo - should re-run a query when the observable value has emitted', (done: any) => {

const subject = new Subject();
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByKey: true,
equalTo: subject
Expand All @@ -319,7 +319,7 @@ describe('FirebaseListFactory', () => {
it('startAt - should re-run a query when the observable value has emitted', (done: any) => {

const subject = new Subject();
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByKey: true,
startAt: subject
Expand All @@ -332,7 +332,7 @@ describe('FirebaseListFactory', () => {
it('endAt - should re-run a query when the observable value has emitted', (done: any) => {

const subject = new Subject();
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByKey: true,
endAt: subject
Expand All @@ -348,7 +348,7 @@ describe('FirebaseListFactory', () => {
describe('shape', () => {

it('should have a a FirebaseListObservable shape when queried', () => {
const observable = FirebaseListFactory(app.database().ref(questionsPath), {
const observable = FirebaseListFactory(app.database!().ref(questionsPath), {
query: {
orderByChild: 'height',
equalTo: '1'
Expand Down Expand Up @@ -378,9 +378,9 @@ describe('FirebaseListFactory', () => {
val1 = { key: 'key1' };
val2 = { key: 'key2' };
val3 = { key: 'key3' };
app.database().ref().remove(done);
questions = FirebaseListFactory(app.database().ref(`questions`));
questionsSnapshotted = FirebaseListFactory(app.database().ref(`questionssnapshot`), { preserveSnapshot: true });
app.database!().ref().remove(done);
questions = FirebaseListFactory(app.database!().ref(`questions`));
questionsSnapshotted = FirebaseListFactory(app.database!().ref(`questionssnapshot`), { preserveSnapshot: true });
ref = questions.$ref;
refSnapshotted = questionsSnapshotted.$ref;
});
Expand Down Expand Up @@ -576,7 +576,7 @@ describe('FirebaseListFactory', () => {


it('should call off on all events when disposed', (done: any) => {
const questionRef = app.database().ref().child('questions');
const questionRef = app.database!().ref().child('questions');
subscription = FirebaseListFactory(questionRef).subscribe(_ => {
let firebaseSpy = spyOn(questionRef, 'off').and.callThrough();
expect(firebaseSpy).not.toHaveBeenCalled();
Expand Down Expand Up @@ -682,7 +682,7 @@ describe('FirebaseListFactory', () => {
})
.run(() => {
// Creating a new observable so that the current zone is captured.
subscription = FirebaseListFactory(app.database().ref(`questions`))
subscription = FirebaseListFactory(app.database!().ref(`questions`))
.filter(d => d
.map((v: any) => v.$value)
.indexOf('in-the-zone') > -1)
Expand Down Expand Up @@ -745,15 +745,15 @@ describe('FirebaseListFactory', () => {
})
.then(() => {

let query1 = FirebaseListFactory(app.database().ref(`questions`), {
let query1 = FirebaseListFactory(app.database!().ref(`questions`), {
query: {
orderByChild: 'data',
startAt: { value: 0 }
}
});
let promise1 = toPromise.call(take.call(query1, 1));

let query2 = FirebaseListFactory(app.database().ref(`questions`), {
let query2 = FirebaseListFactory(app.database!().ref(`questions`), {
query: {
orderByChild: 'data',
startAt: { value: 0, key: 'val2' }
Expand Down Expand Up @@ -783,15 +783,15 @@ describe('FirebaseListFactory', () => {
})
.then(() => {

let query1 = FirebaseListFactory(app.database().ref(`questions`), {
let query1 = FirebaseListFactory(app.database!().ref(`questions`), {
query: {
orderByChild: 'data',
equalTo: { value: 0 }
}
});
let promise1 = toPromise.call(take.call(query1, 1));

let query2 = FirebaseListFactory(app.database().ref(`questions`), {
let query2 = FirebaseListFactory(app.database!().ref(`questions`), {
query: {
orderByChild: 'data',
equalTo: { value: 0, key: 'val2' }
Expand Down Expand Up @@ -821,15 +821,15 @@ describe('FirebaseListFactory', () => {
})
.then(() => {

let query1 = FirebaseListFactory(app.database().ref(`questions`), {
let query1 = FirebaseListFactory(app.database!().ref(`questions`), {
query: {
orderByChild: 'data',
endAt: { value: 0 }
}
});
let promise1 = toPromise.call(take.call(query1, 1));

let query2 = FirebaseListFactory(app.database().ref(`questions`), {
let query2 = FirebaseListFactory(app.database!().ref(`questions`), {
query: {
orderByChild: 'data',
endAt: { value: 0, key: 'val2' }
Expand Down Expand Up @@ -859,7 +859,7 @@ describe('FirebaseListFactory', () => {
.then(() => {

let subject = new Subject<boolean>();
let query = FirebaseListFactory(app.database().ref(`questions`), {
let query = FirebaseListFactory(app.database!().ref(`questions`), {
query: {
orderByChild: 'even',
equalTo: subject
Expand Down
2 changes: 1 addition & 1 deletion src/database-deprecated/firebase_list_observable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('FirebaseListObservable', () => {
inject([FirebaseApp, AngularFireDatabase], (_app: FBApp, _db: AngularFireDatabase) => {
app = _app;
db = _db;
ref = app.database().ref();
ref = app.database!().ref();
O = new FirebaseListObservable(ref, (observer:Observer<any>) => {
});
})();
Expand Down
12 changes: 6 additions & 6 deletions src/database-deprecated/firebase_object_factory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('FirebaseObjectFactory', () => {
describe('<constructor>', () => {

it('should accept a Firebase db ref in the constructor', () => {
const object = FirebaseObjectFactory(app.database().ref().child(`questions`));
const object = FirebaseObjectFactory(app.database!().ref().child(`questions`));
expect(object instanceof FirebaseObjectObservable).toBe(true);
});

Expand All @@ -45,9 +45,9 @@ describe('FirebaseObjectFactory', () => {

beforeEach((done: any) => {
i = Date.now();
ref = app.database().ref().child(`questions/${i}`);
ref = app.database!().ref().child(`questions/${i}`);
nextSpy = nextSpy = jasmine.createSpy('next');
observable = FirebaseObjectFactory(app.database().ref(`questions/${i}`));
observable = FirebaseObjectFactory(app.database!().ref(`questions/${i}`));
ref.remove(done);
});

Expand Down Expand Up @@ -105,7 +105,7 @@ describe('FirebaseObjectFactory', () => {
});

it('should emit snapshots if preserveSnapshot option is true', (done: any) => {
observable = FirebaseObjectFactory(app.database().ref(`questions/${i}`), { preserveSnapshot: true });
observable = FirebaseObjectFactory(app.database!().ref(`questions/${i}`), { preserveSnapshot: true });
ref.remove(() => {
ref.set('preserved snapshot!', () => {
subscription = observable.subscribe(data => {
Expand All @@ -118,7 +118,7 @@ describe('FirebaseObjectFactory', () => {


it('should call off on all events when disposed', () => {
const dbRef = app.database().ref();
const dbRef = app.database!().ref();
let firebaseSpy = spyOn(dbRef, 'off');
subscription = FirebaseObjectFactory(dbRef).subscribe();
expect(firebaseSpy).not.toHaveBeenCalled();
Expand All @@ -132,7 +132,7 @@ describe('FirebaseObjectFactory', () => {
})
.run(() => {
// Creating a new observable so that the current zone is captured.
subscription = FirebaseObjectFactory(app.database().ref(`questions/${i}`))
subscription = FirebaseObjectFactory(app.database!().ref(`questions/${i}`))
.filter(d => d.$value === 'in-the-zone')
.subscribe(data => {
expect(Zone.current.name).toBe('newZone');
Expand Down
2 changes: 1 addition & 1 deletion src/database-deprecated/firebase_object_observable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('FirebaseObjectObservable', () => {
inject([FirebaseApp, AngularFireDatabase], (_app: FBApp, _db: AngularFireDatabase) => {
app = _app;
db = _db;
ref = app.database().ref();
ref = app.database!().ref();
O = new FirebaseObjectObservable((observer: Observer<any>) => {
}, ref);
})();
Expand Down
2 changes: 1 addition & 1 deletion src/database/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class AngularFireDatabase {
this.scheduler = new FirebaseZoneScheduler(zone, platformId);
this.database = zone.runOutsideAngular(() => {
const app = _firebaseAppFactory(options, name, config);
return app.database(databaseURL || undefined);
return app.database!(databaseURL || undefined);
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/database/list/audit-trail.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ describe('auditTrail', () => {
inject([FirebaseApp, AngularFireDatabase], (app_: FirebaseApp, _db: AngularFireDatabase) => {
app = app_;
db = _db;
app.database().goOffline();
createRef = (path: string) => { app.database().goOffline(); return app.database().ref(path); };
app.database!().goOffline();
createRef = (path: string) => { app.database!().goOffline(); return app.database!().ref(path); };
})();
});

Expand Down
Loading