Arkadii Ivanov
09/17/2022, 9:11 PMValue
. Currently it is defined as abstract class Value<out T : Any>
. But sometimes it would be useful to have something like Value<String?>
, instead of wrapping into something like Value<Optional<String>>
.
The reason of that limitation is the interop with Swift - generics in interfaces are not supported, and a class with <T>
is always nullable. But it feels that Swift is not needed for everyone, there are projects without Swift but with Android/desktop/Web/compose-ios etc.
I got an idea to make Value
a normal interface, and at the same time keep the interop with Swift.
interface Value<T>
With additional classes:
abstract class ReqValue<T : Any> : Value<T>
and
abstract class OptValue<out T : Any> : Value<T?>
And two extension functions:
<T : Any> Value<T>.asRequired(): ReqValue<T>
<T : Any> Value<T?>.asOptional(): OptValue<T>
So, if Swift is not needed - it's ok to just use Value
. But if Swift is needed - one should expose ReqValue
or OptValue
. This looks more flexible - e.g. it will be possible to expose both <T>
and <T?>
to Swift, and it will be type-safe. But also a bit more verbose in case of Swift.
What do you think, 👍 or 👎?Andrew Steinmetz
09/17/2022, 11:07 PMlehakorshun
09/18/2022, 4:17 AMArkadii Ivanov
09/18/2022, 9:37 AMValue<DialogComponent?>
, to dynamically create and destroy a dialog/overlay component. It may be also useful for developers who prefer to have multiple Value properties instead of one single state class.
It was originally requested here - https://github.com/badoo/Decompose/issues/258 And then also here - https://github.com/arkivanov/Decompose/discussions/55
But there are no exact use cases described. Personally I bumped into this limitation when created components dynamically.Andrew Steinmetz
09/19/2022, 6:01 PMArkadii Ivanov
09/19/2022, 6:06 PMArkadii Ivanov
09/25/2022, 8:23 PM