Skip to content

Commit a9d87fc

Browse files
docs(website): update docs to latest changes
1 parent e8ed416 commit a9d87fc

File tree

9 files changed

+29
-17
lines changed

9 files changed

+29
-17
lines changed

packages/overmind-website/api/action.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
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 called the **context**. This context holds the state of application, whatever effects you have defined and optionally value passed in when the action was called.
7+
An action is where you write the logic of the application. Every action receives one argument called the **context**. This context holds:
88

9-
This context gives Overmind the ability to understand what state you are changing and what effects you are running. Additionally this context makes your actions highly testable as it can easily be mocked.
9+
`{ state, actions, ...effects }`
10+
11+
This context gives Overmind the primarily the ability to understand what state you are changing and what effects you are running. You can also use other actions defined in your application. Additionally this context makes your actions highly testable as it can easily be mocked.
1012

1113
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.

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ export default (ts, view) =>
88
code: `
99
import { OnInitialize } from 'overmind'
1010
11-
const onInitialize: OnInitialize = async ({ value: overmind, state, api }) => {
11+
const onInitialize: OnInitialize = async ({
12+
value: overmind,
13+
state,
14+
actions,
15+
api
16+
}) => {
1217
const initialData = await api.getInitialData()
1318
state.initialData = initialData
1419
}
@@ -38,7 +43,12 @@ const config = {
3843
{
3944
fileName: 'overmind/onInitialize.js',
4045
code: `
41-
const onInitialize = async ({ value: overmind, state, api }) => {
46+
const onInitialize = async ({
47+
value: overmind,
48+
state,
49+
actions,
50+
api
51+
}) => {
4252
const initialData = await api.getInitialData()
4353
state.initialData = initialData
4454
}

packages/overmind-website/examples/guide/usingovermindwithreact/hoc.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import { connect, Connect } from '../overmind'
3434
type Props = {} & Connect
3535
3636
const App: React.FunctionComponent<Props> = ({ overmind }) => {
37-
const { state, actions } = overmind
37+
const { state, actions, effects, addMutationListener } = overmind
3838
3939
return <div />
4040
}
@@ -65,7 +65,7 @@ import React from 'react'
6565
import { connect } from '../overmind'
6666
6767
const App = ({ overmind }) => {
68-
const { state, actions } = overmind
68+
const { state, actions, effects, addMutationListener } = overmind
6969
7070
return <div />
7171
}

packages/overmind-website/examples/guide/usingovermindwithreact/hoc_compareprop.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ class App extends React.Component<Props> {
1414
return this.props.overmind !== nextProps.overmind
1515
}
1616
render() {
17-
const { state, actions } = this.props.overmind
18-
1917
return <div />
2018
}
2119
}
@@ -36,8 +34,6 @@ class App extends React.Component {
3634
return this.props.overmind !== nextProps.overmind
3735
}
3836
render() {
39-
const { state, actions } = this.props.overmind
40-
4137
return <div />
4238
}
4339
}

packages/overmind-website/examples/guide/usingovermindwithreact/hook.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import * as React from 'react'
3030
import { useOvermind } from '../overmind'
3131
3232
const App: React.FunctionComponent = () => {
33-
const { state, actions } = useOvermind()
33+
const { state, actions, effects, addMutationListener } = useOvermind()
3434
3535
return <div />
3636
}
@@ -61,7 +61,7 @@ import React from 'react'
6161
import { useOvermind } from '../overmind'
6262
6363
const App = () => {
64-
const { state, actions } = useOvermind()
64+
const { state, actions, effects, addMutationListener } = useOvermind()
6565
6666
return <div />
6767
}

packages/overmind-website/guides/beginner/03_connectingcomponents.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,16 @@ All the actions defined in the Overmind application is available to connected co
6565
h(Example, { name: "guide/connectingcomponents/actions" })
6666
```
6767

68-
## Effects
68+
## Reactions
6969

7070
Sometimes you want to make something happen inside a component related to a state change. This is typically doing some manual work on the DOM. When you connect a component to overmind it also gets access to **addMutationListener**. This function allows you to subscribe to changes in state, mutations as we call them. Each mutation holds information about what kind of mutation it was, at what path it happened and even any arguments used in the mutation. You can use all this information to create an effect.
7171

7272
This example shows how you can scroll to the top of the page every time you change the current article of the app.
7373

7474
```marksy
7575
h(Example, { name: "guide/connectingcomponents/effects" })
76-
```
76+
```
77+
78+
## Effects
79+
80+
Any effects you define in your Overmind application is also exposed to the components. They can be found on the property **effects**. It is encouraged that you keep your logic inside actions, but you might be in a situation where you want some other relationship between components and Overmind. A shared effect is the way to go.

packages/overmind-website/guides/beginner/06_usingovermindwithreact.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ If you pass a state object or array as a property to a child component you will
2929
h(Example, { name: "guide/usingovermindwithreact/hoc_passprop" })
3030
```
3131

32-
### Effects
32+
### Reactions
3333

3434
To run effects in components based on changes to state you use the **addMutationListener** function in the lifecycle hooks of React.
3535

packages/overmind-website/guides/beginner/07_usingovermindwithangular.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ If you pass a state object or array as a property to a child component you will
2727
h(Example, { name: "guide/usingovermindwithangular/passprop" })
2828
```
2929

30-
## Effects
30+
## OvermindProvider
3131

3232
To run effects in components based on changes to state you use the **addMutationListener** function in the lifecycle hooks of Angular.
3333

packages/overmind-website/guides/beginner/08_usingovermindwithvue.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ If you pass a state object or array as a property to a child component you will
1717
h(Example, { name: "guide/usingovermindwithvue/passprops" })
1818
```
1919

20-
## Effects
20+
## OvermindProvider
2121

2222
To run effects in components based on changes to state you use the **addMutationListener** function in the lifecycle hooks of Vue.
2323

0 commit comments

Comments
 (0)