-
Notifications
You must be signed in to change notification settings - Fork 70
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
[RFC] [DNM] SideEffect as Type #1182
Conversation
This has now been addressed. |
Why did we close / reopen? Did something change? |
public protocol SideEffect: Hashable { | ||
associatedtype Action: WorkflowAction | ||
|
||
func run(sink: Sink<Action>) -> Lifetime | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Squinting, this looks a lot like Worker
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It pretty much is - except we're moving the ReactiveSwift
specific stuff out of Worker
. So instead of it returning SignalProducer<Output>
, we'll be passing in a Sink
and use an internal concept for Lifetime
instead.
Oh, we're also adding a hash
value to it.
Yes, we're now passing the |
This was discussed in #1021, the team has decided to stick with the API as-designed. |
Context
In #1174, we introduce the
sideEffect
API onRenderContext
:action
is executed the first time akey
is encountered andLifetime.onEnded
is called after it's no longer needed.Example usage:
Proposal
Make
SideEffect
a type:and the API becomes:
Why?
Harder to mess-up
The
Hashable
contract implies that thehashValue
will be calculated based on hashing all the contents of the object (SideEffect
). If thehashValue
s are the same, we then compare the two objects to make sure they're the same. This contract gives us a strong guarantee that the block of work that will be executed by theSideEffect
will be the same.If we instead put the responsibility on the consumer of the API to formulate the right
key
, we will be unnecessarily burdening the caller to carefully generate the rightkey
and the impact of doing this incorrectly will be subtle.In other words, if we want the
key
to represent the sameaction
AND theaction
is a function of(a, b, c)
I believe that the the key should bef(a, b, c)
Flexible
Making
SideEffect
a protocol (instead of having thekey
and an independentaction
closure) will make this more flexible. We will then be able to get any of theWorker
s to conform to theSideEffect
. (Instead of having an intermediateWorkflow
to do therunSideEffect
call.)