-
-
Notifications
You must be signed in to change notification settings - Fork 95
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: Replace run and mutate operator with action #173
Comments
I also encountered 2. while playing with overmind and that's what made me explore some alternative way to express actions (that and the type of parallele 😄 ) (https://github.com/etienne-dldc/meleze-store). const maybeSetFoo = action(({ value }) => {
if (value > 42) {
// we return the mutation we want to perform
return setFoo;
}
// null is ignored
return null;
}) Here I could have used a |
@christianalfoni Is this a thought experiment or does the implementation live somewhere we can play with? |
@etienne-dldc Thanks for your input here! I see where you are going and yeah, that is certainly powerful! And I guess there is nothing wrong with us creating an operator that does exactly that. Instead of like One thing I see though is that even though the implementation has a lot of power, it will hide some implementation details in the expressed pipe. pipe(
maybeSetFoo // You do not know what operator is actually run when truthy
)
pipe(
when(valueIsMoreThan42, {
true: setFoo,
false: null
})
) This was of course a contrived example as well and splitting up into a |
@abalmos It is a tiny change I will do later today a long with a couple of other small fixes... which marks that my list of fixes is done and I can focus on more docs and start preparing some videos :) |
Old stuff |
So we are closing in on release, woop woop!
I have one final breaking change I want to do. I want to replace the
run
andmutate
operator with a singleaction
operator. Let me explain why.1. Introducing the concept
When we now explain Overmind we start out with simple imperative actions.
When we move to the functional world of operators we could make the jump by simply doing:
Congrats, you have now created a lego block out of your action. You can now make this action only callable when the value has a certain length:
And so on. It creates a natural stepping stone from imperative actions to functional actions, where you have additional operators to manage "FLOW".
2. Overdoing the separation
The operators API should be closer to an action than rxjs. The reason is that there are only certain functional aspects that truly gives value. Let me explain with an example:
This looks very nice, but the last part there. Creating three composable pieces to get and set the search result. This is where I think we are overdoing it. I think it makes a lot more sense to do:
Where
getSearchResult
looks like:Summary
So by getting rid of
run
andmutate
we reduce API surface, we create a simpler transition to the functional world and we expose operators that actually manages FLOW. Likefilter
,debounce
etc. Nowmap
becomes an operator to put values into the flow, not as an intermediate step every time you want to express "grab data from effect and set state"... which is what we mostly do :)Okay... thanks for listening :-)
The text was updated successfully, but these errors were encountered: