Overmind also provides a functional API to help you manage complex logic. This API is inspired by asynchronous flow libraries like RxJS, though it is designed to manage application state and effects. If you want to create and use a traditional action "operator style" you define it like this:
h(Example, { name: "api/operators" })
The mutate function is one of many operators. Operators are small composable pieces of logic that can be combined in many ways. This allows you to express complexity in a declarative way. You typically use the pipe operator in combination with the other operators to do this:
h(Example, { name: "api/operators_pipe" })
Any of these operators can be used with other operators. You can even insert a pipe inside an other pipe. This kind of composition is what makes functional programming so powerful.
async
This operator runs if any of the previous operators throws an error. It allows you to manage that error by changing your state, run effects or even return a new value to the next operators.
h(Example, { name: "api/operators_operator_catcherror" })
When action is called multiple times within the set time limit, only the last action will move beyond the point of the debounce.
h(Example, { name: "api/operators_operator_debounce" })
Stop execution if it returns false.
h(Example, { name: "api/operators_operator_filter" })
Allows you to pass each item of a value that is an array to the operator/pipe on the second argument.
h(Example, { name: "api/operators_operator_forEach" })
Allows you to execute an operator/pipe based on the matching key.
h(Example, { name: "api/operators_operator_fork" })
Returns a new value to the pipe. If the value is a promise it will wait until promise is resolved.
h(Example, { name: "api/operators_operator_map" })
async
You use this operator whenever you want to change the state of the app, but you can run effects as well. Any returned value is ignored.
h(Example, { name: "api/operators_operator_action" })
This operator does absolutely nothing. Is useful when paths of execution is not supposed to do anything.
h(Example, { name: "api/operators_operator_noop" })
Will run every operator and wait for all of them to finish before moving on. Works like Promise.all.
h(Example, { name: "api/operators_operator_parallel" })
The pipe is an operator in itself. Use it to compose other operators and pipes.
h(Example, { name: "api/operators_operator_pipe" })
This operator allows you to run side effects. You can not change state and you can not return a value.
h(Example, { name: "api/operators_operator_run" })
This operator allows you to scope execution and manage errors. This operator does not return a new value to the execution.
h(Example, { name: "api/operators_operator_trycatch" })
Hold execution for set time.
h(Example, { name: "api/operators_operator_wait" })
Go down the true or false path based on the returned value.
h(Example, { name: "api/operators_operator_when" })