[auth][ios] finalised auth changed listener logic

This commit is contained in:
Salakar
2017-07-17 20:56:08 +01:00
parent 2d744b162e
commit d8fee7f5cb
6 changed files with 110 additions and 67 deletions

View File

@@ -37,9 +37,9 @@ export default class FirebaseApp {
this._nativeInitialized = true;
} else {
FirebaseCoreModule.initializeApp(this._name, this._options, (error, result) => {
// todo check error/result
this._initialized = true;
this._nativeInitialized = false;
INTERNALS.SharedEventEmitter.emit(`AppReady:${this._name}`, { error, result });
});
}
}
@@ -82,6 +82,17 @@ export default class FirebaseApp {
}
onReady(): Promise {
if (this._initialized) return Promise.resolve(this);
return new Promise((resolve, reject) => {
INTERNALS.SharedEventEmitter.once(`AppReady:${this._name}`, ({ error }) => {
if (error) return reject(new Error(error)); // error is a string as it's from native
return resolve(this); // return app
});
});
}
/*
* MODULES
*/