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
2020 }
2121 }
2222 }
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] } }
2633 StructureKind .MAP -> (value as Map <* , * >).entries.toList().let {
2734 FirebaseCompositeDecoder (it.size) { _, index -> it[index/ 2 ].run { if (index % 2 == 0 ) key else value } }
2835 }
Original file line number Diff line number Diff line change @@ -20,9 +20,16 @@ actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor): Compo
2020 }
2121 }
2222 }
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] } }
2633 StructureKind .MAP -> (value as Map <* , * >).entries.toList().let {
2734 FirebaseCompositeDecoder (it.size) { _, index -> it[index/ 2 ].run { if (index % 2 == 0 ) key else value } }
2835 }
Original file line number Diff line number Diff line change @@ -22,9 +22,16 @@ actual fun FirebaseDecoder.structureDecoder(descriptor: SerialDescriptor): Compo
2222 }
2323 }
2424 }
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] } }
2835 StructureKind .MAP -> (js(" Object" ).entries(value) as Array <Array <Any >>).let {
2936 FirebaseCompositeDecoder (it.size) { _, index -> it[index/ 2 ].run { if (index % 2 == 0 ) get(0 ) else get(1 ) } }
3037 }
You can’t perform that action at this time.
0 commit comments