Skip to content

Commit

Permalink
chore(): lean only on firebase types and compatibility with 5.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdaniels committed Jun 13, 2018
1 parent a42a84f commit eed5802
Show file tree
Hide file tree
Showing 20 changed files with 420 additions and 449 deletions.
2 changes: 1 addition & 1 deletion docs/auth/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ the Firebase docs for more information on what methods are available.](https://f
```ts
import { Component } from '@angular/core';
import { AngularFireAuth } from 'angularfire2/auth';
import { auth } from 'firebase/app';
import { auth } from 'firebase';

@Component({
selector: 'app-root',
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"@angular/core": "^6.0.0",
"@angular/platform-browser": "^6.0.0",
"@angular/platform-browser-dynamic": "^6.0.0",
"firebase": "^5.0.3",
"bufferutil": "^3.0.3",
"firebase": "^5.0.3",
"rxjs": "^6.0.0",
"utf-8-validate": "^4.0.0",
"ws": "^3.3.2",
Expand Down
2 changes: 1 addition & 1 deletion src/auth/auth.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { User } from 'firebase/app';
import { User } from 'firebase';
import { ReflectiveInjector, Provider } from '@angular/core';
import { Observable, Subject } from 'rxjs'
import { TestBed, inject } from '@angular/core/testing';
Expand Down
2 changes: 1 addition & 1 deletion src/auth/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Observable, of, from } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { FirebaseAppConfig, FirebaseOptions } from 'angularfire2';

import { User, auth } from 'firebase/app';
import { User, auth } from 'firebase';

import { FirebaseAuth, FirebaseOptionsToken, FirebaseNameOrConfigToken, _firebaseAppFactory, FirebaseZoneScheduler } from 'angularfire2';

Expand Down
2 changes: 1 addition & 1 deletion src/core/angularfire2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FirebaseApp, AngularFireModule } from 'angularfire2';
import { Subscription } from 'rxjs';
import { COMMON_CONFIG } from './test-config';
import { BrowserModule } from '@angular/platform-browser';
import { database } from 'firebase/app';
import { database } from 'firebase';

describe('angularfire', () => {
let subscription:Subscription;
Expand Down
7 changes: 4 additions & 3 deletions src/core/firebase.app.module.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { InjectionToken, NgZone, NgModule, Optional } from '@angular/core';
import { app, auth, apps, database, firestore, functions, initializeApp, messaging, storage } from 'firebase/app';
import { app, auth, database, firestore, functions, messaging, storage } from 'firebase';
import * as firebase from 'firebase/app';

// Public types don't expose FirebaseOptions or FirebaseAppConfig
export type FirebaseOptions = {[key:string]: any};
Expand Down Expand Up @@ -34,9 +35,9 @@ export function _firebaseAppFactory(options: FirebaseOptions, nameOrConfig?: str
const name = typeof nameOrConfig === 'string' && nameOrConfig || '[DEFAULT]';
const config = typeof nameOrConfig === 'object' && nameOrConfig || {};
config.name = config.name || name;
const existingApp = apps.filter(app => app && app.name === config.name)[0];
const existingApp = firebase.apps.filter(app => app && app.name === config.name)[0];
// We support FirebaseConfig, initializeApp's public type only accepts string; need to cast as any
return (existingApp || (initializeApp as any)(options, config)) as FirebaseApp;
return (existingApp || firebase.initializeApp(options, <any>config)) as FirebaseApp;
}

const FirebaseAppProvider = {
Expand Down
4 changes: 2 additions & 2 deletions src/database-deprecated/firebase_list_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function firebaseListObservable(ref: Reference | DatabaseQuery, {preserveSnapsho
snap.forEach((child: any) => {
lastLoadedKey = child.key;
});
if (array.find((child: any) => toKey(child) === lastLoadedKey)) {
if ((<any>array).find((child: any) => toKey(child) === lastLoadedKey)) {
hasLoaded = true;
obs.next(array);
}
Expand Down Expand Up @@ -177,7 +177,7 @@ function firebaseListObservable(ref: Reference | DatabaseQuery, {preserveSnapsho
// The Firebase SDK requires the reference, event name, and callback to
// properly unsubscribe, otherwise it can affect other subscriptions.
handles.forEach(item => {
ref.off(item.event, item.handle);
ref.off(item.event as any, item.handle);
});
};

Expand Down
2 changes: 1 addition & 1 deletion src/database-deprecated/firebase_object_observable.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Observable, Operator, Subscriber, Subscription } from 'rxjs';
import { Reference } from './interfaces';
import { database } from 'firebase/app';
import { database } from 'firebase';

export class FirebaseObjectObservable<T> extends Observable<T> {
constructor(subscribe?: <R>(subscriber: Subscriber<R>) => Subscription | Function | void, public $ref?:Reference) {
Expand Down
2 changes: 1 addition & 1 deletion src/database-deprecated/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Observable } from 'rxjs';
import { database } from 'firebase/app';
import { database } from 'firebase';

export type Reference = database.Reference;
export type DataSnapshot = database.DataSnapshot;
Expand Down
2 changes: 1 addition & 1 deletion src/database/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Observable } from 'rxjs';
import { database } from 'firebase/app';
import { database } from 'firebase';

export type FirebaseOperation = string | database.Reference | database.DataSnapshot;

Expand Down
4 changes: 2 additions & 2 deletions src/database/list/changes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Reference } from 'firebase/database-types';
import { database } from 'firebase';
import { FirebaseApp, AngularFireModule } from 'angularfire2';
import { AngularFireDatabase, AngularFireDatabaseModule, listChanges } from 'angularfire2/database';
import { TestBed, inject } from '@angular/core/testing';
Expand All @@ -12,7 +12,7 @@ const FIREBASE_APP_NAME = rando();
describe('listChanges', () => {
let app: FirebaseApp;
let db: AngularFireDatabase;
let ref: (path: string) => Reference;
let ref: (path: string) => database.Reference;
let batch = {};
const items = [{ name: 'zero' }, { name: 'one' }, { name: 'two' }].map((item, i) => ( { key: i.toString(), ...item } ));
Object.keys(items).forEach(function (key, i) {
Expand Down
3 changes: 1 addition & 2 deletions src/database/list/remove.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { DatabaseReference, DataSnapshot, FirebaseOperation, DatabaseSnapshot } from '../interfaces';
import { checkOperationCases } from '../utils';
import { createDataOperationMethod } from './data-operation';
import { database } from 'firebase/app';
import { database } from 'firebase';

// TODO(davideast): Find out why TS thinks this returns firebase.Primise
// instead of Promise.
Expand Down
4 changes: 2 additions & 2 deletions src/database/list/snapshot-changes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Reference } from 'firebase/database-types';
import { database } from 'firebase';
import { FirebaseApp, AngularFireModule } from 'angularfire2';
import { AngularFireDatabase, AngularFireDatabaseModule, snapshotChanges, ChildEvent } from 'angularfire2/database';
import { TestBed, inject } from '@angular/core/testing';
Expand All @@ -13,7 +13,7 @@ const FIREBASE_APP_NAME = rando();
describe('snapshotChanges', () => {
let app: FirebaseApp;
let db: AngularFireDatabase;
let createRef: (path: string) => Reference;
let createRef: (path: string) => database.Reference;
let batch = {};
const items = [{ name: 'zero' }, { name: 'one' }, { name: 'two' }].map((item, i) => ( { key: i.toString(), ...item } ));
Object.keys(items).forEach(function (key, i) {
Expand Down
4 changes: 2 additions & 2 deletions src/database/list/state-changes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Reference } from 'firebase/database-types';
import { database } from 'firebase';
import { FirebaseApp, AngularFireModule } from 'angularfire2';
import { AngularFireDatabase, AngularFireDatabaseModule, stateChanges, ChildEvent } from 'angularfire2/database';
import { TestBed, inject } from '@angular/core/testing';
Expand All @@ -12,7 +12,7 @@ const FIREBASE_APP_NAME = rando();
describe('stateChanges', () => {
let app: FirebaseApp;
let db: AngularFireDatabase;
let createRef: (path: string) => Reference;
let createRef: (path: string) => database.Reference;
let batch = {};
const items = [{ name: 'zero' }, { name: 'one' }, { name: 'two' }].map((item, i) => ( { key: i.toString(), ...item } ));
Object.keys(items).forEach(function (key, i) {
Expand Down
6 changes: 3 additions & 3 deletions src/firestore/firestore.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { InjectionToken, NgZone, PLATFORM_ID, Injectable, Inject, Optional } from '@angular/core';

import { Observable, Subscriber, of, from } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { firestore } from 'firebase/app';
import { Observable, of, from } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { firestore } from 'firebase';

import { Settings, CollectionReference, DocumentReference, QueryFn, AssociatedReference } from './interfaces';
import { AngularFirestoreDocument } from './document/document';
Expand Down
2 changes: 1 addition & 1 deletion src/firestore/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Subscriber } from 'rxjs';
import { firestore } from 'firebase/app';
import { firestore } from 'firebase';

export type Settings = firestore.Settings;
export type CollectionReference = firestore.CollectionReference;
Expand Down
4 changes: 2 additions & 2 deletions src/firestore/utils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { FirebaseFirestore, CollectionReference } from 'firebase/firestore-types';
import { firestore } from 'firebase';
import { AngularFirestoreCollection } from './collection/collection';

export interface Stock {
Expand All @@ -10,7 +10,7 @@ export const FAKE_STOCK_DATA = { name: 'FAKE', price: 1 };

export const randomName = (firestore): string => firestore.collection('a').doc().id;

export const createRandomStocks = async (firestore: FirebaseFirestore, collectionRef: CollectionReference, numberOfItems) => {
export const createRandomStocks = async (firestore: firestore.Firestore, collectionRef: firestore.CollectionReference, numberOfItems) => {
// Create a batch to update everything at once
const batch = firestore.batch();
// Store the random names to delete them later
Expand Down
2 changes: 1 addition & 1 deletion src/storage/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { storage } from 'firebase/app';
import { storage } from 'firebase';

export type UploadTask = storage.UploadTask;
export type UploadTaskSnapshot = storage.UploadTaskSnapshot;
Expand Down
2 changes: 1 addition & 1 deletion src/storage/observable/fromTask.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Observable } from 'rxjs';
import { UploadTask, UploadTaskSnapshot } from '../interfaces';
import { storage } from 'firebase/app';
import { storage } from 'firebase';

export function fromTask(task: UploadTask) {
return new Observable<UploadTaskSnapshot>(subscriber => {
Expand Down
Loading

0 comments on commit eed5802

Please sign in to comment.