Skip to content

Commit 1b97e5f

Browse files
fix(overmind): fix async action and add async indication in docs
1 parent aa0d044 commit 1b97e5f

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

packages/node_modules/overmind/src/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -987,8 +987,15 @@ export function action<Input, ThisConfig extends IConfiguration = Config>(
987987
(err, context, value, next) => {
988988
if (err) next(err, value)
989989
else {
990-
operation(context, value)
991-
next(null, value)
990+
const result = operation(context, value) as any
991+
992+
if (result instanceof Promise) {
993+
result
994+
.then(() => next(null, value))
995+
.catch((promiseErr) => next(promiseErr, value))
996+
} else {
997+
next(null, value)
998+
}
992999
}
9931000
}
9941001
)

packages/overmind-website/api/operators.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,19 @@ Any of these operators can be used with other operators. You can even insert a p
1818

1919

2020
## action
21+
22+
**async**
23+
2124
This operator takes a normal action and converts it to an operator so that it can be combined with other operators. You use this operator whenever you want to change the state of the app, but you can run effects as well. Just like a normal action.
2225

2326
```marksy
2427
h(Example, { name: "api/operators_operator_action" })
2528
```
2629

2730
## catchError
31+
32+
**async**
33+
2834
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.
2935

3036
```marksy

0 commit comments

Comments
 (0)