Skip to content

Fix for #1385 that was caused by firebase releasing 4.8.1 #1386

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 2 commits into from
Dec 26, 2017
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
2 changes: 0 additions & 2 deletions src/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { NgModule, NgZone } from '@angular/core';
import * as firebase from 'firebase/app';
import 'firebase/auth';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it better using scoped one?

import  '@firebase/auth';
// ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused. This is simply a removal as it was not being used here. I did not add back any imports, only removed.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh my bad. Sorry, I think I need some coffee.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, I feel ya. Been up since 7am yesterday (now 1pm). I am seeing cross eyed so I really was not sure if I was missing something!

import { FirebaseApp, AngularFireModule } from 'angularfire2';
import { AngularFireAuth } from './auth';

Expand Down
17 changes: 9 additions & 8 deletions src/auth/auth.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as firebase from 'firebase/app';
import { FirebaseApp as FBApp } from '@firebase/app-types';
import { User } from '@firebase/auth-types';
import { ReflectiveInjector, Provider } from '@angular/core';
import { Observable } from 'rxjs/Observable'
import { Subject } from 'rxjs/Subject'
Expand All @@ -19,16 +20,16 @@ function authSkip(auth: Observable<any>, count: number): Observable<any> {
return skip.call(auth, 1);
}

const firebaseUser = <firebase.User> {
const firebaseUser = <User> {
uid: '12345',
providerData: [{ displayName: 'jeffbcrossyface' }]
};

describe('AngularFireAuth', () => {
let app: firebase.app.App;
let app: FBApp;
let afAuth: AngularFireAuth;
let authSpy: jasmine.Spy;
let mockAuthState: Subject<firebase.User>;
let mockAuthState: Subject<User>;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -42,11 +43,11 @@ describe('AngularFireAuth', () => {
afAuth = _auth;
})();

mockAuthState = new Subject<firebase.User>();
mockAuthState = new Subject<User>();
spyOn(afAuth, 'authState').and.returnValue(mockAuthState);
spyOn(afAuth, 'idToken').and.returnValue(mockAuthState);
afAuth.authState = mockAuthState as Observable<firebase.User>;
afAuth.idToken = mockAuthState as Observable<firebase.User>;
afAuth.authState = mockAuthState as Observable<User>;
afAuth.idToken = mockAuthState as Observable<User>;
});

afterEach(done => {
Expand Down Expand Up @@ -104,7 +105,7 @@ describe('AngularFireAuth', () => {

it('should emit auth updates through idToken', (done: any) => {
let count = 0;

// Check that the first value is null and second is the auth user
const subs = afAuth.idToken.subscribe(user => {
if (count === 0) {
Expand Down
11 changes: 5 additions & 6 deletions src/auth/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as firebase from 'firebase/app';
import 'firebase/auth';
import { FirebaseAuth, User } from '@firebase/auth-types';
import { Injectable, NgZone } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { observeOn } from 'rxjs/operator/observeOn';
Expand All @@ -15,12 +14,12 @@ export class AngularFireAuth {
/**
* Firebase Auth instance
*/
public readonly auth: firebase.auth.Auth;
public readonly auth: FirebaseAuth;

/**
* Observable of authentication state; as of 4.0 this is only triggered via sign-in/out
*/
public readonly authState: Observable<firebase.User|null>;
public readonly authState: Observable<User|null>;

/**
* Observable of the signed-in user's ID token; which includes sign-in, sign-out, and token refresh events
Expand All @@ -36,7 +35,7 @@ export class AngularFireAuth {
});
this.authState = observeOn.call(authState$, new ZoneScheduler(Zone.current));

const idToken$ = new Observable<firebase.User|null>(subscriber => {
const idToken$ = new Observable<User|null>(subscriber => {
const unsubscribe = this.auth.onIdTokenChanged(subscriber);
return { unsubscribe };
}).switchMap(user => {
Expand All @@ -45,4 +44,4 @@ export class AngularFireAuth {
this.idToken = observeOn.call(idToken$, new ZoneScheduler(Zone.current));
}

}
}
9 changes: 5 additions & 4 deletions src/core/angularfire2.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as firebase from 'firebase/app';

import { Reference } from '@firebase/database-types';
import { TestBed, inject, withModule, async } from '@angular/core/testing';
import { ReflectiveInjector, Provider, PlatformRef, NgModule, Compiler, ApplicationRef, CompilerFactory } from '@angular/core';
import { FirebaseApp, FirebaseAppConfig, AngularFireModule } from 'angularfire2';
Expand All @@ -9,9 +10,9 @@ import { BrowserModule } from '@angular/platform-browser';
describe('angularfire', () => {
let subscription:Subscription;
let app: FirebaseApp;
let rootRef: firebase.database.Reference;
let questionsRef: firebase.database.Reference;
let listOfQuestionsRef: firebase.database.Reference;
let rootRef: Reference;
let questionsRef: Reference;
let listOfQuestionsRef: Reference;
let defaultPlatform: PlatformRef;

const APP_NAME = 'super-awesome-test-firebase-app-name';
Expand Down
1 change: 0 additions & 1 deletion src/core/angularfire2.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import * as firebase from 'firebase/app';
import { FirebaseAppConfigToken, FirebaseApp, _firebaseAppFactory } from './firebase.app.module';
import { Injectable, InjectionToken, NgModule } from '@angular/core';
import { Subscription } from 'rxjs/Subscription';
Expand Down
21 changes: 14 additions & 7 deletions src/core/firebase.app.module.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
import { InjectionToken, } from '@angular/core';
import { FirebaseAppConfig } from './';
import * as firebase from 'firebase/app';
import firebase from '@firebase/app';

import { FirebaseApp as FBApp } 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 const FirebaseAppConfigToken = new InjectionToken<FirebaseAppConfig>('FirebaseAppConfigToken');

export class FirebaseApp implements firebase.app.App {
export class FirebaseApp implements FBApp {
name: string;
options: {};
auth: () => firebase.auth.Auth;
database: () => firebase.database.Database;
messaging: () => firebase.messaging.Messaging;
storage: () => firebase.storage.Storage;
auth: () => FirebaseAuth;
database: () => FirebaseDatabase;
messaging: () => FirebaseMessaging;
storage: () => FirebaseStorage;
delete: () => Promise<any>;
firestore: () => firebase.firestore.Firestore;
firestore: () => FirebaseFirestore;
}

export function _firebaseAppFactory(config: FirebaseAppConfig, appName?: string): FirebaseApp {
Expand Down
2 changes: 0 additions & 2 deletions src/database-deprecated/database.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { NgModule } from '@angular/core';
import * as firebase from 'firebase/app';
import 'firebase/database';
import { AngularFireModule, FirebaseApp } from 'angularfire2';
import { AngularFireDatabase } from './database';

Expand Down
7 changes: 3 additions & 4 deletions src/database-deprecated/database.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import * as firebase from 'firebase/app';
import 'firebase/database';
import { FirebaseDatabase } from '@firebase/database-types';
import { Inject, Injectable } from '@angular/core';
import { FirebaseAppConfigToken, FirebaseAppConfig, FirebaseApp } from 'angularfire2';
import { FirebaseListFactory } from './firebase_list_factory';
Expand All @@ -15,8 +14,8 @@ export class AngularFireDatabase {
/**
* Firebase Database instance
*/
database: firebase.database.Database;
database: FirebaseDatabase;

constructor(public app: FirebaseApp) {
this.database = app.database();
}
Expand Down
16 changes: 8 additions & 8 deletions src/database-deprecated/firebase_list_factory.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as firebase from 'firebase/app';
import { DataSnapshot } from '@firebase/database-types';
import { FirebaseApp, FirebaseAppConfig, AngularFireModule} from 'angularfire2';
import { AngularFireDatabase, AngularFireDatabaseModule, FirebaseListObservable,
FirebaseListFactory, onChildAdded, onChildChanged, onChildRemoved, onChildUpdated,
FirebaseObjectFactory
import { AngularFireDatabase, AngularFireDatabaseModule, FirebaseListObservable,
FirebaseListFactory, onChildAdded, onChildChanged, onChildRemoved, onChildUpdated,
FirebaseObjectFactory
} from 'angularfire2/database-deprecated';
import { TestBed, inject } from '@angular/core/testing';
import * as utils from './utils';
Expand Down Expand Up @@ -652,15 +652,15 @@ describe('FirebaseListFactory', () => {
};

it('should return an object value with a $key property', () => {
const unwrapped = utils.unwrapMapFn(snapshot as firebase.database.DataSnapshot);
const unwrapped = utils.unwrapMapFn(snapshot as DataSnapshot);
expect(unwrapped.$key).toEqual(snapshot.ref.key);
});

it('should return an object value with a $value property if value is scalar', () => {
const existsFn = () => { return true; }
const unwrappedValue5 = utils.unwrapMapFn(Object.assign(snapshot, { val: () => 5, exists: existsFn }) as firebase.database.DataSnapshot);
const unwrappedValueFalse = utils.unwrapMapFn(Object.assign(snapshot, { val: () => false, exists: existsFn }) as firebase.database.DataSnapshot);
const unwrappedValueLol = utils.unwrapMapFn(Object.assign(snapshot, { val: () => 'lol', exists: existsFn }) as firebase.database.DataSnapshot);
const unwrappedValue5 = utils.unwrapMapFn(Object.assign(snapshot, { val: () => 5, exists: existsFn }) as DataSnapshot);
const unwrappedValueFalse = utils.unwrapMapFn(Object.assign(snapshot, { val: () => false, exists: existsFn }) as DataSnapshot);
const unwrappedValueLol = utils.unwrapMapFn(Object.assign(snapshot, { val: () => 'lol', exists: existsFn }) as DataSnapshot);

expect(unwrappedValue5.$key).toEqual('key');
expect(unwrappedValue5.$value).toEqual(5);
Expand Down
7 changes: 3 additions & 4 deletions src/database-deprecated/firebase_list_factory.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import * as firebase from 'firebase/app';
import * as database from '@firebase/database-types';
import { ZoneScheduler } from 'angularfire2';
import * as utils from './utils';
import 'firebase/database';
import { AFUnwrappedDataSnapshot } from './interfaces';
import { FirebaseListObservable } from './firebase_list_observable';
import { Observer } from 'rxjs/Observer';
Expand Down Expand Up @@ -92,7 +91,7 @@ export function FirebaseListFactory (
}

return queried;
}), (queryRef: firebase.database.Reference, ix: number) => {
}), (queryRef: database.Reference, ix: number) => {
return firebaseListObservable(queryRef, { preserveSnapshot });
})
.subscribe(subscriber);
Expand All @@ -108,7 +107,7 @@ export function FirebaseListFactory (
* asynchonous. It creates a initial array from a promise of ref.once('value'), and then starts
* listening to child events. When the initial array is loaded, the observable starts emitting values.
*/
function firebaseListObservable(ref: firebase.database.Reference | DatabaseQuery, {preserveSnapshot}: FirebaseListFactoryOpts = {}): FirebaseListObservable<any> {
function firebaseListObservable(ref: database.Reference | DatabaseQuery, {preserveSnapshot}: FirebaseListFactoryOpts = {}): FirebaseListObservable<any> {

const toValue = preserveSnapshot ? (snapshot => snapshot) : utils.unwrapMapFn;
const toKey = preserveSnapshot ? (value => value.key) : (value => value.$key);
Expand Down
Loading