Skip to content

Commit 1562c38

Browse files
docs(website): make state usage more clear
1 parent d415aa7 commit 1562c38

File tree

3 files changed

+60
-4
lines changed

3 files changed

+60
-4
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
export default (ts) =>
2+
ts
3+
? [
4+
{
5+
fileName: 'overmind/index.ts',
6+
code: `
7+
import { state } from './state'
8+
9+
export const config = {
10+
state
11+
}
12+
13+
declare module 'overmind' {
14+
interface Config extends IConfig<typeof config> {}
15+
}
16+
`,
17+
},
18+
{
19+
fileName: 'index.ts',
20+
code: `
21+
import { createOvermind } from 'overmind'
22+
import { config } from './overmind'
23+
24+
const overmind = createOvermind(config)
25+
`,
26+
},
27+
]
28+
: [
29+
{
30+
fileName: 'overmind/index.js',
31+
code: `
32+
import { state } from './state'
33+
34+
export const config = {
35+
state
36+
}
37+
`,
38+
},
39+
{
40+
fileName: 'index.ts',
41+
code: `
42+
import { createOvermind } from 'overmind'
43+
import { config } from './overmind'
44+
45+
const overmind = createOvermind(config)
46+
`,
47+
},
48+
]

packages/overmind-website/examples/guide/structuringtheapp/actions.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ export default (ts, view) =>
66
code: `
77
import { Action } from 'overmind'
88
9-
export const handleError: Action = () => {}
9+
export const handleError: Action = ({ state }) => {
10+
// All actions can access all state
11+
state.posts
12+
state.admin
13+
}
1014
`,
1115
},
1216
{
@@ -37,7 +41,11 @@ export const changeUserAccess: AsyncAction = async () => {}
3741
{
3842
fileName: 'overmind/posts/internalActions.js',
3943
code: `
40-
export const handleError = () => {}
44+
export const handleError = ({ state }) => {
45+
// All actions can access all state
46+
state.posts
47+
state.admin
48+
}
4149
`,
4250
},
4351
{

packages/overmind-website/guides/beginner/02_definingstate.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,10 @@ h(Example, { name: "guide/definingstate/define" })
125125
h(TypescriptNotice, null, "Is is important that you define your state with a **type**, do **NOT** use an **interface**")
126126
```
127127

128-
As your application grows you will most likely move parts of the state to their own namespaces. An example of that could be:
128+
To expose the state on the instance you can follow this recommended pattern:
129129

130130
```marksy
131-
h(Example, { name: "guide/definingstate/namespaces" })
131+
h(Example, { name: "guide/definingstate/bringtogether" })
132132
```
133133

134134
## Summary

0 commit comments

Comments
 (0)