Skip to content

Commit 7b1d001

Browse files
docs(website): update docs to latest API, other fixes
1 parent 0030a36 commit 7b1d001

File tree

22 files changed

+232
-126
lines changed

22 files changed

+232
-126
lines changed

packages/overmind-website/api/action.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@
44
h(Example, { name: "api/action"})
55
```
66

7-
An action is where you write the logic of the application. Every action receives one argument and that is the configuration of your application:
7+
An action is where you write the logic of the application. Every action receives at least on argument and that is the **context**. This is the signature of the context:
88

99
`{ state, actions, effects }`
1010

11-
This *injected* configuration allows Overmind to understand from where you are chaing 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.
11+
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.
1212

13-
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.
13+
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.
14+
15+
## Payload
16+
17+
When an action is called you can optionally pass it a payload. This payload is received as the second argument to the action.
18+
19+
```marksy
20+
h(Example, { name: "api/action_payload"})
21+
```
22+
23+
```marksy
24+
h(Notice, null, "There is only one argument, which means if you want to pass multiple values you have to do so with an object")
25+
```

packages/overmind-website/api/overmind.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ It is possible to listen to all mutations performed in Overmind. This allows you
1616
h(Example, { name: "api/app_addMutationListener" })
1717
```
1818

19+
## addFlushListener
20+
21+
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.
22+
23+
```marksy
24+
h(Example, { name: "api/app_addFlushListener" })
25+
```
26+
1927

