Skip to content

Commit b01acaa

Browse files
docs(website): rewritten functional docs
1 parent 3cb9f20 commit b01acaa

36 files changed

+698
-630
lines changed

packages/node_modules/overmind-devtools/src/components/ActionFlush/styles.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const flush = css({
99
position: 'relative',
1010
':hover div:nth-child(2)': {
1111
display: 'block',
12+
zIndex: 2,
1213
},
1314
':hover': {
1415
borderBottomRightRadius: 0,

packages/node_modules/overmind-devtools/src/overmind/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export type ActionsListItem = ActionItem | ActionGroupItem
4444

4545
export type Execution = {
4646
actionId: number
47-
name: string
47+
actionName: string
4848
executionId: number
4949
isAsync?: boolean
5050
operatorId: number

packages/overmind-website/api/operators.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,14 @@ Overmind also provides a functional API to help you manage complex logic. This A
66
h(Example, { name: "api/operators" })
77
```
88

9-
The **action** function is an operator that allows you to express logic just like you do in a traditional action. The **fromOperator** function converts an operator to a callable action that you can add to the configuration of your app. That means whenever you want to call an operator from a component, or somewhere else, you have to attach the operator on the configuration using the **fromOperator** function.
10-
11-
Operators are small composable pieces of logic that can be combined in many ways. 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:
9+
The **mutate** function is one of many operators. Operators are small composable pieces of logic that can be combined in many ways. 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:
1210

1311
```marksy
1412
h(Example, { name: "api/operators_pipe" })
1513
```
1614

1715
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.
1816

19-
20-
## action
21-
22-
**async**
23-
24-
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.
25-
26-
```marksy
27-
h(Example, { name: "api/operators_operator_action" })
28-
```
29-
3017
## catchError
3118

3219
**async**
@@ -72,6 +59,16 @@ Returns a new value to the pipe. If the value is a promise it will wait until pr
7259
h(Example, { name: "api/operators_operator_map" })
7360
```
7461

62+
## mutate
63+
64+
**async**
65+
66+
You use this operator whenever you want to change the state of the app, but you can run effects as well. Any returned value is ignored.
67+
68+
```marksy
69+
h(Example, { name: "api/operators_operator_action" })
70+
```
71+
7572
## parallel
7673
Will run every operator and wait for all of them to finish before moving on. Works like *Promise.all*.
7774

packages/overmind-website/examples/api/operators.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ export default (ts) =>
33
? [
44
{
55
code: `
6-
import { Operator, action } from 'overmind'
6+
import { Operator, mutate } from 'overmind'
77
8-
export const changeFoo: Operator = action(({ state }) => {
8+
export const changeFoo: Operator = mutate(({ state }) => {
99
state.foo = 'bar'
1010
})
1111
`,
@@ -14,9 +14,9 @@ export const changeFoo: Operator = action(({ state }) => {
1414
: [
1515
{
1616
code: `
17-
import { action } from 'overmind'
17+
import { mutate } from 'overmind'
1818
19-
export const changeFoo = action(({ state }) => {
19+
export const changeFoo = mutate(({ state }) => {
2020
state.foo = 'bar'
2121
})
2222
`,

packages/overmind-website/examples/api/operators_operator_action.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ export default (ts) =>
33
? [
44
{
55
code: `
6-
import { Operator, action } from 'overmind'
6+
import { Operator, mutate } from 'overmind'
77
8-
export const setUser: Operator<User> = action(({ value: user, state }) => {
8+
export const setUser: Operator<User> = mutate(({ value: user, state }) => {
99
state.user = user
1010
})
1111
`,
@@ -14,9 +14,9 @@ export const setUser: Operator<User> = action(({ value: user, state }) => {
1414
: [
1515
{
1616
code: `
17-
import { action } from 'overmind'
17+
import { mutate } from 'overmind'
1818
19-
export const setUser = action(({ value: user, state }) => {
19+
export const setUser = mutate(({ value: user, state }) => {
2020
state.user = user
2121
})
2222
`,

packages/overmind-website/examples/api/operators_operator_catcherror.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ export default (ts) =>
33
? [
44
{
55
code: `
6-
import { Operator, pipe, action, catchError } from 'overmind'
6+
import { Operator, pipe, mutate, catchError } from 'overmind'
77
88
export const doSomething: Operator<string> = pipe(
9-
action(() => {
9+
mutate(() => {
1010
throw new Error('foo')
1111
}),
12-
action(() => {
12+
mutate(() => {
1313
// This one is skipped
1414
})
1515
catchError(({ state }, error) => {
1616
state.error = error.message
1717
1818
return 'value_to_be_passed_on'
1919
}),
20-
action(() => {
20+
mutate(() => {
2121
// This one continues executing with replaced value
2222
})
2323
)
@@ -27,21 +27,21 @@ export const doSomething: Operator<string> = pipe(
2727
: [
2828
{
2929
code: `
30-
import { pipe, action, catchError } from 'overmind'
30+
import { pipe, mutate, catchError } from 'overmind'
3131
3232
export const doSomething = pipe(
33-
action(() => {
33+
mutate(() => {
3434
throw new Error('foo')
3535
}),
36-
action(() => {
36+
mutate(() => {
3737
// This one is skipped
3838
})
3939
catchError(({ state }, error) => {
4040
state.error = error.message
4141
4242
return 'value_to_be_passed_on'
4343
}),
44-
action(() => {
44+
mutate(() => {
4545
// This one continues executing with replaced value
4646
})
4747
)

packages/overmind-website/examples/api/operators_operator_parallel.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,29 @@ export default (ts) =>
33
? [
44
{
55
code: `
6-
import { Operator, pipe, action } from 'overmind'
7-
import { Item } from './state'
6+
import { Operator, pipe } from 'overmind'
87
98
export const loadSomeData: Operator = pipe(...)
109
export const loadSomeMoreData: Operator = pipe(...)
11-
export const manageAllData = action(...)
1210
13-
export const openItem: Operator = pipe(
14-
parallel(
15-
loadSomeData,
16-
loadSomeMoreData
17-
),
18-
manageAllData
11+
export const loadAllData: Operator = parallel(
12+
loadSomeData,
13+
loadSomeMoreData
1914
)
2015
`,
2116
},
2217
]
2318
: [
2419
{
2520
code: `
26-
import { pipe, action } from 'overmind'
21+
import { pipe } from 'overmind'
2722
2823
export const loadSomeData = pipe(...)
2924
export const loadSomeMoreData = pipe(...)
30-
export const manageAllData = action(...)
3125
32-
export const openItem = pipe(
33-
parallel(
34-
loadSomeData,
35-
loadSomeMoreData
36-
),
37-
manageAllData
26+
export const loadAllData = parallel(
27+
loadSomeData,
28+
loadSomeMoreData
3829
)
3930
`,
4031
},

packages/overmind-website/examples/api/operators_operator_trycatch.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export default (ts) =>
33
? [
44
{
55
code: `
6-
import { Operator, pipe, action, tryCatch } from 'overmind'
6+
import { Operator, pipe, tryCatch } from 'overmind'
77
88
export const doSomething: Operator<string> = tryCatch({
99
try: pipe(
@@ -19,7 +19,7 @@ export const doSomething: Operator<string> = tryCatch({
1919
: [
2020
{
2121
code: `
22-
import { pipe, action, tryCatch } from 'overmind'
22+
import { pipe, tryCatch } from 'overmind'
2323
2424
export const doSomething = tryCatch({
2525
try: pipe(

packages/overmind-website/examples/guide/createcustomoperators/action.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ export default (ts) =>
55
code: `
66
import { Operator, Context, Config, createMutationOperator } from 'overmind'
77
8-
export function action<Input>(
8+
export function mutate<Input>(
99
operation: (context: Context, value: Input) => void
1010
): Operator<Input> {
1111
return createMutationOperator<Config>(
12-
'action',
12+
'mutate',
1313
operation.name,
1414
(err, context, value, next) => {
1515
if (err) next(err, value)
@@ -28,9 +28,9 @@ export function action<Input>(
2828
code: `
2929
import { createMutationOperator } from 'overmind'
3030
31-
export function action(operation) {
31+
export function mutate(operation) {
3232
return createMutationOperator(
33-
'action',
33+
'mutate',
3434
operation.name,
3535
(err, context, value, next) => {
3636
if (err) next(err, value)

packages/overmind-website/examples/guide/createcustomoperators/touppercase.ts

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,53 +3,57 @@ export default (ts) =>
33
? [
44
{
55
code: `
6-
import { Operator, createOperator } from 'overmind'
6+
import { Operator, createOperator, mutate } from 'overmind'
77
8-
export function toUpperCase(): Operator<string> {
8+
export const toUpperCase: () => Operator<string> = () => {
99
return createOperator('toUpperCase', '', (err, context, value, next) => {
1010
if (err) next(err, value)
1111
else next(null, value.toUpperCase())
1212
})
1313
}
14+
15+
export const setTitle: Operator<string> = mutate(({ state }, title) => {
16+
state.title = title
17+
})
1418
`,
1519
},
1620
{
1721
code: `
18-
import { Operator, pipe, action } from 'overmind'
19-
import { toUpperCase } from './operators'
22+
import { Operator, pipe } from 'overmind'
23+
import { toUpperCase, setTitle } from './operators'
2024
2125
export const setUpperCaseTitle: Operator<string> = pipe(
2226
toUpperCase(),
23-
action(({ state }, title) => {
24-
state.title = title
25-
})
27+
setTitle
2628
)
2729
`,
2830
},
2931
]
3032
: [
3133
{
3234
code: `
33-
import { createOperator } from 'overmind'
35+
import { createOperator, mutate } from 'overmind'
3436
35-
export function toUpperCase() {
37+
export const toUpperCase = () => {
3638
return createOperator('toUpperCase', '', (err, context, value, next) => {
3739
if (err) next(err, value)
3840
else next(null, value.toUpperCase())
3941
})
4042
}
43+
44+
export const setTitle = mutate(({ state }, title) => {
45+
state.title = title
46+
})
4147
`,
4248
},
4349
{
4450
code: `
45-
import { pipe, action } from 'overmind'
51+
import { pipe } from 'overmind'
4652
import { toUpperCase } from './operators'
4753
4854
export const setUpperCaseTitle = pipe(
4955
toUpperCase(),
50-
action(({ state }, title) => {
51-
state.title = title
52-
})
56+
setTitle
5357
)
5458
`,
5559
},

0 commit comments

Comments
 (0)