Skip to content

Commit 7b85e07

Browse files
docs(website): improve structuring the app guide
1 parent 4566327 commit 7b85e07

File tree

5 files changed

+221
-1
lines changed

5 files changed

+221
-1
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
export default (ts, view) =>
2+
ts
3+
? [
4+
{
5+
fileName: 'overmind/posts/actions.ts',
6+
code: `
7+
import { Action } from 'overmind'
8+
9+
export const getPosts: Action = () => {}
10+
11+
export const addNewPost: Action = () => {}
12+
`,
13+
},
14+
{
15+
fileName: 'overmind/admin/actions.ts',
16+
code: `
17+
import { Action } from 'overmind'
18+
19+
export const getUsers: Action = () => {}
20+
21+
export const changeUserAccess: Action = () => {}
22+
`,
23+
},
24+
]
25+
: [
26+
{
27+
fileName: 'overmind/posts/actions.js',
28+
code: `
29+
export const getPosts = () => {}
30+
31+
export const addNewPost = () => {}
32+
`,
33+
},
34+
{
35+
fileName: 'overmind/admin/actions.js',
36+
code: `
37+
export const getUsers = () => {}
38+
39+
export const changeUserAccess = () => {}
40+
`,
41+
},
42+
]
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
export default (ts, view) =>
2+
ts
3+
? [
4+
{
5+
fileName: 'overmind/posts/effects.ts',
6+
code: `
7+
export const postsApi = {
8+
getPostsFromServer(): Promise<Post[]> {}
9+
}
10+
`,
11+
},
12+
{
13+
fileName: 'overmind/admin/effects.ts',
14+
code: `
15+
export const adminApi = {
16+
getUsersFromServer(): Promise<User[]> {}
17+
}
18+
`,
19+
},
20+
]
21+
: [
22+
{
23+
fileName: 'overmind/posts/effects.js',
24+
code: `
25+
export const postsApi = {
26+
getPostsFromServer() {}
27+
}
28+
`,
29+
},
30+
{
31+
fileName: 'overmind/admin/effects.js',
32+
code: `
33+
export const adminApi = {
34+
getUsersFromServer() {}
35+
}
36+
`,
37+
},
38+
]

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

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
export default (ts, view) =>
22
ts
33
? [
4+
{
5+
fileName: 'overmind/posts/index.ts',
6+
code: `
7+
import { state } from './state'
8+
import * as actions from './actions'
9+
import * as effects from './effects'
10+
11+
export {
12+
state,
13+
actions,
14+
effects
15+
}
16+
`,
17+
},
18+
{
19+
fileName: 'overmind/admin/index.ts',
20+
code: `
21+
import { state } from './state'
22+
import * as actions from './actions'
23+
import * as effects from './effects'
24+
25+
export {
26+
state,
27+
actions,
28+
effects
29+
}
30+
`,
31+
},
432
{
533
fileName: 'overmind/index.ts',
634
code: `
@@ -23,6 +51,34 @@ const overmind = new Overmind(config)
2351
},
2452
]
2553
: [
54+
{
55+
fileName: 'overmind/posts/index.js',
56+
code: `
57+
import { state } from './state'
58+
import * as actions from './actions'
59+
import * as effects from './effects'
60+
61+
export {
62+
state,
63+
actions,
64+
effects
65+
}
66+
`,
67+
},
68+
{
69+
fileName: 'overmind/admin/index.js',
70+
code: `
71+
import { state } from './state'
72+
import * as actions from './actions'
73+
import * as effects from './effects'
74+
75+
export {
76+
state,
77+
actions,
78+
effects
79+
}
80+
`,
81+
},
2682
{
2783
fileName: 'overmind/index.js',
2884
code: `
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
export default (ts, view) =>
2+
ts
3+
? [
4+
{
5+
fileName: 'overmind/posts/state.ts',
6+
code: `
7+
export type Post = {
8+
id: number
9+
title: string
10+
}
11+
12+
export type State = {
13+
posts: Post[]
14+
}
15+
16+
export const state: State = {
17+
posts: []
18+
}
19+
`,
20+
},
21+
{
22+
fileName: 'overmind/admin/state.ts',
23+
code: `
24+
export type User = {
25+
id: number
26+
name: string
27+
}
28+
29+
export type State = {
30+
users: User[]
31+
}
32+
33+
export const state: State = {
34+
users: []
35+
}
36+
`,
37+
},
38+
]
39+
: [
40+
{
41+
fileName: 'overmind/posts/state.js',
42+
code: `
43+
export const state = {
44+
posts: []
45+
}
46+
`,
47+
},
48+
{
49+
fileName: 'overmind/admin/state.js',
50+
code: `
51+
export const state = {
52+
users: []
53+
}
54+
`,
55+
},
56+
]

packages/overmind-website/guides/beginner/05_structuringtheapp.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,35 @@ But if we want to split up into actual domains it would look more like this:
2424
h(Example, { name: "guide/structuringtheapp/domains" })
2525
```
2626

27-
In this case each domain **index** file bring its own state, actions and effects together and the **app/index** file is responsible for bringing the configuration together. Let us look at how that can be accomplished.
27+
In this case each domain **index** file bring its own state, actions and effects together and the **app/index** file is responsible for bringing the configuration together.
28+
29+
## The state file
30+
31+
You will typically define your **state** file by exporting a single constant named *state*.
32+
33+
```marksy
34+
h(Example, { name: "guide/structuringtheapp/state" })
35+
```
36+
37+
## The actions file
38+
39+
The actions are exported individually by giving them a name and a definition.
40+
41+
```marksy
42+
h(Example, { name: "guide/structuringtheapp/actions" })
43+
```
44+
45+
## The effects file
46+
47+
The effects are also exported individually where you would typically organize the methods in an object, but this could have been a class instance or just a plain function as well.
48+
49+
```marksy
50+
h(Example, { name: "guide/structuringtheapp/effects" })
51+
```
52+
53+
## Bring it together
54+
55+
Now let us export the state, actions and effects for each module and bring it all together into a **namespaced** configuration.
2856

2957
```marksy
3058
h(Example, { name: "guide/structuringtheapp/namespaced" })

0 commit comments

Comments
 (0)