|
1 | 1 | # Action |
2 | 2 |
|
3 | | -hihi |
| 3 | +```marksy |
| 4 | +<Example name="api_action" /> |
| 5 | +``` |
4 | 6 |
|
| 7 | +An action allows you to compose pieces of logic into an execution. You typically execute an action based on some user interaction in your application, but it could be everything from a route change to a websocket message as well. |
5 | 8 |
|
6 | | -## Map |
7 | | -Some operator code |
| 9 | +Actions are defined with a powerful chaining API which gives control of the execution itself. The asynchronocity of your execution is completely abstracted away, you only think about the logical order of execution and Overmind takes care of the rest. |
8 | 10 |
|
9 | | -## Do |
10 | | -Some more operator code |
| 11 | +The action is built up by **operators**, methods called on the action itself. These operators describes the execution logic. |
| 12 | + |
| 13 | +## debounce |
| 14 | +```marksy |
| 15 | +<Example name="api_action_debounce" /> |
| 16 | +``` |
| 17 | + |
| 18 | +Typically used to only continue execution of the last action call if multiple action calls has been made in the time limit passed in. |
| 19 | + |
| 20 | +The only argument is the time limit in milliseconds the operator should prevent action calls to continue. When the an action call has waited for the milliseconds defined, without any new action calls has been made, the execution will continue. |
| 21 | + |
| 22 | +## do |
| 23 | +```marksy |
| 24 | +<Example name="api_action_do" /> |
| 25 | +``` |
| 26 | + |
| 27 | +Typically used to fire off an effect without caring about its returned result, if any. |
| 28 | + |
| 29 | +Only argument is a function that receives the **effects** registered in the application as the first argument, and the current **value** of the action as the second argument. Any returned value will be ignored. The current value of the action will be passed to the next operator. |
| 30 | + |
| 31 | +## filter |
| 32 | +```marksy |
| 33 | +<Example name="api_action_filter" /> |
| 34 | +``` |
| 35 | + |
| 36 | +Typically used to stop execution related to some condition. |
| 37 | + |
| 38 | +The first argument is a function that receives the **effects** registered in the application as the first argument, and the current **value** as the second argument. If the function returns the value `false`, synchronously or asynchronously, the execution of the action will stop. |
| 39 | + |
| 40 | +## fork |
| 41 | +```marksy |
| 42 | +<Example name="api_action_fork" /> |
| 43 | +``` |
| 44 | +Typically used to fork out execution when a value can result in multiple complex executions. |
| 45 | + |
| 46 | +The first argument is a function that receives the **effects** as the first argument and the current **value** as the second. The function is expected to return a value, either synchronously or asynchronously, that matches the paths passed as the second argument to the fork operator. |
| 47 | + |
| 48 | + |
| 49 | +## map |
| 50 | +```marksy |
| 51 | +<Example name="api_action_map" /> |
| 52 | +``` |
| 53 | + |
| 54 | +Typically used to get values from an effect or transform the current value of the action. |
| 55 | + |
| 56 | +Only argument is a function that receives the **effects** registered in the application as the first argument, and the current **value** of the action as the second argument. The returned value will become the new value of the action. |
| 57 | + |
| 58 | +## mutation |
| 59 | +```marksy |
| 60 | +<Example name="api_action_mutation" /> |
| 61 | +``` |
| 62 | + |
| 63 | +Used to change the state of the application. |
| 64 | + |
| 65 | +Only argument is a function that receives the **state** as the first argument and the current **value** of the action as the second argument. This operator is the only operator that is allowed to mutate the state of the application. |
| 66 | + |
| 67 | +## try |
| 68 | +```marksy |
| 69 | +<Example name="api_action_try" /> |
| 70 | +``` |
| 71 | + |
| 72 | +Typically used to explicitly handle potentially thrown errors from an effect. |
| 73 | + |
| 74 | +The first argument is a function that receives the **effects** registered in the application as the first argument, and the current **value** as the second argument. The second argument to the operator are two paths, **success** and **error** which are respectively executed based on the success of the first argument function. |
| 75 | + |
| 76 | +## when |
| 77 | +```marksy |
| 78 | +<Example name="api_action_when" /> |
| 79 | +``` |
| 80 | + |
| 81 | +Typically used to fork execution based on a thruthy or falsy value. |
| 82 | + |
| 83 | +The first argument is a function that receives the **effects** registered in the application as the first argument, and the current **value** as the second argument. The second argument to the operator are two paths, **true** and **false** which are respectively executed based on the thruthyness of the returned value in the first argument function, which can be synchronous or asynchronous. |
0 commit comments