forked from angular/angularfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from angular/master
Update upstream
- Loading branch information
Showing
38 changed files
with
1,878 additions
and
1,414 deletions.
There are no files selected for viewing
This file contains 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 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,8 @@ | ||
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, | ||
]; | ||
|
||
@NgModule({ | ||
imports: [ AngularFireModule ], | ||
providers: [ AUTH_PROVIDERS ] | ||
providers: [ AngularFireAuth ] | ||
}) | ||
export class AngularFireAuthModule { } |
This file contains 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 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 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 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,42 @@ | ||
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 { Observable } from 'rxjs/Observable'; | ||
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'); | ||
import 'zone.js'; | ||
import 'rxjs/add/operator/first'; | ||
import { Subscriber } from 'rxjs/Subscriber'; | ||
import { observeOn } from 'rxjs/operator/observeOn'; | ||
|
||
export const FirebaseAppProvider = { | ||
provide: FirebaseApp, | ||
useFactory: _firebaseAppFactory, | ||
deps: [ FirebaseAppConfigToken, FirebaseAppName ] | ||
}; | ||
export const FirebaseAppName = new InjectionToken<string>('angularfire2.appName'); | ||
export const FirebaseAppConfig = new InjectionToken<FirebaseOptions>('angularfire2.config'); | ||
|
||
@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 }; | ||
// TODO this is a hack, clean it up | ||
keepUnstableUntilFirst<T>(obs$: Observable<T>) { | ||
return new Observable<T>(subscriber => { | ||
const noop = () => {}; | ||
const task = Zone.current.scheduleMacroTask('firebaseZoneBlock', noop, {}, noop, noop); | ||
obs$.first().subscribe(() => this.zone.runOutsideAngular(() => task.invoke())); | ||
return obs$.subscribe(subscriber); | ||
}); | ||
} | ||
runOutsideAngular<T>(obs$: Observable<T>): Observable<T> { | ||
const outsideAngular = new Observable<T>(subscriber => { | ||
return this.zone.runOutsideAngular(() => { | ||
return obs$.subscribe(subscriber); | ||
}); | ||
}); | ||
return observeOn.call(outsideAngular, this); | ||
} | ||
} |
This file contains 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 { | ||
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 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'; |
Oops, something went wrong.