[android][database] updated keepSynced to now work with modifiers

This commit is contained in:
Salakar 2017-08-05 21:42:36 +01:00
parent 6298b86557
commit 913bb4e500
2 changed files with 29 additions and 11 deletions

View File

@ -73,9 +73,10 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
* @param state
*/
@ReactMethod
public void keepSynced(String appName, String path, Boolean state) {
// TODO: Needs to take into account modifiers as well as just the path
getReferenceForAppPath(appName, path).keepSynced(state);
public void keepSynced(String appName, int id, String path, ReadableArray modifiers, Boolean state) {
getInternalReferenceForApp(appName, id, path, modifiers, false)
.getQuery()
.keepSynced(state);
}
@ -406,8 +407,6 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
}
/*
* INTERNALS/UTILS
*/
@ -441,6 +440,11 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
return "RNFirebaseDatabase";
}
/**
* React Native constants for RNFirebaseDatabase
*
* @return
*/
@Override
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
@ -471,6 +475,8 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
}
/**
* Return an existing or create a new RNFirebaseDatabaseReference instance.
*
* @param appName
* @param refId
* @param path
@ -520,6 +526,13 @@ public class RNFirebaseDatabase extends ReactContextBaseJavaModule {
return service.toUpperCase() + "/" + code.toUpperCase();
}
/**
* Convert as firebase DatabaseError instance into a writable map
* with the correct web-like error codes.
*
* @param nativeError
* @return
*/
static WritableMap getJSError(DatabaseError nativeError) {
WritableMap errorMap = Arguments.createMap();
errorMap.putInt("nativeErrorCode", nativeError.getCode());

View File

@ -33,6 +33,10 @@ public class RNFirebaseDatabaseReference {
private SparseArray<ChildEventListener> childEventListeners;
private SparseArray<ValueEventListener> valueEventListeners;
Query getQuery() {
return query;
}
/**
* @param context
* @param app
@ -45,11 +49,8 @@ public class RNFirebaseDatabaseReference {
appName = app;
path = refPath;
reactContext = context;
// todo only create if needed
childEventListeners = new SparseArray<ChildEventListener>();
valueEventListeners = new SparseArray<ValueEventListener>();
query = buildDatabaseQueryAtPathAndModifiers(path, modifiersArray);
}
@ -58,7 +59,7 @@ public class RNFirebaseDatabaseReference {
*
* @param promise
*/
void addOnceValueEventListener(final Promise promise) {
private void addOnceValueEventListener(final Promise promise) {
ValueEventListener onceValueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
@ -83,7 +84,7 @@ public class RNFirebaseDatabaseReference {
* @param eventName
* @param promise
*/
void addChildOnceEventListener(final String eventName, final Promise promise) {
private void addChildOnceEventListener(final String eventName, final Promise promise) {
ChildEventListener childEventListener = new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName) {
@ -132,12 +133,16 @@ public class RNFirebaseDatabaseReference {
}
/**
* Handles a React Native JS 'on' request and initializes listeners.
* @param eventName
*/
void on(String eventName) {
}
/**
*
* Handles a React Native JS 'once' request.
* @param eventName
* @param promise
*/