Skip to content

Latest commit

 

History

History
95 lines (66 loc) · 2.51 KB

File metadata and controls

95 lines (66 loc) · 2.51 KB

Operators

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 a simpler approach. You define an operator just like an action:

h(Example, { name: "api/operators" })

Operators forces you to split up your logic in tiny composable pieces that has a specific purpose. 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.

debounce

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" })

filter

Stop execution if it returns false.

h(Example, { name: "api/operators_operator_filter" })

forEach

Allows you to point to an array where each item will be sent to the operator/pipe on the second argument.

h(Example, { name: "api/operators_operator_forEach" })

fork

Allows you to execute an operator/pipe based on the matching key.

h(Example, { name: "api/operators_operator_fork" })

map

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" })

mutate

You are only allowed to change the state in the mutate operator.

h(Example, { name: "api/operators_operator_mutate" })

parallel

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" })

pipe

The pipe is an operator in itself. Use it to compose other operators and pipes.

h(Example, { name: "api/operators_operator_pipe" })

run

This operator is useful to run effects. It will just pass the current value a long. You may return a promise which will hold further execution until it is resolved.

h(Example, { name: "api/operators_operator_run" })

wait

Hold execution for set time.

h(Example, { name: "api/operators_operator_wait" })

when

Go down the true or false path based on the returned value.

h(Example, { name: "api/operators_operator_when" })