[auth] Pass previousChildName back to callback

This commit is contained in:
Elliot Hesp
2017-06-15 14:55:52 +01:00
parent 840f6b0ced
commit 3809fa8f63
3 changed files with 18 additions and 13 deletions
@@ -3,6 +3,8 @@ package io.invertase.firebase.database;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import android.support.annotation.Nullable;
import android.util.Log;
import java.util.Map;
@@ -50,28 +52,28 @@ public class RNFirebaseDatabaseReference {
@Override
public void onChildAdded(DataSnapshot dataSnapshot, String previousChildName) {
if ("child_added".equals(eventName)) {
handleDatabaseEvent("child_added", listenerId, dataSnapshot);
handleDatabaseEvent("child_added", listenerId, dataSnapshot, previousChildName);
}
}
@Override
public void onChildChanged(DataSnapshot dataSnapshot, String previousChildName) {
if ("child_changed".equals(eventName)) {
handleDatabaseEvent("child_changed", listenerId, dataSnapshot);
handleDatabaseEvent("child_changed", listenerId, dataSnapshot, previousChildName);
}
}
@Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
if ("child_removed".equals(eventName)) {
handleDatabaseEvent("child_removed", listenerId, dataSnapshot);
handleDatabaseEvent("child_removed", listenerId, dataSnapshot, null);
}
}
@Override
public void onChildMoved(DataSnapshot dataSnapshot, String previousChildName) {
if ("child_moved".equals(eventName)) {
handleDatabaseEvent("child_moved", listenerId, dataSnapshot);
handleDatabaseEvent("child_moved", listenerId, dataSnapshot, previousChildName);
}
}
@@ -94,7 +96,7 @@ public class RNFirebaseDatabaseReference {
ValueEventListener valueEventListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
handleDatabaseEvent("value", listenerId, dataSnapshot);
handleDatabaseEvent("value", listenerId, dataSnapshot, null);
}
@Override
@@ -166,11 +168,14 @@ public class RNFirebaseDatabaseReference {
}
}
private void handleDatabaseEvent(final String name, final Integer listenerId, final DataSnapshot dataSnapshot) {
private void handleDatabaseEvent(final String name, final Integer listenerId, final DataSnapshot dataSnapshot, @Nullable String previousChildName) {
WritableMap data = Utils.snapshotToMap(name, mRefId, listenerId, mPath, dataSnapshot);
WritableMap evt = Arguments.createMap();
evt.putString("eventName", name);
evt.putMap("body", data);
if (previousChildName != null) {
evt.putString("previousChildName", previousChildName);
}
Utils.sendEvent(mReactContext, "database_event", evt);
}