Last active
February 3, 2020 00:21
-
-
Save dmitrykolesnikovich/72f71d139de95d24b7d1cf7f2f4e3828 to your computer and use it in GitHub Desktop.
How to make resources in featurea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
unlike dependencies resources needs to be defined explicitly e. g. without any sort of inheritance | |
*/ | |
/*platform*/ | |
typealias LoaderOnSuccess = Loader.() -> Unit | |
object Loader { | |
fun load(vararg resources: List<String>, onSuccess: LoaderOnSuccess? = null) { | |
resources.forEach { print(it) } | |
println() | |
onSuccess?.invoke(this) | |
} | |
} | |
/*solutions*/ | |
object AResources { | |
val a1Jpeg = "a1.jpeg" | |
val a2Glsl = "a2.glsl" | |
val list = listOf(a1Jpeg, a2Glsl) | |
} | |
object BResources { | |
val b1Png = "b1.png" | |
val b2Mp3 = "b2.mp3" | |
val list = listOf(b1Png, b2Mp3) | |
} | |
/*project*/ | |
fun Loader.loadAll(onSuccess: LoaderOnSuccess) = load(AResources.list, BResources.list) { onSuccess() } | |
fun main() { | |
Loader.loadAll { | |
println("Success") | |
} | |
} |
/> featurea listResources test2
val list = listOf(b1Png, b2Mp3)
/>
/> featurea loadAllResources test2
fun Loader.loadAll(onSuccess: LoaderOnSuccess) = load(AResources.list, BResources.list) { onSuccess() }
/>
/> featurea listResources $test2
object Resources {
val b1Png = "b1.png"
val b2Mp3 = "b2.mp3"
val list = listOf(b1Png, b2Mp3)
}
/>
-r is flag that means "recursively"
/>featurea loadResources -r $test2
fun Loader.loadAll() = load(AResources.list, BResources.list)
/>
fun main() {
Loader.loadAll {
println("Success")
}
}
/*platform*/
typealias LoaderOnSuccess = Loader.() -> Unit
typealias LoaderBlock = (LoaderOnSuccess) -> Unit
object Loader {
var onSuccess: LoaderOnSuccess = {}
fun load(vararg resources: List<String>) {
resources.forEach { print(it) }
println()
onSuccess()
onSuccess = {}
}
}
/*solutions*/
object AResources {
val a1Jpeg = "a1.jpeg"
val a2Glsl = "a2.glsl"
val list = listOf(a1Jpeg, a2Glsl)
}
object BResources {
val b1Png = "b1.png"
val b2Mp3 = "b2.mp3"
val list = listOf(b1Png, b2Mp3)
}
/*project*/
fun Loader.loadAll() = load(AResources.list, BResources.list)
fun main() {
Loader.loadAll()
Loader.onSuccess = {
println("Success")
// app.screen = load(Resources.screensRml.screen1)
}
}
import Resources.*
/*resources*/
object Resources {
val a = "a"
object screensRml {
val screen1 = "screens.rml:/screen1"
}
}
val resources = listOf(a)
/*screens*/
private val screenResources = include(featurea.a.resources, featurea.b.resources)
fun Loader.loadScreen1() = load(screenResources) { app.screen = loadScreen(screensRml.screen1) }
/*project*/
fun main() = Loader.loadScreen1()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
alias "featurea listResources test2" = featurea listResources $Home/workspace/test2/src/commonMain/kotlin/featurea/test2/AResources.kt:/AResources