Open digitalbuddha opened 4 years ago
My concern here is that it's going to be an even bigger temptation to read from the state
argument to render instead of the nextState
of the WorkflowAction
. Your handler lambda really should be receiving a StateT
as well as T
.
Given that, still want this?
I think my concern is more around obscuring how various calls to the proposed run
function would be deduped (even after adding a key
parameter). Hiding the fact that there is a Worker here makes it even more magical that two run
calls with the same type are considered equivalent, but with a different return type are considered separate. One of the most confusing bits of the API is how workers are deduped, even when they're explicit. I'm not sure if this would make that significantly more confusing, or just marginally confusing relative to how much it already is.
Also, to clarify the discussion going forward, this proposes two separate and unrelated things:
Worker.from
(which is what my concern above is about)action
(which is what Ray's concern is about, I think). We've also had other proposals about doing the latter (cc @steveinflow)@rjrjr Yup! The handler should be receiving both the result of the worker as well as the state. I am mostly looking for a way to make the common case of get data from a service and make a new state based on the result a bit shorter to write.
Hi folks, I wrote an extension function
run
which tries to reduce some of the boilerplate associated with running workers. I find myself writing a bit more boilerplate that the minimum when creating a worker that changes state. I'd like the ability to pass a lambda torunningWorker
that is anAction.Updater
while still receiving the result of my worker.As an example:
Ideally I wanted to collapse the following to something that asks for a suspended function to execute and a state to show with the response
I got pretty close but cannot get a working solution that allows me to pass an
updater
to myrun
function without having to also pass an action:From what I gather (apologies this is all new to me) the issue is with
action
being unable to pass a param toupdater
the only reason the above example compiles is thatit
is being captured from the "handler" without ever getting passed between the action and the action.updater. For context here is my current solutionI'm coming from mvrx which has a similar api as I describe above where a single
execute
function both acts as a mutator and an action. It would be helpful to have the same here.