Skip to content

Commit eca5ddc

Browse files
committed
WIP
1 parent bc92da5 commit eca5ddc

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

android/src/main/java/io/fullstack/firestack/FirestackModule.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package io.fullstack.firestack;
22

33
import android.content.Context;
4-
5-
import android.content.Context;
4+
import android.util.Log;
65
import android.support.annotation.NonNull;
7-
import android.widget.Toast;
86

97
import com.facebook.react.bridge.Arguments;
108
import com.facebook.react.bridge.ReactApplicationContext;
@@ -31,6 +29,7 @@
3129
import com.google.firebase.auth.GoogleAuthProvider;
3230

3331
class FirestackModule extends ReactContextBaseJavaModule {
32+
private static final String TAG = "FirestackModule";
3433
private Context context;
3534
private FirebaseAuth mAuth;
3635
private FirebaseUser user;
@@ -47,7 +46,9 @@ public String getName() {
4746
}
4847

4948
@ReactMethod
50-
public void configureWithOptions(ReadableMap params, final Callback onSuccess) {
49+
public void configureWithOptions(ReadableMap params, final Callback onComplete) {
50+
System.out.println("Calling configureWithOptions");
51+
Log.i(TAG, "configureWithOptions");
5152
ReactContext mCtx = getReactApplicationContext();
5253
FirebaseOptions.Builder builder = new FirebaseOptions.Builder();
5354

@@ -68,13 +69,16 @@ public void configureWithOptions(ReadableMap params, final Callback onSuccess) {
6869
}
6970

7071
try {
72+
Log.i(TAG, "Configuring");
7173
FirebaseApp app = FirebaseApp.initializeApp(mCtx, builder.build());
74+
Log.i(TAG, "Configured");
75+
onComplete.invoke();
7276
}
73-
catch (Exception e){
74-
77+
catch (Exception ex){
78+
Log.e(TAG, "ERROR configureWithOptions");
79+
Log.e(TAG, ex.getMessage());
80+
onComplete.invoke();
7581
}
76-
77-
onSuccess.invoke();
7882
}
7983

8084
@ReactMethod

lib/firestack.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,18 @@ export class Firestack {
3838
const firestackOptions = Object.assign({}, this.options, opts);
3939
try {
4040
this.appInstance = app.initializeApp(firestackOptions);
41-
} catch (e) {}
41+
} catch (e) {
42+
console.log('Error occurred while calling configure', e);
43+
}
4244

4345
return promisify('configureWithOptions')(firestackOptions)
4446
.then((...args) => {
47+
console.log('Native configureWithOptions success', args);
4548
this.configured = true;
4649
return args;
47-
}).catch((err) => {})
50+
}).catch((err) => {
51+
console.log('Native error occurred while calling configure', e);
52+
})
4853
}
4954

5055
// Auth

lib/firestackModule.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ export class FirestackModule {
3232

3333
this._refName = refName;
3434
this._makeRef = opts.makeRef || identity;
35-
let firestack = this._firestack = opts.firestack;
3635

3736
const initialState = Object.assign({}, opts.initialState || defaultInitialState, {
3837
listening: false,
@@ -46,12 +45,23 @@ export class FirestackModule {
4645
this._sortFn = opts.sortFn || defaultSortFn
4746
this._onChange = opts.onChange || identity;
4847

49-
this.setStore(opts.store);
48+
if (opts.firestack) {
49+
this.setFirestack(opts.firestack);
50+
} else if (opts.store) {
51+
this.setStore(opts.store);
52+
}
5053
}
5154

5255
makeRef(path) {
53-
const refName = [this._refName, path].join('/');
54-
return this._makeRef(this._firestack.database.ref(refName));
56+
const refName = '/' + [this._refName, path].join('/');
57+
const ref = this._firestack.database.ref(refName);
58+
return this._makeRef(ref);
59+
}
60+
61+
setFirestack(firestack) {
62+
if (firestack) {
63+
this._firestack = firestack;
64+
}
5565
}
5666

5767
setStore(store) {
@@ -156,7 +166,7 @@ export class FirestackModule {
156166
}
157167
return error ? reject(error) : resolve(value)
158168
});
159-
});
169+
})
160170
});
161171
}
162172

@@ -198,7 +208,7 @@ export class FirestackModule {
198208
get actions() {
199209
return [
200210
'listen', 'unlisten',
201-
'get', 'set', 'update', 'remove'
211+
'getAt', 'setAt', 'updateAt', 'removeAt'
202212
].reduce((sum, name) => {
203213
return {
204214
...sum,

0 commit comments

Comments
 (0)