11import * as firebase from 'firebase/app' ;
22import * as utils from './utils' ;
3- import { FirebaseAppConfig } from './interfaces' ;
4- import { AuthConfiguration } from './auth' ;
5- import {
6- FirebaseListFactoryOpts ,
7- FirebaseObjectFactoryOpts ,
8- } from './interfaces' ;
9- import {
10- FirebaseConfig ,
11- FirebaseApp ,
12- WindowLocation ,
13- FirebaseUserConfig ,
14- FirebaseAuthConfig ,
15- FirebaseAppName
16- } from './tokens' ;
17- import {
18- APP_INITIALIZER ,
19- Inject ,
20- Injectable ,
21- OpaqueToken ,
22- NgModule ,
23- ModuleWithProviders
24- } from '@angular/core' ;
25- import {
26- FirebaseSdkAuthBackend ,
27- AngularFireAuth ,
28- firebaseAuthConfig ,
29- AuthBackend ,
30- AuthMethods ,
31- AuthProviders ,
32- FirebaseAuthState
33- } from './auth/index' ;
34- import {
35- FirebaseListObservable ,
36- FirebaseObjectObservable ,
37- FirebaseListFactory ,
38- FirebaseObjectFactory ,
39- AngularFireDatabase
40- } from './database/index' ;
3+ import { FirebaseListFactoryOpts , FirebaseObjectFactoryOpts , FirebaseAppConfig } from './interfaces' ;
4+ import { FirebaseAppName } from './tokens' ;
5+ import { Injectable , OpaqueToken , NgModule , ModuleWithProviders } from '@angular/core' ;
6+ import { FirebaseListObservable , FirebaseObjectObservable , FirebaseListFactory , FirebaseObjectFactory , AngularFireDatabase } from './database/index' ;
417
428@Injectable ( )
439export class AngularFire {
44- constructor (
45- @Inject ( FirebaseConfig ) private firebaseConfig :FirebaseAppConfig ,
46- public auth : AngularFireAuth ,
47- public database : AngularFireDatabase ) { }
10+ constructor ( public database : AngularFireDatabase ) { }
4811}
4912
50- export function _getFirebase ( config : FirebaseAppConfig , appName ?: string ) : firebase . app . App {
13+ export function _getFirebase ( config : FirebaseAppConfig , appName ?: string ) : FirebaseApp {
5114 try {
5215 if ( appName ) {
5316 return firebase . initializeApp ( config , appName ) ;
@@ -60,86 +23,75 @@ export function _getFirebase(config: FirebaseAppConfig, appName?: string): fireb
6023 }
6124}
6225
63- export function _getWindowLocation ( ) {
64- return window . location ;
26+ export const FirebaseAppConfigToken = new OpaqueToken ( 'FirebaseAppConfigToken' ) ;
27+
28+ @Injectable ( )
29+ export class FirebaseApp {
30+ name : string ;
31+ options : { } ;
32+ auth : ( ) => firebase . auth . Auth ;
33+ database : ( ) => firebase . database . Database ;
34+ messaging : ( ) => firebase . messaging . Messaging ;
35+ storage : ( ) => firebase . storage . Storage ;
36+ delete : ( ) => firebase . Promise < any > ;
6537}
6638
67- export function _getAuthBackend ( app : firebase . app . App ) : FirebaseSdkAuthBackend {
68- return new FirebaseSdkAuthBackend ( app ) ;
39+ export function _getAngularFire ( db : AngularFireDatabase ) {
40+ return new AngularFire ( db ) ;
6941}
7042
71- export function _getDefaultFirebase ( config ) {
72- // remove a trailing slash from the Database URL if it exists
73- config . databaseURL = utils . stripTrailingSlash ( config . databaseURL ) ;
74- return config ;
43+ export function _getAngularFireDatabase ( app : FirebaseApp ) {
44+ return new AngularFireDatabase ( app ) ;
7545}
7646
77- export const COMMON_PROVIDERS : any [ ] = [
78- {
79- provide : FirebaseApp ,
80- useFactory : _getFirebase ,
81- deps : [ FirebaseConfig , FirebaseAppName ]
82- } ,
83- AngularFireAuth ,
84- AngularFire ,
85- AngularFireDatabase
86- ] ;
47+ export const FirebaseAppProvider = {
48+ provide : FirebaseApp ,
49+ useFactory : _getFirebase ,
50+ deps : [ FirebaseAppConfigToken , FirebaseAppName ]
51+ } ;
52+
53+ export const AngularFireDatabaseProvider = {
54+ provide : AngularFireDatabase ,
55+ useFactory : _getAngularFireDatabase ,
56+ deps : [ FirebaseApp ]
57+ } ;
58+
59+ export const AngularFireProvider = {
60+ provide : AngularFire ,
61+ useFactory : _getAngularFire ,
62+ deps : [ AngularFireDatabase ]
63+ } ;
8764
8865export const FIREBASE_PROVIDERS :any [ ] = [
89- COMMON_PROVIDERS ,
90- {
91- provide : AuthBackend ,
92- useFactory : _getAuthBackend ,
93- deps : [ FirebaseApp ]
94- } ,
95- {
96- provide : WindowLocation ,
97- useFactory : _getWindowLocation
98- } ,
66+ FirebaseAppProvider ,
67+ AngularFireDatabaseProvider ,
68+ AngularFireProvider
9969] ;
10070
101- /**
102- * Used to define the default Firebase root location to be
103- * used throughout an application.
104- */
105- export const defaultFirebase = ( config : FirebaseAppConfig ) : any => {
106- return [
107- { provide : FirebaseUserConfig , useValue : config } ,
108- { provide : FirebaseConfig , useFactory : _getDefaultFirebase , deps : [ FirebaseUserConfig ] }
109- ]
110- } ;
71+ export {
72+ AngularFireDatabase ,
73+ FirebaseListObservable ,
74+ FirebaseObjectObservable ,
75+ FirebaseListFactory ,
76+ FirebaseObjectFactory
77+ }
78+
79+ export { FirebaseConfig , FirebaseAuthConfig , FirebaseRef , FirebaseUrl , FirebaseUserConfig } from './tokens' ;
80+ export { FirebaseAppConfig } from './interfaces' ;
11181
11282@NgModule ( {
113- providers : FIREBASE_PROVIDERS
83+ providers : [ FIREBASE_PROVIDERS ]
11484} )
11585export class AngularFireModule {
116- static initializeApp ( config : FirebaseAppConfig , authConfig ?: AuthConfiguration , appName ?: string ) : ModuleWithProviders {
86+ static initializeApp ( config , authConfig ?, appName ?) : ModuleWithProviders {
11787 return {
11888 ngModule : AngularFireModule ,
11989 providers : [
120- { provide : FirebaseUserConfig , useValue : config } ,
121- { provide : FirebaseConfig , useFactory : _getDefaultFirebase , deps : [ FirebaseUserConfig ] } ,
122- { provide : FirebaseAuthConfig , useValue : authConfig } ,
123- { provide : FirebaseAppName , useValue : appName }
90+ { provide : FirebaseAppConfigToken , useValue : config } ,
91+ { provide : FirebaseAppName , useValue : appName } ,
92+ FirebaseAppProvider ,
12493 ]
12594 }
12695 }
12796}
12897
129- export {
130- AngularFireAuth ,
131- AngularFireDatabase ,
132- FirebaseListObservable ,
133- FirebaseObjectObservable ,
134- FirebaseListFactory ,
135- FirebaseObjectFactory ,
136- firebaseAuthConfig ,
137- FirebaseAuthState ,
138- AuthMethods ,
139- AuthProviders ,
140- WindowLocation
141- }
142-
143- export { FirebaseConfig , FirebaseApp , FirebaseAuthConfig , FirebaseRef , FirebaseUrl , FirebaseUserConfig } from './tokens' ;
144- export { FirebaseAppConfig } from './interfaces' ;
145-
0 commit comments