jeff
01/30/2021, 7:44 PMMyCustomComponent : Component
) that is attached to a view IFF it is already attached (i.e. don't create one if it doesn't exist)?jeff
01/30/2021, 7:44 PMinline fun <reified T : Component> BaseView.getComponentOrNull(): T? {
return getOrCreateComponentOther<T> {
return null
}
}
Deactivated User
01/31/2021, 6:18 PMgetOrCreateComponentUpdate
, getOrCreateComponentMouse
... Initially it was just getOrCreateComponent
but was converted into that to improve performance in K/N. What's your use case / why do you need the method you want to write?jeff
01/31/2021, 6:26 PMjeff
01/31/2021, 6:26 PMgetOrCreateComponent
but in the case where none previously existed I'd end up constructing one only to immediately throw it awayjeff
01/31/2021, 6:27 PMDeactivated User
01/31/2021, 6:39 PMjeff
01/31/2021, 6:39 PMComponent
(not, say, UpdateComponent
)Deactivated User
01/31/2021, 6:47 PMgetOrCreateComponentOther
We can just add variants like getComponentOrNull
you can even make a PR to add them:
https://github.com/korlibs/korge-next/blob/721d78c9ae1c7ce5c3a5b999a30eaeca46c93a8[…]rge/src/commonMain/kotlin/com/soywiz/korge/baseview/BaseView.kt
Can you make a PR adding those getComponent*OrNull
methods?
Alternatively, View
implements the Extra
interface, that support adding extrinsic properties without weak maps, so you can attach stuff there yourself and externally define your own code for a custom component system.
But well, as said, PRs are welcome 🙂jeff
01/31/2021, 6:50 PMjeff
01/31/2021, 6:50 PMjeff
01/31/2021, 6:50 PM