mirror of
https://github.com/zhigang1992/react-native-firebase.git
synced 2026-06-16 11:59:29 +08:00
[android][database] Combine snapshotToMap methods
This commit is contained in:
@@ -84,26 +84,7 @@ public class Utils {
|
||||
*/
|
||||
public static WritableMap snapshotToMap(DataSnapshot dataSnapshot, @Nullable String previousChildName) {
|
||||
WritableMap result = Arguments.createMap();
|
||||
WritableMap snapshot = Arguments.createMap();
|
||||
|
||||
snapshot.putString("key", dataSnapshot.getKey());
|
||||
snapshot.putBoolean("exists", dataSnapshot.exists());
|
||||
snapshot.putBoolean("hasChildren", dataSnapshot.hasChildren());
|
||||
snapshot.putDouble("childrenCount", dataSnapshot.getChildrenCount());
|
||||
snapshot.putArray("childKeys", Utils.getChildKeys(dataSnapshot));
|
||||
mapPutValue("priority", dataSnapshot.getPriority(), snapshot);
|
||||
|
||||
if (!dataSnapshot.hasChildren()) {
|
||||
mapPutValue("value", dataSnapshot.getValue(), snapshot);
|
||||
} else {
|
||||
Object value = Utils.castValue(dataSnapshot);
|
||||
if (value instanceof WritableNativeArray) {
|
||||
snapshot.putArray("value", (WritableArray) value);
|
||||
} else {
|
||||
snapshot.putMap("value", (WritableMap) value);
|
||||
}
|
||||
}
|
||||
|
||||
WritableMap snapshot = Utils.snapshotToMap(dataSnapshot);
|
||||
|
||||
result.putMap("snapshot", snapshot);
|
||||
result.putString("previousChildName", previousChildName);
|
||||
@@ -161,6 +142,8 @@ public class Utils {
|
||||
snapshot.putBoolean("exists", dataSnapshot.exists());
|
||||
snapshot.putBoolean("hasChildren", dataSnapshot.hasChildren());
|
||||
snapshot.putDouble("childrenCount", dataSnapshot.getChildrenCount());
|
||||
snapshot.putArray("childKeys", Utils.getChildKeys(dataSnapshot));
|
||||
mapPutValue("priority", dataSnapshot.getPriority(), snapshot);
|
||||
|
||||
if (!dataSnapshot.hasChildren()) {
|
||||
mapPutValue("value", dataSnapshot.getValue(), snapshot);
|
||||
@@ -173,9 +156,6 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
|
||||
snapshot.putArray("childKeys", Utils.getChildKeys(dataSnapshot));
|
||||
mapPutValue("priority", dataSnapshot.getPriority(), snapshot);
|
||||
|
||||
return snapshot;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user