I have implemented a typed Android data flow that ...
# uniflow
e
I have implemented a typed Android data flow that instead of
val currentState: UIState?
provides
val typedState: T
, with
<T : UIState>
as the generic type and it throws if the current state is
null
. Is this something you think is useful in some form? I can make a PR. Another idea could be to pull this up to a new
TypedDataFlow
interface. Worth the consideration, what are your thoughts on this?
a
Interesting question here, as we usually setup a first inital data
I think we never have a null state to start
but concerning the action functions, it can arrive that we don’t return any new state
e
The crux is what you say: usually So we could have two types of `DataFlow`: typed and untyped. The current impl is untyped, the typed one has generic type
<T : UIState>
and can never be null. We could also have a nullable typed version. The nonnullable version must guarantee that the state getter(s) always return nonnull state If used with a user's own sealed class hiearachy of
UIState
, then this allows for some powerfull state machine modelling
a
2 things I have in mind, and perhaps confirm what you say: • there is always a type for the flow (sealed class of states), an empty state at minmum • an action can return null to not update finally anything
the thing also is to allow to reuse generic states like Loading, Fail or Empty
then a DataFlow has a strong type, but you can push any event that is in your DataFlow type hierarchy
your sealed class, including the generic states