Skip to content

Commit a3dd83d

Browse files
docs(website): update docs to fit Operator type
1 parent e36a8b1 commit a3dd83d

14 files changed

+127
-97
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Operators
2+
3+
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:
4+
5+
```marksy
6+
h(Example, { name: "api/operators" })
7+
```
8+
9+
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:
10+
11+
```marksy
12+
h(Example, { name: "api/operators_pipe" })
13+
```
14+
15+
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.
16+
17+
## debounce
18+
When action is called multiple times within the set time limit, only the last action will move beyond the point of the debounce.
19+
20+
```marksy
21+
h(Example, { name: "api/operators_operator_debounce" })
22+
```
23+
24+
## filter
25+
Stop execution if it returns false.
26+
27+
```marksy
28+
h(Example, { name: "api/operators_operator_filter" })
29+
```
30+
31+
## forEach
32+
Allows you to point to an array where each item will be sent to the operator/pipe on the second argument.
33+
34+
```marksy
35+
h(Example, { name: "api/operators_operator_forEach" })
36+
```
37+
38+
## fork
39+
Allows you to execute an operator/pipe based on the matching key.
40+
41+
```marksy
42+
h(Example, { name: "api/operators_operator_fork" })
43+
```
44+
45+
## map
46+
Returns a new value to the pipe. If the value is a promise it will wait until promise is resolved.
47+
48+
```marksy
49+
h(Example, { name: "api/operators_operator_map" })
50+
```
51+
52+
## mutate
53+
You are only allowed to change the state in the mutate operator.
54+
55+
```marksy
56+
h(Example, { name: "api/operators_operator_mutate" })
57+
```
58+
59+
## pipe
60+
The pipe is an operator in itself. Use it to compose other operators and pipes.
61+
62+
```marksy
63+
h(Example, { name: "api/operators_operator_pipe" })
64+
```
65+
66+
## run
67+
This operator is useful to run effects. It will just pass the current value a long.
68+
69+
```marksy
70+
h(Example, { name: "api/operators_operator_run" })
71+
```
72+
73+
## wait
74+
Hold execution for set time.
75+
76+
```marksy
77+
h(Example, { name: "api/operators_operator_wait" })
78+
```
79+
80+
## when
81+
Go down the true or false path based on the returned value.
82+
83+
```marksy
84+
h(Example, { name: "api/operators_operator_when" })
85+
```
86+
87+

packages/overmind-website/api/pipe.md

Lines changed: 0 additions & 81 deletions
This file was deleted.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export default (ts) =>
2+
ts
3+
? [
4+
{
5+
code: `
6+
import { mutate } from 'overmind'
7+
8+
export const changeFoo = mutate(({ state }) => {
9+
state.foo = 'bar'
10+
})
11+
`,
12+
},
13+
]
14+
: [
15+
{
16+
code: `
17+
import { mutate } from 'overmind'
18+
19+
export const changeFoo = mutate(({ state }) => {
20+
state.foo = 'bar'
21+
})
22+
`,
23+
},
24+
]

packages/overmind-website/examples/api/pipe_debounce.ts renamed to packages/overmind-website/examples/api/operators_operator_debounce.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ export default (ts) =>
33
? [
44
{
55
code: `
6-
import { Pipe, pipe, debounce } from 'overmind'
6+
import { Operator, pipe, debounce } from 'overmind'
77
import { performSearch } from './operators'
88
9-
export const search: Pipe<string, string> = pipe(
9+
export const search: Operator<string, string> = pipe(
1010
debounce(200),
1111
performSearch
1212
)

packages/overmind-website/examples/api/pipe_filter.ts renamed to packages/overmind-website/examples/api/operators_operator_filter.ts

File renamed without changes.

packages/overmind-website/examples/api/pipe_forEach.ts renamed to packages/overmind-website/examples/api/operators_operator_forEach.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ export default (ts) =>
33
? [
44
{
55
code: `
6-
import { Pipe, pipe, forEach } from 'overmind'
6+
import { Operator, pipe, forEach } from 'overmind'
77
import { Post } from './state'
88
import { getPosts, getAuthor, setAuthor } from './operators'
99
10-
export const openPosts: Pipe<string, Post[]> = pipe(
10+
export const openPosts: Operator<string, Post[]> = pipe(
1111
getPosts,
1212
forEach(pipe(
1313
getAuthor,

packages/overmind-website/examples/api/pipe_fork.ts renamed to packages/overmind-website/examples/api/operators_operator_fork.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ export const forkUserType = (paths: {
1515
{
1616
fileName: 'app/actions.ts',
1717
code: `
18-
import { Pipe, pipe } from 'overmind'
18+
import { Operator, pipe } from 'overmind'
1919
import { forkUserType, doThis, doThat } from './operators'
2020
21-
export const getUser: Pipe<string> = pipe(
21+
export const getUser: Operator<string> = pipe(
2222
getUser,
2323
forkUserType({
2424
admin: doThis,

packages/overmind-website/examples/api/pipe_map.ts renamed to packages/overmind-website/examples/api/operators_operator_map.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default (ts) =>
66
import { map } from 'overmind'
77
import { User } from './state'
88
9-
export const getUser = map<string, User>(({ api }) => api.getUser())
9+
export const getUser = map<any, User>(({ api }) => api.getUser())
1010
`,
1111
},
1212
]

packages/overmind-website/examples/api/pipe_mutate.ts renamed to packages/overmind-website/examples/api/operators_operator_mutate.ts

File renamed without changes.

packages/overmind-website/examples/api/pipe_pipe.ts renamed to packages/overmind-website/examples/api/operators_operator_pipe.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ export default (ts) =>
33
? [
44
{
55
code: `
6-
import { Pipe, pipe } from 'overmind'
6+
import { Operator, pipe } from 'overmind'
77
import { Item } from './state'
88
9-
export const openItems: Pipe<void, Item[]> = pipe(
9+
export const openItems: Operator<void, Item[]> = pipe(
1010
getItems,
1111
setItems
1212
)
1313
14-
export const openItem: Pipe<void, Item> = pipe(
14+
export const openItem: Operator<void, Item> = pipe(
1515
openItems,
1616
getItem,
1717
setItem

0 commit comments

Comments
 (0)