2028
## options.devtools
2129
If you develop your app on localhost the application connects to the devtools on **localhost:3031**. You can change this in case you need to use an IP address, the devtools is configured with a different port or you want to connect to localhost (with default port) even though the app is not on localhost.

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

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,22 @@ export default (ts) =>
55
code: `
66
import { Action } from 'overmind'
77
8-
export const changeTitle: Action<string> = ({ value: title, state }) => {
9-
state.title = title
8+
export const getPosts: Action = async ({ state, effects }) => {
9+
state.isLoadingPosts = true
10+
state.posts = await effects.api.getPosts()
11+
state.isLoadingPosts = false
1012
}
1113
`,
1214
},
13-
{
14-
code: `
15-
import { Action } from 'overmind'
16-
17-
export const getItem: Action<number> = async ({ value: id, state, effects }) => {
18-
const item = await effects.api.getItem(id)
19-
state.items.push(item)
20-
}
21-
`,
22-
},
2315
]
2416
: [
2517
{
2618
code: `
27-
export const changeTitle = ({ value: title, state }) => {
28-
state.title = title
19+
export const getPosts = async ({ state, effects }) => {
20+
state.isLoadingPosts = true
21+
state.posts = await effects.api.getPosts()
22+
state.isLoadingPosts = false
2923
}
3024
`,
3125
},
32-
{
33-
code: `
34-
export const getItem = async ({ value: id, state, effects }) => {
35-
const item = await effects.api.getItem(id)
36-
state.items.push(item)
37-
}
38-
`,
39-
},
4026
]
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export default (ts) =>
2+
ts
3+
? [
4+
{
5+
code: `
6+
import { Action } from 'overmind'
7+
8+
export const setTitle: Action<string> = async ({ state }, title) => {
9+
state.title = title
10+
}
11+
`,
12+
},
13+
]
14+
: [
15+
{
16+
code: `
17+
export const setTitle = async ({ state }, title) => {
18+
state.title = title
19+
}
20+
`,
21+
},
22+
]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { tsAppIndex } from '../templates'
2+
3+
export default (ts, view) =>
4+
ts
5+
? [
6+
{
7+
fileName: 'overmind/onInitialize.ts',
8+
code: `
9+
import { OnInitialize } from 'overmind'
10+
11+
const onInitialize: OnInitialize = async ({ state, effects }, overmind) => {
12+
overmind.addFlushListener(effects.history.addMutations)
13+
}
14+
15+
export default onInitialize
16+
`,
17+
},
18+
]
19+
: [
20+
{
21+
fileName: 'overmind/onInitialize.js',
22+
code: `
23+
const onInitialize = async ({ state, effects }, overmind) => {
24+
overmind.addFlushListener(effects.history.addMutations)
25+
}
26+
27+
export default onInitialize
28+
`,
29+
},
30+
]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default (ts, view) =>
88
code: `
99
import { OnInitialize } from 'overmind'
1010
11-
const onInitialize: OnInitialize = async ({ value: overmind, state, localStorage }) => {
11+
const onInitialize: OnInitialize = async ({ state, localStorage }, overmind) => {
1212
overmind.addMutationListener((mutation) => {
1313
if (mutation.path.indexOf('todos') === 0) {
1414
localStorage.set('todos', state.todos)
@@ -24,7 +24,7 @@ export default onInitialize
2424
{
2525
fileName: 'overmind/onInitialize.js',
2626
code: `
27-
const onInitialize = async ({ value: overmind, state, localStorage }) => {
27+
const onInitialize = async ({ state, localStorage }, overmind) => {
2828
overmind.addMutationListener((mutation) => {
2929
if (mutation.path.indexOf('todos') === 0) {
3030
localStorage.set('todos', state.todos)

packages/overmind-website/examples/guide/goingfunctional/actionoperator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ export default (ts) =>
66
code: `
77
import { Action, Operator, action } from 'overmind'
88
9-
export const plainAction: Action = ({ value, state }) => {
9+
export const plainAction: Action = ({ state }, value) => {
1010
1111
}
1212
13-
export const functionlAction: Operator = action(({ value, state }) => {
13+
export const functionlAction: Operator = action(({ state }, value) => {
1414
1515
})
1616
`,
@@ -22,11 +22,11 @@ export const functionlAction: Operator = action(({ value, state }) => {
2222
code: `
2323
import { action } from 'overmind'
2424
25-
export const plainAction = ({ value, state }) => {
25+
export const plainAction = ({ state }, value) => {
2626
2727
}
2828
29-
export const functionlAction = action(({ value, state }) => {
29+
export const functionlAction = action(({ state }, value) => {
3030
3131
})
3232
`,

packages/overmind-website/examples/guide/goingfunctional/clean.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export const search: Operator<Event> = pipe(
1111
getEventTargetValue,
1212
lengthGreaterThan(2),
1313
debounce(200),
14-
action(async ({ value: query, state, effects }) => {
14+
action(async ({ state, effects }, query) => {
1515
state.isSearching = true
1616
state.searchResult = await effects.api.search(query)
1717
state.isSearching = false
@@ -25,10 +25,10 @@ export const search: Operator<Event> = pipe(
2525
import { Operator, map, filter } from 'overmind'
2626
2727
const getEventTargetValue: Operator<Event, string> =
28-
map(({ value }) => value.currentTarget.value)
28+
map((_, value) => value.currentTarget.value)
2929
3030
const lengthGreaterThan: (length: number) => Operator<string> =
31-
(length) => filter(({ value }) => value.length > length)
31+
(length) => filter((_, value) => value.length > length)
3232
3333
`,
3434
},
@@ -44,7 +44,7 @@ export const search = pipe(
4444
getEventTargetValue,
4545
lengthGreaterThan(2),
4646
debounce(200),
47-
action(async ({ value: query, state, effects }) => {
47+
action(async ({ state, effects }, query) => {
4848
state.isSearching = true
4949
state.searchResult = await effects.api.search(query)
5050
state.isSearching = false
@@ -57,9 +57,9 @@ export const search = pipe(
5757
code: `
5858
import { map, filter } from 'overmind'
5959
60-
export const getEventTargetValue = map(({ value }) => value.currentTarget.value)
60+
export const getEventTargetValue = map((_, value) => value.currentTarget.value)
6161
62-
export const lengthGreaterThan = (length) => filter(({ value }) => value.length > length)
62+
export const lengthGreaterThan = (length) => filter((_, value) => value.length > length)
6363
`,
6464
},
6565
]

packages/overmind-website/examples/guide/goingfunctional/factory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default (ts) =>
77
import { Operator, filter } from 'overmind'
88
99
const lengthGreaterThan: (length: number) => Operator<string> =
10-
(length) => filter(({ value }) => value.length > length)
10+
(length) => filter((_, value) => value.length > length)
1111
1212
`,
1313
},
@@ -18,7 +18,7 @@ const lengthGreaterThan: (length: number) => Operator<string> =
1818
code: `
1919
import { map, filter } from 'overmind'
2020
21-
export const lengthGreaterThan = (length) => filter(({ value }) => value.length > length)
21+
export const lengthGreaterThan = (length) => filter((_, value) => value.length > length)
2222
`,
2323
},
2424
]

packages/overmind-website/examples/guide/goingfunctional/map.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default (ts) =>
66
code: `
77
import { Operator, map } from 'overmind'
88
9-
export const getTargetValue: Operator<Event, string> = map(({ value : event }) =>
9+
export const getTargetValue: Operator<Event, string> = map((_, event) =>
1010
event.currentTarget.value
1111
)
1212
`,
@@ -19,7 +19,7 @@ import { getTargetValue } from './operators'
1919
2020
export const setValue: Operator<Event, string> = pipe(
2121
getTargetValue,
22-
action(({ state, value }) => {
22+
action(({ state}, value) => {
2323
state.value = value
2424
})
2525
)
@@ -32,7 +32,7 @@ export const setValue: Operator<Event, string> = pipe(
3232
code: `
3333
import { map } from 'overmind'
3434
35-
export const getTargetValue = map(({ value : event }) =>
35+
export const getTargetValue = map((_, event) =>
3636
event.currentTarget.value
3737
)
3838
`,
@@ -45,7 +45,7 @@ import { getTargetValue } from './operators'
4545
4646
export const setValue = pipe(
4747
getTargetValue,
48-
action(({ state, value }) => {
48+
action(({ state }, value) => {
4949
state.value = value
5050
})
5151
)

0 commit comments

Comments
 (0)