Skip to content

Commit f99683d

Browse files
committed
#582 remove duplication from runtime
1 parent 1d99f0e commit f99683d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+336
-774
lines changed

resources-compose/src/commonJsMain/kotlin/dev/icerock/moko/resources/compose/StringResource.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
package dev.icerock.moko.resources.compose
66

77
import androidx.compose.runtime.Composable
8-
import androidx.compose.runtime.produceState
98
import androidx.compose.runtime.remember
109
import dev.icerock.moko.resources.PluralsResource
1110
import dev.icerock.moko.resources.StringResource

resources/src/jsMain/kotlin/dev/icerock/moko/resources/AssetResource.kt renamed to resources/src/commonJsMain/kotlin/dev/icerock/moko/resources/AssetResource.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/*
2-
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2025 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package dev.icerock.moko.resources
66

7+
import dev.icerock.moko.resources.internal.fetchText
78
import dev.icerock.moko.resources.internal.retryIO
8-
import kotlinx.browser.window
9-
import kotlinx.coroutines.await
109

1110
actual class AssetResource(
1211
// path after webpack serving
@@ -16,7 +15,7 @@ actual class AssetResource(
1615
) {
1716
suspend fun getText(): String {
1817
return retryIO {
19-
window.fetch(originalPath).await().text().await()
18+
fetchText(originalPath)
2019
}
2120
}
2221
}

resources/src/wasmJsMain/kotlin/dev/icerock/moko/resources/ColorResource.kt renamed to resources/src/commonJsMain/kotlin/dev/icerock/moko/resources/ColorResource.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
package dev.icerock.moko.resources
66

77
import dev.icerock.moko.graphics.Color
8+
import dev.icerock.moko.resources.internal.Window
89
import dev.icerock.moko.resources.internal.getDarkModeFlow
910
import dev.icerock.moko.resources.internal.isDarkMode
1011
import kotlinx.coroutines.flow.Flow
1112
import kotlinx.coroutines.flow.map
12-
import org.w3c.dom.Window
1313

1414
actual class ColorResource(
1515
val lightColor: Color,

resources/src/jsMain/kotlin/dev/icerock/moko/resources/FileResource.kt renamed to resources/src/commonJsMain/kotlin/dev/icerock/moko/resources/FileResource.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
/*
2-
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2025 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package dev.icerock.moko.resources
66

7+
import dev.icerock.moko.resources.internal.fetchText
78
import dev.icerock.moko.resources.internal.retryIO
8-
import kotlinx.browser.window
9-
import kotlinx.coroutines.await
109

1110
actual class FileResource(val fileUrl: String) {
1211
suspend fun getText(): String {
1312
return retryIO {
14-
window.fetch(fileUrl).await().text().await()
13+
fetchText(fileUrl)
1514
}
1615
}
1716
}

resources/src/jsMain/kotlin/dev/icerock/moko/resources/PluralsResource.kt renamed to resources/src/commonJsMain/kotlin/dev/icerock/moko/resources/PluralsResource.kt

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44

55
package dev.icerock.moko.resources
66

7+
import dev.icerock.moko.resources.internal.LocalizedText
78
import dev.icerock.moko.resources.internal.currentLocale
8-
import dev.icerock.moko.resources.internal.messageFormat.CompiledPlural
9-
import dev.icerock.moko.resources.internal.messageFormat.MessageFormat
109
import dev.icerock.moko.resources.provider.JsStringProvider
1110
import dev.icerock.moko.resources.provider.RemoteJsStringLoader
12-
import kotlin.js.Json
1311

1412
actual class PluralsResource(
1513
private val key: String,
@@ -18,21 +16,12 @@ actual class PluralsResource(
1816
fun localized(provider: JsStringProvider, locale: String?, quantity: Int): String {
1917
val pluralString: String = provider.provideString(id = key, locale = locale)
2018
val pluralLocale: String = locale ?: currentLocale()
21-
22-
val compiledPlural: (Json) -> String = MessageFormat(arrayOf(pluralLocale))
23-
.compile(pluralString)
24-
25-
return CompiledPlural(compiledPlural).evaluate(quantity)
19+
return LocalizedText(locale = pluralLocale, text = pluralString).evaluate(quantity = quantity)
2620
}
2721

2822
fun localized(provider: JsStringProvider, locale: String?, quantity: Int, vararg args: Any): String {
2923
val pluralString: String = provider.provideString(id = key, locale = locale)
3024
val pluralLocale: String = locale ?: currentLocale()
31-
32-
val compiledPlural = CompiledPlural(
33-
MessageFormat(arrayOf(pluralLocale)).compile(pluralString)
34-
)
35-
36-
return compiledPlural.evaluate(quantity, *args)
25+
return LocalizedText(locale = pluralLocale, text = pluralString).evaluate(quantity = quantity, args = args)
3726
}
3827
}

resources/src/commonJsMain/kotlin/dev/icerock/moko/resources/ResourceContainerExt.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ actual fun ResourceContainer<ImageResource>.getImageByFileName(
88
fileName: String
99
): ImageResource? = values()
1010
.find { it.fileName == fileName }
11+
12+
actual fun ResourceContainer<AssetResource>.getAssetByFilePath(
13+
filePath: String
14+
): AssetResource? = values()
15+
.find { it.rawPath == filePath }

resources/src/jsMain/kotlin/dev/icerock/moko/resources/StringResource.kt renamed to resources/src/commonJsMain/kotlin/dev/icerock/moko/resources/StringResource.kt

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/*
2-
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2025 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package dev.icerock.moko.resources
66

7+
import dev.icerock.moko.resources.internal.LocalizedText
78
import dev.icerock.moko.resources.internal.currentLocale
8-
import dev.icerock.moko.resources.internal.messageFormat.CompiledVariableString
9-
import dev.icerock.moko.resources.internal.messageFormat.MessageFormat
109
import dev.icerock.moko.resources.provider.JsStringProvider
1110
import dev.icerock.moko.resources.provider.RemoteJsStringLoader
1211

@@ -20,10 +19,7 @@ actual class StringResource(
2019

2120
fun localized(provider: JsStringProvider, locale: String?, vararg args: Any): String {
2221
val rawString: String = provider.provideString(id = key, locale = locale)
23-
val compiled = CompiledVariableString(
24-
MessageFormat(arrayOf(locale ?: currentLocale())).compile(rawString)
25-
)
26-
return compiled.evaluate(*args)
22+
return LocalizedText(locale = locale ?: currentLocale(), text = rawString).evaluate(args = args)
2723
}
2824

2925
override fun equals(other: Any?): Boolean {

resources/src/jsMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt renamed to resources/src/commonJsMain/kotlin/dev/icerock/moko/resources/desc/PluralFormattedStringDesc.kt

File renamed without changes.

resources/src/wasmJsMain/kotlin/dev/icerock/moko/resources/desc/PluralStringDesc.kt renamed to resources/src/commonJsMain/kotlin/dev/icerock/moko/resources/desc/PluralStringDesc.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2025 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package dev.icerock.moko.resources.desc

resources/src/jsMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt renamed to resources/src/commonJsMain/kotlin/dev/icerock/moko/resources/desc/ResourceFormattedStringDesc.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2022 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
2+
* Copyright 2025 IceRock MAG Inc. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

55
package dev.icerock.moko.resources.desc

0 commit comments

Comments
 (0)