44 */
55
66
7- import { NativeModules , NativeEventEmitter , AsyncStorage } from 'react-native' ;
7+ import { NativeModules , NativeEventEmitter } from 'react-native' ;
88
9- import Log from './utils/log'
9+ import Log from './utils/log' ;
1010import promisify from './utils/promisify' ;
1111import Singleton from './utils/singleton' ;
1212
@@ -34,7 +34,7 @@ export default class Firestack extends Singleton {
3434 * @param options
3535 * @param name - TODO support naming multiple instances
3636 */
37- constructor ( options , name ) {
37+ constructor ( options : Object , name : string ) {
3838 const instance = super ( options ) ;
3939
4040 instance . options = options || { } ;
@@ -49,7 +49,6 @@ export default class Firestack extends Singleton {
4949 delete instance . options . remoteConfig ;
5050
5151 instance . configured = instance . options . configure || false ;
52- instance . _auth = null ;
5352
5453 instance . eventHandlers = { } ;
5554
@@ -59,13 +58,24 @@ export default class Firestack extends Singleton {
5958 instance . _auth = new Auth ( instance , instance . options ) ;
6059 }
6160
61+ _db : ?Object ;
62+ _log : ?Object ;
63+ _auth : ?Object ;
64+ _store : ?Object ;
65+ _storage : ?Object ;
66+ _presence : ?Object ;
67+ _analytics : ?Object ;
68+ _constants : ?Object ;
69+ _messaging : ?Object ;
70+ _remoteConfig : ?Object ;
71+
6272 /**
6373 * Support web version of initApp.
6474 * @param options
6575 * @param name
6676 * @returns {* }
6777 */
68- static initializeApp ( options , name = 'default' ) {
78+ static initializeApp ( options : Object = { } , name : string = 'default' ) {
6979 if ( ! instances [ name ] ) instances [ name ] = new Firestack ( options ) ;
7080 return instances [ name ] ;
7181 }
@@ -76,7 +86,7 @@ export default class Firestack extends Singleton {
7686 * @param opts
7787 * @returns {Promise.<TResult>|*|Promise.<T> }
7888 */
79- configure ( opts = { } ) {
89+ configure ( opts : Object = { } ) {
8090 if ( ! this . configurePromise ) {
8191 const firestackOptions = Object . assign ( { } , this . options , opts ) ;
8292
@@ -88,12 +98,13 @@ export default class Firestack extends Singleton {
8898 return configuredProperties ;
8999 } ) . catch ( ( err ) => {
90100 log . info ( 'Native error occurred while calling configure' , err ) ;
91- } )
101+ } ) ;
92102 }
93103 return this . configurePromise ;
94104 }
95105
96- onReady ( cb ) {
106+ onReady ( cb : Function ) {
107+ // TODO wut o.O
97108 return this . configurePromise = this . configurePromise . then ( cb ) ;
98109 }
99110
@@ -104,24 +115,18 @@ export default class Firestack extends Singleton {
104115 * idea or not (imperative vs. direct manipulation/proxy)
105116 */
106117 auth ( ) {
107- console . log ( 'auth GET' ) ;
108- if ( ! this . _auth ) {
109- this . _auth = new Auth ( this ) ;
110- }
111118 return this . _auth ;
112119 }
113120
114- // database
121+
115122 database ( ) {
116123 if ( ! this . _db ) {
117124 this . _db = new Database ( this ) ;
118125 }
119126 return this . _db ;
120- // db.enableLogging(this._debug);
121- // return this.appInstance.database();
122127 }
123128
124- // analytics
129+
125130 analytics ( ) {
126131 if ( ! this . _analytics ) {
127132 this . _analytics = new Analytics ( this ) ;
@@ -137,71 +142,61 @@ export default class Firestack extends Singleton {
137142 return this . _storage ;
138143 }
139144
140- // presence
141145 presence ( ) {
142146 if ( ! this . _presence ) {
143147 this . _presence = new Presence ( this ) ;
144148 }
145149 return this . _presence ;
146150 }
147151
148- // CloudMessaging
149152 messaging ( ) {
150- if ( ! this . _cloudMessaging ) {
151- this . _cloudMessaging = new Messaging ( this ) ;
153+ if ( ! this . _messaging ) {
154+ this . _messaging = new Messaging ( this ) ;
152155 }
153- return this . _cloudMessaging ;
156+ return this . _messaging ;
154157 }
155158
156- /**
157- * remote config
158- */
159159 remoteConfig ( ) {
160- if ( ! this . remoteConfig ) {
161- this . remoteConfig = new RemoteConfig ( this . _remoteConfig ) ;
160+ if ( ! this . _remoteConfig ) {
161+ this . _remoteConfig = new RemoteConfig ( this ) ;
162162 }
163- return this . remoteConfig ;
163+ return this . _remoteConfig ;
164164 }
165165
166166 // other
167- get ServerValue ( ) {
167+ get ServerValue ( ) : Promise < * > {
168168 return promisify ( 'serverValue' , FirestackModule ) ( ) ;
169169 }
170170
171-
172- /**
173- * app instance
174- **/
175- get app ( ) {
171+ // TODO what are these for?
172+ get app ( ) : Object {
176173 return this . appInstance ;
177174 }
178175
179- /**
180- * app instance
181- **/
182- getInstance ( ) {
176+ // TODO what are these for?
177+ getInstance ( ) : Object {
183178 return this . appInstance ;
184179 }
185180
186- get apps ( ) {
181+ get apps ( ) : Array < string > {
187182 return Object . keys ( instances ) ;
188183 }
189184
190185 /**
191186 * Logger
192187 */
193- get log ( ) {
188+ get log ( ) : Log {
194189 return this . _log ;
195190 }
196191
197192 /**
198193 * Redux store
199194 **/
200- get store ( ) {
195+ get store ( ) : Object {
201196 return this . _store ;
202197 }
203198
204- get constants ( ) {
199+ get constants ( ) : Object {
205200 if ( ! this . _constants ) {
206201 this . _constants = Object . assign ( { } , Storage . constants )
207202 }
@@ -211,7 +206,7 @@ export default class Firestack extends Singleton {
211206 /**
212207 * Set the redux store helper
213208 */
214- setStore ( store ) {
209+ setStore ( store : Object ) {
215210 if ( store ) {
216211 this . log . info ( 'Setting the store for Firestack instance' ) ;
217212 this . _store = store ;
@@ -221,19 +216,17 @@ export default class Firestack extends Singleton {
221216 /**
222217 * Global event handlers for the single Firestack instance
223218 */
224- on ( name , cb , nativeModule ) {
219+ on ( name : string , cb : Function , nativeModule : Object = FirestackModuleEvt ) {
225220 if ( ! this . eventHandlers [ name ] ) {
226221 this . eventHandlers [ name ] = [ ] ;
227222 }
228- if ( ! nativeModule ) {
229- nativeModule = FirestackModuleEvt ;
230- }
223+
231224 const sub = nativeModule . addListener ( name , cb ) ;
232225 this . eventHandlers [ name ] . push ( sub ) ;
233226 return sub ;
234227 }
235228
236- off ( name ) {
229+ off ( name : string ) {
237230 if ( this . eventHandlers [ name ] ) {
238231 this . eventHandlers [ name ]
239232 . forEach ( subscription => subscription . remove ( ) ) ;
0 commit comments