You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -16,16 +14,14 @@ An action is where you write the logic of the application. Every action receives
16
14
17
15
This _injected_ context allows Overmind to understand from where you are changing state and running effects. You can also use other actions defined in your application. Additionally with _injection_ your actions become highly testable as it can easily be mocked.
18
16
19
-
State changes are restricted to these actions. That means if you try to change the state outside of an action you will get an error. The state changes are also scoped to the action. That means it does not matter if you perform the state change asynchronously, either by defining the action as an **async** function or for example use a **setTimeout**. You can change the state at any time within the action.
17
+
State changes are restricted to these actions. That means if you try to change the state outside of an action you will get an error. The state changes are also scoped to the action. That means it does not matter if you perform the state change asynchronously, either by defining the action as an **async** function or for example use a **setTimeout**, returning a promise which is resolved when it times out.
20
18
21
19
## Payload
22
20
23
21
When an action is called you can optionally pass it a payload. This payload is received as the second argument to the action.
24
22
25
23
```typescript
26
-
import { Action } from'overmind'
27
-
28
-
exportconst setTitle:Action<string> = ({ state }, title) => {
There is only one argument, which means if you want to pass multiple values you have to do so with an object
35
31
{% endhint %}
36
32
37
-
## Typing
38
-
39
-
There are two different action types in Overmind, **Action** and **AsyncAction**. Both of them takes an Input param and an Output param where both of them default to **void**.
40
-
41
-
`Action<void, void>`
42
-
43
-
`AsyncAction<void, void>`.
44
-
45
-
The difference is that **AsyncAction** returns a Promise of the output, **Promise<void>**. Basically whenever you use an **async** action or explicitly return a promise from an action you should use the **AsyncAction** type.
Copy file name to clipboardExpand all lines: api-1/addflushlistener.md
+2-6Lines changed: 2 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,15 +3,11 @@
3
3
The **addMutationListener** triggers whenever there is a mutation. The **addFlushListener** triggers whenever Overmind tells components to render again. It can have multiple mutations related to it.
Copy file name to clipboardExpand all lines: api-1/addmutationlistener.md
+2-6Lines changed: 2 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,19 +3,15 @@
3
3
It is possible to listen to all mutations performed in Overmind. This allows you to create special effects based on mutations within a certain domain of your app, or whatever else you come up with. Note that this method triggers right after any mutation occurs, you might rather want to use **addFlushListener** to be notified about batched changes, like the components does.
Copy file name to clipboardExpand all lines: api-1/derive.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,11 +3,11 @@
3
3
You can add derived state to your application. You access derived state like any other value, there is no need to call it as a function. The derived value is cached and will only update when any accessed state changes.
0 commit comments