Skip to content

Commit 4a5f6f4

Browse files
docs(website): fix operators api docs
1 parent 42fcd9e commit 4a5f6f4

21 files changed

+212
-133
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export const addAction: () => Operator<StartActionMessage> = () =>
209209
const existingId = (app.actionsList[0] as ActionItem).id
210210
app.actionsList[0] = {
211211
type: ActionsListItemType.GROUP,
212-
id: getActionId(action),
212+
id: actionId,
213213
actionId: action.actionId,
214214
isCollapsed: true,
215215
actionIds: [actionId, existingId],

packages/overmind-website/api/operators.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ You use this operator whenever you want to change the state of the app, but you
6969
h(Example, { name: "api/operators_operator_action" })
7070
```
7171

72+
## noop
73+
74+
This operator does absolutely nothing. Is useful when paths of execution is not supposed to do anything.
75+
76+
```marksy
77+
h(Example, { name: "api/operators_operator_noop" })
78+
```
79+
80+
7281
## parallel
7382
Will run every operator and wait for all of them to finish before moving on. Works like *Promise.all*.
7483

@@ -83,6 +92,14 @@ The pipe is an operator in itself. Use it to compose other operators and pipes.
8392
h(Example, { name: "api/operators_operator_pipe" })
8493
```
8594

95+
## run
96+
97+
This operator allows you to run side effects. You can not change state and you can not return a value.
98+
99+
```marksy
100+
h(Example, { name: "api/operators_operator_run" })
101+
```
102+
86103
## tryCatch
87104
This operator allows you to scope execution and manage errors. This operator does not return a new value to the execution.
88105

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@ export default (ts, view) =>
99
import { OnInitialize } from 'overmind'
1010
1111
const onInitialize: OnInitialize = async ({
12-
value: overmind,
1312
state,
1413
actions,
1514
effects
16-
}) => {
15+
}, overmind) => {
1716
const initialData = await effects.api.getInitialData()
1817
state.initialData = initialData
1918
}
@@ -44,11 +43,10 @@ const config = {
4443
fileName: 'overmind/onInitialize.js',
4544
code: `
4645
const onInitialize = async ({
47-
value: overmind,
4846
state,
4947
actions,
5048
effects
51-
}) => {
49+
}, overmind) => {
5250
const initialData = await effects.api.getInitialData()
5351
state.initialData = initialData
5452
}

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ export default (ts) =>
55
code: `
66
import { Operator, mutate } from 'overmind'
77
8-
export const changeFoo: Operator = mutate(({ state }) => {
9-
state.foo = 'bar'
10-
})
8+
export const changeFoo: <T>() => Operator<T> = () =>
9+
mutate(({ state }) => {
10+
state.foo = 'bar'
11+
})
1112
`,
1213
},
1314
]
@@ -16,9 +17,10 @@ export const changeFoo: Operator = mutate(({ state }) => {
1617
code: `
1718
import { mutate } from 'overmind'
1819
19-
export const changeFoo = mutate(({ state }) => {
20-
state.foo = 'bar'
21-
})
20+
export const changeFoo = () =>
21+
mutate(({ state }) => {
22+
state.foo = 'bar'
23+
})
2224
`,
2325
},
2426
]

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,27 @@ export default (ts) =>
22
ts
33
? [
44
{
5+
fileName: 'operators.ts',
56
code: `
67
import { Operator, mutate } from 'overmind'
78
8-
export const setUser: Operator<User> = mutate(({ value: user, state }) => {
9-
state.user = user
10-
})
9+
export const setUser: () => Operator<User> = () =>
10+
mutate(function setUser({ state }, user) {
11+
state.user = user
12+
})
1113
`,
1214
},
1315
]
1416
: [
1517
{
18+
fileName: 'operators.js',
1619
code: `
1720
import { mutate } from 'overmind'
1821
19-
export const setUser = mutate(({ value: user, state }) => {
20-
state.user = user
21-
})
22+
export const setUser = () =>
23+
mutate(function setUser({ state }, user) {
24+
state.user = user
25+
})
2226
`,
2327
},
2428
]

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export default (ts) =>
22
ts
33
? [
44
{
5+
fileName: 'actions.ts',
56
code: `
67
import { Operator, pipe, mutate, catchError } from 'overmind'
78
@@ -26,6 +27,7 @@ export const doSomething: Operator<string> = pipe(
2627
]
2728
: [
2829
{
30+
fileName: 'actions.js',
2931
code: `
3032
import { pipe, mutate, catchError } from 'overmind'
3133

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,28 @@ export default (ts) =>
22
ts
33
? [
44
{
5+
fileName: 'actions.ts',
56
code: `
67
import { Operator, pipe, debounce } from 'overmind'
7-
import { performSearch } from './operators'
8+
import * as o from './operators'
89
910
export const search: Operator<string> = pipe(
1011
debounce(200),
11-
performSearch
12+
o.performSearch()
1213
)
1314
`,
1415
},
1516
]
1617
: [
1718
{
19+
fileName: 'actions.js',
1820
code: `
1921
import { pipe, debounce } from 'overmind'
20-
import { performSearch } from './operators'
22+
import * as o from './operators'
2123
2224
export const search = pipe(
2325
debounce(200),
24-
performSearch
26+
o.performSearch()
2527
)
2628
`,
2729
},

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,27 @@ export default (ts) =>
22
ts
33
? [
44
{
5+
fileName: 'operators.ts',
56
code: `
67
import { Operator, filter } from 'overmind'
78
8-
export const lengthGreaterThan: (length: number) => Operator<string> =
9-
(length) => filter(({ value }) => value.length > length)
9+
export const lengthGreaterThan: (length: number) => Operator<string> = (length) =>
10+
filter(function lengthGreaterThan(_, value) {
11+
return value.length > length
12+
})
1013
`,
1114
},
1215
]
1316
: [
1417
{
18+
fileName: 'operators.js',
1519
code: `
1620
import { filter } from 'overmind'
1721
1822
export const lengthGreaterThan = (length) =>
19-
filter(({ value }) => value.length > length)
23+
filter(function lengthGreaterThan(_, value) {
24+
return value.length > length
25+
})
2026
`,
2127
},
2228
]

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,29 @@ export default (ts) =>
22
ts
33
? [
44
{
5+
fileName: 'actions.ts',
56
code: `
67
import { Operator, pipe, forEach } from 'overmind'
78
import { Post } from './state'
8-
import { getPosts, getAuthor } from './operators'
9+
import * as o from './operators'
910
1011
export const openPosts: Operator<string, Post[]> = pipe(
11-
getPosts,
12-
forEach(getAuthor)
12+
o.getPosts(),
13+
forEach(o.getAuthor())
1314
)
1415
`,
1516
},
1617
]
1718
: [
1819
{
20+
fileName: 'actions.js',
1921
code: `
2022
import { pipe, forEach } from 'overmind'
21-
import { getPosts, getAuthor } from './operators'
23+
import * as o from './operators'
2224
2325
export const openPosts = pipe(
24-
getPosts,
25-
forEach(getAuthor)
26+
o.getPosts(),
27+
forEach(o.getAuthor())
2628
)
2729
`,
2830
},

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

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,51 +2,56 @@ export default (ts) =>
22
ts
33
? [
44
{
5-
fileName: 'overmind/operators.ts',
5+
fileName: 'operators.ts',
66
code: `
77
import { fork, Operator } from 'overmind'
88
import { User } from './state'
99
10-
export const forkUserType: (paths: { [key: string]: Operator<User> }) => Operator<User> =
11-
(paths) => fork(({ value: user }) => user.type, paths)
10+
export const forkUserType: (paths: { [key: string]: Operator<User> }) => Operator<User> = (paths) =>
11+
fork(function forkUserType(_, user) {
12+
return user.type
13+
}, paths)
1214
`,
1315
},
1416
{
15-
fileName: 'overmind/actions.ts',
17+
fileName: 'actions.ts',
1618
code: `
1719
import { Operator, pipe } from 'overmind'
18-
import { forkUserType, doThis, doThat } from './operators'
20+
import * as o from './operators'
1921
2022
export const getUser: Operator<string, User> = pipe(
21-
getUser,
22-
forkUserType({
23-
admin: doThis,
24-
superuser: doThat
23+
o.getUser(),
24+
o.forkUserType({
25+
admin: o.doThis(),
26+
superuser: o.doThat()
2527
})
2628
)
2729
`,
2830
},
2931
]
3032
: [
3133
{
32-
fileName: 'overmind/operators.ts',
34+
fileName: 'operators.js',
3335
code: `
3436
import { fork } from 'overmind'
3537
36-
export const forkUserType = (paths) => fork(({ value: user }) => user.type, paths)
38+
export const forkUserType = (paths) =>
39+
fork(function forkUserType(_, user) {
40+
return user.type
41+
}, paths)
3742
`,
3843
},
3944
{
40-
fileName: 'overmind/actions.ts',
45+
fileName: 'actions.js',
4146
code: `
4247
import { pipe } from 'overmind'
43-
import { forkUserType, doThis, doThat } from './operators'
48+
import * as o from './operators'
4449
4550
export const getUser = pipe(
46-
getUser,
47-
forkUserType({
48-
admin: doThis,
49-
superuser: doThat
51+
o.getUser(),
52+
o.forkUserType({
53+
admin: o.doThis(),
54+
superuser: o.doThat()
5055
})
5156
)
5257
`,

0 commit comments

Comments
 (0)