-
Notifications
You must be signed in to change notification settings - Fork 2.2k
runOutsideAngular for Universal compatibility and allow advanced configuration with DI #1454
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
+1,878
−1,414
Merged
Changes from 12 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
fa34c8e
First.
jamesdaniels 3121b94
SSR work
jamesdaniels 440b5e6
StorageBucket is a string...
jamesdaniels 6e86fc7
Add AngularFireModule back in
jamesdaniels 331de24
Fix up storage and the tests
jamesdaniels 2700a36
Merge branch 'master' into providers_and_di
jamesdaniels b9cc132
Adding StorageBucket and DatabaseURL DI tests
jamesdaniels 63a94f9
Adding specs for DI in auth + firestore
jamesdaniels a77b21d
More complete tests + fixed the storage test config
jamesdaniels 32ed0a5
Adding app.module back in and writing tests for app injection
jamesdaniels 345e23c
Export RealtimeDatabaseURL from database-deprecated
jamesdaniels ee36144
Export FirebaseApp
jamesdaniels 0c0569e
Working, needs wrapper
jamesdaniels e68d66a
More
jamesdaniels 7d35667
Merge branch 'master' into providers_and_di
davideast a563f3f
Merge and tests
jamesdaniels 5df96ef
State changes and auditlog
jamesdaniels b1be1f5
Wrap auth
jamesdaniels c20d10e
Reverted database-depricated a bit
jamesdaniels 7287f01
More cleanup
jamesdaniels c995ee5
Cleanup unused imports
jamesdaniels File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,9 @@ | ||
import { NgModule, NgZone } from '@angular/core'; | ||
import { FirebaseApp, AngularFireModule } from 'angularfire2'; | ||
import { NgModule } from '@angular/core'; | ||
import { AngularFireAuth } from './auth'; | ||
import '@firebase/auth'; | ||
|
||
export function _getAngularFireAuth(app: FirebaseApp) { | ||
return new AngularFireAuth(app); | ||
} | ||
|
||
export const AngularFireAuthProvider = { | ||
provide: AngularFireAuth, | ||
useFactory: _getAngularFireAuth, | ||
deps: [ FirebaseApp ] | ||
}; | ||
|
||
export const AUTH_PROVIDERS = [ | ||
AngularFireAuthProvider, | ||
]; | ||
import { FirebaseApp } from '@firebase/app-types' | ||
|
||
@NgModule({ | ||
imports: [ AngularFireModule ], | ||
providers: [ AUTH_PROVIDERS ] | ||
providers: [ AngularFireAuth ] | ||
}) | ||
export class AngularFireAuthModule { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,20 @@ | ||
import { FirebaseAppConfigToken, FirebaseApp, _firebaseAppFactory } from './firebase.app.module'; | ||
import { Injectable, InjectionToken, NgModule } from '@angular/core'; | ||
import { InjectionToken, NgZone } from '@angular/core'; | ||
import { Subscription } from 'rxjs/Subscription'; | ||
import { Scheduler } from 'rxjs/Scheduler'; | ||
import { queue } from 'rxjs/scheduler/queue'; | ||
|
||
export interface FirebaseAppConfig { | ||
apiKey?: string; | ||
authDomain?: string; | ||
databaseURL?: string; | ||
storageBucket?: string; | ||
messagingSenderId?: string; | ||
projectId?: string; | ||
} | ||
import firebase from '@firebase/app'; | ||
import { FirebaseApp, FirebaseOptions } from '@firebase/app-types'; | ||
|
||
const FirebaseAppName = new InjectionToken<string>('FirebaseAppName'); | ||
export const FirebaseAppName = new InjectionToken<string>('angularfire2.appName'); | ||
export const FirebaseAppConfig = new InjectionToken<FirebaseOptions>('angularfire2.config'); | ||
|
||
export const FirebaseAppProvider = { | ||
provide: FirebaseApp, | ||
useFactory: _firebaseAppFactory, | ||
deps: [ FirebaseAppConfigToken, FirebaseAppName ] | ||
}; | ||
|
||
@NgModule({ | ||
providers: [ FirebaseAppProvider ], | ||
}) | ||
export class AngularFireModule { | ||
static initializeApp(config: FirebaseAppConfig, appName?: string) { | ||
return { | ||
ngModule: AngularFireModule, | ||
providers: [ | ||
{ provide: FirebaseAppConfigToken, useValue: config }, | ||
{ provide: FirebaseAppName, useValue: appName } | ||
] | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* TODO: remove this scheduler once Rx has a more robust story for working | ||
* with zones. | ||
*/ | ||
export class ZoneScheduler { | ||
|
||
// TODO: Correctly add ambient zone typings instead of using any. | ||
constructor(public zone: any) {} | ||
// Put in database.ts when we drop database-depreciated | ||
export const RealtimeDatabaseURL = new InjectionToken<string>('angularfire2.realtimeDatabaseURL'); | ||
|
||
export class FirebaseZoneScheduler { | ||
constructor(public zone: NgZone) {} | ||
schedule(...args: any[]): Subscription { | ||
return <Subscription>this.zone.run(() => queue.schedule.apply(queue, args)); | ||
return <Subscription>this.zone.runGuarded(function() { return queue.schedule.apply(queue, args)}); | ||
} | ||
} | ||
|
||
export { FirebaseApp, FirebaseAppName, FirebaseAppConfigToken }; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,49 @@ | ||
import { InjectionToken, } from '@angular/core'; | ||
import { FirebaseAppConfig } from './'; | ||
import firebase from '@firebase/app'; | ||
import { InjectionToken, NgZone, NgModule } from '@angular/core'; | ||
|
||
import { FirebaseAppConfig, FirebaseAppName } from './angularfire2'; | ||
|
||
import { FirebaseApp as FBApp } from '@firebase/app-types'; | ||
import firebase from '@firebase/app'; | ||
import { FirebaseApp as _FirebaseApp, FirebaseOptions } 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 _FirebaseApp { | ||
name: string; | ||
options: {}; | ||
auth: () => FirebaseAuth; | ||
database: (databaseURL?: string) => FirebaseDatabase; | ||
messaging: () => FirebaseMessaging; | ||
storage: (storageBucket?: string) => FirebaseStorage; | ||
delete: () => Promise<void>; | ||
firestore: () => FirebaseFirestore; | ||
} | ||
|
||
export class FirebaseApp implements FBApp { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would still like for us to provide the |
||
name: string; | ||
options: {}; | ||
auth: () => FirebaseAuth; | ||
database: () => FirebaseDatabase; | ||
messaging: () => FirebaseMessaging; | ||
storage: () => FirebaseStorage; | ||
delete: () => Promise<any>; | ||
firestore: () => FirebaseFirestore; | ||
export function _firebaseAppFactory(config: FirebaseOptions, name?: string): FirebaseApp { | ||
const appName = name || '[DEFAULT]'; | ||
const existingApp = firebase.apps.filter(app => app.name == appName)[0] as FirebaseApp; | ||
return existingApp || firebase.initializeApp(config, appName) as FirebaseApp; | ||
} | ||
|
||
export function _firebaseAppFactory(config: FirebaseAppConfig, appName?: string): FirebaseApp { | ||
try { | ||
if (appName) { | ||
return firebase.initializeApp(config, appName) as FirebaseApp; | ||
} else { | ||
return firebase.initializeApp(config) as FirebaseApp; | ||
const FirebaseAppProvider = { | ||
provide: FirebaseApp, | ||
useFactory: _firebaseAppFactory, | ||
deps: [ FirebaseAppConfig, FirebaseAppName ] | ||
}; | ||
|
||
@NgModule({ | ||
providers: [ FirebaseAppProvider ], | ||
}) | ||
export class AngularFireModule { | ||
static initializeApp(config: FirebaseOptions, appName?: string) { | ||
return { | ||
ngModule: AngularFireModule, | ||
providers: [ | ||
{ provide: FirebaseAppConfig, useValue: config }, | ||
{ provide: FirebaseAppName, useValue: appName } | ||
] | ||
} | ||
} | ||
} | ||
catch (e) { | ||
if (e.code === "app/duplicate-app") { | ||
return firebase.app(e.name) as FirebaseApp; | ||
} | ||
|
||
return firebase.app(null!) as FirebaseApp; | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './angularfire2'; | ||
export * from './angularfire2'; | ||
export * from './firebase.app.module'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,9 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { AngularFireModule, FirebaseApp } from 'angularfire2'; | ||
import { FirebaseApp } from '@firebase/app-types'; | ||
import { AngularFireDatabase } from './database'; | ||
import '@firebase/database'; | ||
|
||
export function _getAngularFireDatabase(app: FirebaseApp) { | ||
return new AngularFireDatabase(app); | ||
} | ||
|
||
export const AngularFireDatabaseProvider = { | ||
provide: AngularFireDatabase, | ||
useFactory: _getAngularFireDatabase, | ||
deps: [ FirebaseApp ] | ||
}; | ||
|
||
export const DATABASE_PROVIDERS = [ | ||
AngularFireDatabaseProvider, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [ AngularFireModule ], | ||
providers: [ DATABASE_PROVIDERS ] | ||
providers: [ AngularFireDatabase ] | ||
}) | ||
export class AngularFireDatabaseModule { } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of removing the
AngularFireModule
in place of making people do their own providers. I also like having theFirebaseApp
as an injectable.