File tree Expand file tree Collapse file tree 3 files changed +30
-9
lines changed
androidMain/kotlin/dev/gitlive/firebase
iosMain/kotlin/dev/gitlive/firebase
jsMain/kotlin/dev/gitlive/firebase Expand file tree Collapse file tree 3 files changed +30
-9
lines changed Original file line number Diff line number Diff line change @@ -20,9 +20,16 @@ actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor): Compo
20
20
}
21
21
}
22
22
}
23
- StructureKind .LIST -> ((value as ? Map <* , * >)?.values?.toList() ? : value as List <* >).let {
24
- FirebaseCompositeDecoder (it.size) { _, index -> it[index] }
25
- }
23
+ StructureKind .LIST ->
24
+ when (value) {
25
+ is List <* > -> value
26
+ is Map <* , * > -> value.asSequence()
27
+ .sortedBy { (it) -> it.toString().toIntOrNull() }
28
+ .map { (_, it) -> it }
29
+ .toList()
30
+ else -> error(" unexpected type, got $value when expecting a list" )
31
+ }
32
+ .let { FirebaseCompositeDecoder (it.size) { _, index -> it[index] } }
26
33
StructureKind .MAP -> (value as Map <* , * >).entries.toList().let {
27
34
FirebaseCompositeDecoder (it.size) { _, index -> it[index/ 2 ].run { if (index % 2 == 0 ) key else value } }
28
35
}
Original file line number Diff line number Diff line change @@ -20,9 +20,16 @@ actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor): Compo
20
20
}
21
21
}
22
22
}
23
- StructureKind .LIST -> ((value as ? Map <* , * >)?.values?.toList() ? : value as List <* >).let {
24
- FirebaseCompositeDecoder (it.size) { _, index -> it[index] }
25
- }
23
+ StructureKind .LIST ->
24
+ when (value) {
25
+ is List <* > -> value
26
+ is Map <* , * > -> value.asSequence()
27
+ .sortedBy { (it) -> it.toString().toIntOrNull() }
28
+ .map { (_, it) -> it }
29
+ .toList()
30
+ else -> error(" unexpected type, got $value when expecting a list" )
31
+ }
32
+ .let { FirebaseCompositeDecoder (it.size) { _, index -> it[index] } }
26
33
StructureKind .MAP -> (value as Map <* , * >).entries.toList().let {
27
34
FirebaseCompositeDecoder (it.size) { _, index -> it[index/ 2 ].run { if (index % 2 == 0 ) key else value } }
28
35
}
Original file line number Diff line number Diff line change @@ -22,9 +22,16 @@ actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor): Compo
22
22
}
23
23
}
24
24
}
25
- StructureKind .LIST -> (js(" Object" ).values(value) as Array <* >).let {
26
- FirebaseCompositeDecoder (it.size) { _, index -> it[index] }
27
- }
25
+ StructureKind .LIST ->
26
+ when (value) {
27
+ is Array <* > -> value
28
+ else -> (js(" Object" ).entries(value) as Array <Array <Any >>)
29
+ .asSequence()
30
+ .sortedBy { (it) -> it.toString().toIntOrNull() }
31
+ .map { (_, it) -> it }
32
+ .toList()
33
+ }
34
+ .let { FirebaseCompositeDecoder (it.size) { _, index -> it[index] } }
28
35
StructureKind .MAP -> (js(" Object" ).entries(value) as Array <Array <Any >>).let {
29
36
FirebaseCompositeDecoder (it.size) { _, index -> it[index/ 2 ].run { if (index % 2 == 0 ) get(0 ) else get(1 ) } }
30
37
}
You can’t perform that action at this time.
0 commit comments