-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overload for collectWhileInState with Builder #186
Comments
Couldn't this be a foot gun? You create a Flow based on a value in the state, but if it's in the state it means that the value can change through mutations. Even if you know that the value does not change without you leaving the state first I think it would still be safer to do |
Yes, but that is in general also an issue for data class FooState(val value : Int)
inState<FooState> {
onAction<FooAction> { stateSnapshot, action ->
delay(2000)
...
// Some properties like stateSnapshot.value could be outdated because of mutations happened in parallel
loadItem(stateSnapshot.value)
...
} In that case we need to rely on using |
After I've added the indentity block (#480) I will also tackle this one. The motivation for inState<Foo> {
untilIdentityChanged({ it.bar }) {
collectWhileInState({ createFlow(it.bar) }) { ... }
}
} This approach fits better to the descriptive nature of building a state machine and is less dangerous than the approach of transforming a flow. While refactoring some things in preparation of these changes I've also noticed that the One question would be the name since the initial renaming proposal won't work since we've reached 1.x. |
Sounds good to me!
Gabriel Ittner ***@***.***> schrieb am Mi., 31. Mai 2023,
03:42:
… After I've added the indentity block (#480
<#480>) I will also tackle
this one. The motivation for flowBuilder: (Flow<InputState>) -> Flow<T>
was to enable collecting a flow that depends on a value of the state by
chaining it through a flatMapLatest. The identity block together with
this proposal achieves the same:
inState<Foo> {
untilIdentityChanged({ it.bar }) {
collectWhileInState({ createFlow(it.bar) }) { ... }
}
}
This approach fits better to the descriptive nature of building a state
machine and is less dangerous than the approach of transforming a flow.
While refactoring some things in preparation of these changes I've also
noticed that the (Flow<InputState>) -> Flow<T> introduces additional
complexity to the library. The current builder would be deprecated.
One question would be the name since the initial renaming proposal won't
work since we've reached 1.x.
—
Reply to this email directly, view it on GitHub
<#186 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEOPLUCD7PHSB3QO52I27LXIZEQPANCNFSM5BVTXI7A>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Currently we support
collectWhileInState
withflowBuilder
as shown bellow:I would like to add an overload with
because I personally have more need for this variation of flowBuilder (
(InputState) -> Flow<T>
) compare to the current one(Flow<InputState>) -> Flow<T>
.Obviously, that causes a clash on the JVM because both methods have same signature.
Thus we would need to rename one.
I would propose the following:
(InputState) -> Flow<T>
. Thus I would keep that one under thecollectWhileInState
name.Flow<InputState>) -> Flow<T>
tocollectWhileInStateWithGenericBuilder()
:Any thoughts?
cc @gabrielittner
The text was updated successfully, but these errors were encountered: