[js] move auth statics

This commit is contained in:
Salakar 2017-03-27 19:11:26 +01:00
parent 2ae3003597
commit 86512320f0
2 changed files with 13 additions and 12 deletions

View File

@ -8,7 +8,7 @@ import Log from './utils/log';
import { isObject } from './utils'; import { isObject } from './utils';
// modules // modules
import Auth from './modules/auth'; import Auth, { statics as AuthStatics } from './modules/auth';
import Storage, { statics as StorageStatics } from './modules/storage'; import Storage, { statics as StorageStatics } from './modules/storage';
import Database, { statics as DatabaseStatics } from './modules/database'; import Database, { statics as DatabaseStatics } from './modules/database';
import Messaging from './modules/messaging'; import Messaging from './modules/messaging';
@ -54,8 +54,12 @@ export default class Firebase {
throw new Error(`Google Play Services is required to run this application but no valid installation was found (Code ${this.googleApiAvailability.status}).`); throw new Error(`Google Play Services is required to run this application but no valid installation was found (Code ${this.googleApiAvailability.status}).`);
} }
this.auth = this._staticsOrInstance('auth', StorageStatics, Auth);
this.storage = this._staticsOrInstance('storage', StorageStatics, Storage); this.storage = this._staticsOrInstance('storage', StorageStatics, Storage);
this.database = this._staticsOrInstance('database', DatabaseStatics, Database); this.database = this._staticsOrInstance('database', DatabaseStatics, Database);
// init auth to stat listeners
this.auth();
} }
/** /**
@ -81,10 +85,6 @@ export default class Firebase {
return instances[name]; return instances[name];
} }
auth() {
return this._auth;
}
analytics() { analytics() {
if (!this._analytics) { if (!this._analytics) {
this._analytics = new Analytics(this); this._analytics = new Analytics(this);

View File

@ -25,13 +25,6 @@ export default class Auth extends Base {
this._authResult = null; this._authResult = null;
this.authenticated = false; this.authenticated = false;
// attach auth providers
this.EmailAuthProvider = EmailAuthProvider;
this.GoogleAuthProvider = GoogleAuthProvider;
this.FacebookAuthProvider = FacebookAuthProvider;
this.TwitterAuthProvider = TwitterAuthProvider;
this.GithubAuthProvider = GithubAuthProvider;
// start listening immediately for auth changes // start listening immediately for auth changes
FirebaseAuthEvt.addListener('onAuthStateChanged', this._onAuthStateChanged.bind(this)); FirebaseAuthEvt.addListener('onAuthStateChanged', this._onAuthStateChanged.bind(this));
FirebaseAuth.addAuthStateListener(); FirebaseAuth.addAuthStateListener();
@ -175,3 +168,11 @@ export default class Auth extends Base {
return 'firebase:auth'; return 'firebase:auth';
} }
} }
export const statics = {
GoogleAuthProvider,
EmailAuthProvider,
FacebookAuthProvider,
TwitterAuthProvider,
GithubAuthProvider,
};