Skip to content

Commit 6aa0f61

Browse files
committed
make snapshot first param
1 parent 9b41a82 commit 6aa0f61

File tree

4 files changed

+15
-6
lines changed
  • firebase-common/src/jsMain/kotlin/dev/teamhub/firebase
  • firebase-database/src
    • androidMain/kotlin/dev/teamhub/firebase/database
    • commonMain/kotlin/dev/teamhub/firebase/database
    • jsMain/kotlin/dev/teamhub/firebase/database

4 files changed

+15
-6
lines changed

firebase-common/src/jsMain/kotlin/dev/teamhub/firebase/externals.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ external object firebase {
117117
fun push(): ThenableReference
118118
}
119119
open class DataSnapshot {
120+
val key: String?
120121
fun `val`(): Any
121122
fun exists(): Boolean
122123
fun forEach(action: (a: DataSnapshot) -> Boolean): Boolean

firebase-database/src/androidMain/kotlin/dev/teamhub/firebase/database/database.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,22 @@ actual open class Query internal constructor(
8686

8787
val moved by lazy { types.contains(Type.MOVED) }
8888
override fun onChildMoved(snapshot: com.google.firebase.database.DataSnapshot, previousChildName: String?) {
89-
if(moved) offer(ChildEvent(Type.MOVED, DataSnapshot(snapshot), previousChildName))
89+
if(moved) offer(ChildEvent(DataSnapshot(snapshot), Type.MOVED, previousChildName))
9090
}
9191

9292
val changed by lazy { types.contains(Type.CHANGED) }
9393
override fun onChildChanged(snapshot: com.google.firebase.database.DataSnapshot, previousChildName: String?) {
94-
if(changed) offer(ChildEvent(Type.CHANGED, DataSnapshot(snapshot), previousChildName))
94+
if(changed) offer(ChildEvent(DataSnapshot(snapshot), Type.CHANGED, previousChildName))
9595
}
9696

9797
val added by lazy { types.contains(Type.ADDED) }
9898
override fun onChildAdded(snapshot: com.google.firebase.database.DataSnapshot, previousChildName: String?) {
99-
if(added) offer(ChildEvent(Type.ADDED, DataSnapshot(snapshot), previousChildName))
99+
if(added) offer(ChildEvent(DataSnapshot(snapshot), Type.ADDED, previousChildName))
100100
}
101101

102102
val removed by lazy { types.contains(Type.REMOVED) }
103103
override fun onChildRemoved(snapshot: com.google.firebase.database.DataSnapshot) {
104-
if(removed) offer(ChildEvent(Type.REMOVED, DataSnapshot(snapshot), null))
104+
if(removed) offer(ChildEvent(DataSnapshot(snapshot), Type.REMOVED, null))
105105
}
106106

107107
override fun onCancelled(error: com.google.firebase.database.DatabaseError) {
@@ -146,6 +146,8 @@ actual class DataSnapshot internal constructor(val android: com.google.firebase.
146146

147147
actual val exists get() = android.exists()
148148

149+
actual val key get() = android.key
150+
149151
actual inline fun <reified T> value() =
150152
decode<T>(value = android.value)
151153

firebase-database/src/commonMain/kotlin/dev/teamhub/firebase/database/database.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ expect class FirebaseDatabase {
2626
fun setLoggingEnabled(enabled: Boolean)
2727
}
2828

29-
data class ChildEvent internal constructor(val type: Type, val snapshot: DataSnapshot, val previousChildName: String?) {
29+
data class ChildEvent internal constructor(
30+
val snapshot: DataSnapshot,
31+
val type: Type,
32+
val previousChildName: String?
33+
) {
3034
enum class Type {
3135
ADDED,
3236
CHANGED,
@@ -54,6 +58,7 @@ expect class DatabaseReference : Query {
5458

5559
expect class DataSnapshot {
5660
val exists: Boolean
61+
val key: String?
5762
@ImplicitReflectionSerializer
5863
inline fun <reified T> value(): T
5964
inline fun <reified T> value(strategy: DeserializationStrategy<T>): T

firebase-database/src/jsMain/kotlin/dev/teamhub/firebase/database/database.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ actual open class Query internal constructor(open val js: firebase.database.Quer
4949
{ snapshot, previousChildName ->
5050
offer(
5151
ChildEvent(
52-
type,
5352
DataSnapshot(snapshot),
53+
type,
5454
previousChildName
5555
)
5656
)
@@ -91,6 +91,7 @@ actual class DataSnapshot internal constructor(val js: firebase.database.DataSna
9191
rethrow { decode(strategy, js.`val`()) }
9292

9393
actual val exists get() = rethrow { js.exists() }
94+
actual val key get() = rethrow { js.key }
9495
actual fun child(path: String) = DataSnapshot(js.child(path))
9596

9697
actual val children: Iterable<DataSnapshot> = rethrow {

0 commit comments

Comments
 (0)