Skip to content

Commit 1e479e5

Browse files
docs(website): fix router docs
1 parent a3f4d76 commit 1e479e5

File tree

7 files changed

+215
-198
lines changed

7 files changed

+215
-198
lines changed

packages/overmind-website/examples/guide/routing/compose.ts

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,36 @@ export default (ts) =>
44
{
55
fileName: 'overmind/actions.ts',
66
code: `
7-
import { Operator, pipe } from 'overmind'
8-
import * as o from './operators'
7+
import { Action, Operator, pipe, action } from 'overmind'
98
10-
export const showHomePage: Operator<void, any> =
11-
o.setPage('home')
9+
export const showHomePage: Action = ({ state }) => {
10+
state.currentPage = 'home'
11+
}
1212
13-
export const showUsersPage: Operator<void, any> = pipe(
14-
o.unsetModalUserId,
15-
o.setPage('users'),
16-
o.setLoadingUsers(true),
17-
o.getUsers,
18-
o.setUsers,
19-
o.setLoadingUsers(false)
20-
)
13+
export const showUsersPage: Operator<{ id?: string }> = action(async ({
14+
value: params,
15+
state,
16+
api
17+
}) => {
18+
if (!params.id) state.modalUser = null
19+
20+
state.currentPage = 'users'
21+
state.isLoadingUsers = true
22+
state.users = await api.getUsers()
23+
state.isLoadingUsers = false
24+
})
2125
22-
export const showUserModal: Operator<{ id: string }, any> = pipe(
23-
showUsersPage, // <= We just add the operator managing opening the users page
24-
o.setModalUserId,
25-
o.setLoadingUserWithDetails(true),
26-
o.getUserWithDetails,
27-
o.updateUserWithDetails,
28-
o.setLoadingUserWithDetails(false)
26+
export const showUserModal: Operator<{ id: string }> = pipe(
27+
showUsersPage,
28+
action(async ({
29+
value: params,
30+
state,
31+
api
32+
}) => {
33+
state.isLoadingUserDetails = true
34+
state.modalUser = await api.getUserWithDetails(params.id)
35+
state.isLoadingUserDetails = false
36+
})
2937
)
3038
`,
3139
},
@@ -34,28 +42,27 @@ export const showUserModal: Operator<{ id: string }, any> = pipe(
3442
{
3543
fileName: 'overmind/actions.js',
3644
code: `
37-
import { pipe } from 'overmind'
38-
import * as o from './operators'
45+
import { pipe, action } from 'overmind'
3946
40-
export const showHomePage =
41-
o.setPage('home')
47+
export const showHomePage = ({ state }) => {
48+
state.currentPage = 'home'
49+
}
4250
43-
export const showUsersPage = pipe(
44-
o.unsetModalUserId,
45-
o.setPage('users'),
46-
o.setLoadingUsers(true),
47-
o.getUsers,
48-
o.setUsers,
49-
o.setLoadingUsers(false)
50-
)
51+
export const showUsersPage = action(async ({ state, api }) => {
52+
state.modalUser = null
53+
state.currentPage = 'users'
54+
state.isLoadingUsers = true
55+
state.users = await api.getUsers()
56+
state.isLoadingUsers = false
57+
})
5158
5259
export const showUserModal = pipe(
53-
showUsersPage, // <= We just add the operator managing opening the users page
54-
o.setModalUserId,
55-
o.setLoadingUserWithDetails(true),
56-
o.getUserWithDetails,
57-
o.updateUserWithDetails,
58-
o.setLoadingUserWithDetails(false)
60+
showUsersPage,
61+
action(async ({ value: params, state, api }) => {
62+
state.isLoadingUserDetails = true
63+
state.modalUser = await api.getUserWithDetails(params.id)
64+
state.isLoadingUserDetails = false
65+
})
5966
)
6067
`,
6168
},

packages/overmind-website/examples/guide/routing/effect.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ export default (ts) =>
66
code: `
77
import page from 'page'
88
9+
interface IParams {
10+
[param: string]: string
11+
}
12+
913
export const router = {
10-
route<T extends object>(route: string, action: (params: T) => void) {
14+
route<T extends IParams>(route: string, action: (params: T) => void) {
1115
page(route, ({ params }) => action(params))
1216
},
1317
start: () => page.start(),

packages/overmind-website/examples/guide/routing/parallel.ts

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,36 @@ export default (ts) =>
44
{
55
fileName: 'overmind/actions.ts',
66
code: `
7-
import { Operator, pipe, parallel } from 'overmind'
8-
import * as o from './operators'
7+
import { Action, Operator, action, parallel } from 'overmind'
98
10-
export const showHomePage: Operator<void, any> =
11-
o.setPage('home')
9+
export const showHomePage: Action = ({ state }) => {
10+
state.currentPage = 'home'
11+
}
1212
13-
export const showUsersPage: Operator<void, any> = pipe(
14-
o.unsetModalUserId,
15-
o.setPage('users'),
16-
o.setLoadingUsers(true),
17-
o.getUsers,
18-
o.setUsers,
19-
o.setLoadingUsers(false)
20-
)
13+
export const showUsersPage: Operator<{ id?: string }> = action(async ({
14+
value: params,
15+
state,
16+
api
17+
}) => {
18+
if (!params.id) state.modalUser = null
2119
22-
const getUserWithDetails: Operator<{ id: string }, any> = pipe(
23-
o.setLoadingUserWithDetails(true),
24-
o.getUserWithDetails,
25-
o.updateUserWithDetails,
26-
o.setLoadingUserWithDetails(false)
27-
)
20+
state.currentPage = 'users'
21+
state.isLoadingUsers = true
22+
state.users = await api.getUsers()
23+
state.isLoadingUsers = false
24+
})
2825
29-
export const showUserModal: Operator<{ id: string }, any> = pipe(
30-
o.setModalUserId,
31-
parallel([
32-
showUsersPage,
33-
getUserWithDetails
34-
])
26+
export const showUserModal: Operator<{ id: string }> = parallel(
27+
showUsersPage,
28+
action(async ({
29+
value: params,
30+
state,
31+
api
32+
}) => {
33+
state.isLoadingUserDetails = true
34+
state.modalUser = await api.getUserWithDetails(params.id)
35+
state.isLoadingUserDetails = false
36+
})
3537
)
3638
`,
3739
},
@@ -40,34 +42,32 @@ export const showUserModal: Operator<{ id: string }, any> = pipe(
4042
{
4143
fileName: 'overmind/actions.js',
4244
code: `
43-
import { pipe, parallel } from 'overmind'
44-
import * as o from './operators'
45+
import { parallel, action } from 'overmind'
4546
46-
export const showHomePage =
47-
o.setPage('home')
47+
export const showHomePage = ({ state }) => {
48+
state.currentPage = 'home'
49+
}
4850
49-
export const showUsersPage = pipe(
50-
o.unsetModalUserId,
51-
o.setPage('users'),
52-
o.setLoadingUsers(true),
53-
o.getUsers,
54-
o.setUsers,
55-
o.setLoadingUsers(false)
56-
)
51+
export const showUsersPage = action(async ({
52+
value: params,
53+
state,
54+
api
55+
}) => {
56+
if (!params.id) state.modalUser = null
5757
58-
const getUserWithDetails = pipe(
59-
o.setLoadingUserWithDetails(true),
60-
o.getUserWithDetails,
61-
o.updateUserWithDetails,
62-
o.setLoadingUserWithDetails(false)
63-
)
58+
state.currentPage = 'users'
59+
state.isLoadingUsers = true
60+
state.users = await api.getUsers()
61+
state.isLoadingUsers = false
62+
})
6463
65-
export const showUserModal = pipe(
66-
o.setModalUserId,
67-
parallel([
68-
showUsersPage,
69-
getUserWithDetails
70-
])
64+
export const showUserModal = parallel(
65+
showUsersPage,
66+
action(async ({ value: params, state, api }) => {
67+
state.isLoadingUserDetails = true
68+
state.modalUser = await api.getUserWithDetails(params.id)
69+
state.isLoadingUserDetails = false
70+
})
7171
)
7272
`,
7373
},

packages/overmind-website/examples/guide/routing/setup.ts

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,57 @@ export default (ts) =>
44
{
55
fileName: 'overmind/actions.ts',
66
code: `
7-
import { Operator, pipe } from 'overmind'
8-
import * as o from './operators'
7+
import { Action } from 'overmind'
98
10-
export const showHomePage: Operator<void, any> =
11-
o.setPage('home')
9+
export const routeHomePage: Action = ({ state }) => {
10+
state.currentPage = 'home'
11+
}
1212
13-
export const showUsersPage: Operator<void, any> = pipe(
14-
o.unsetModalUserId,
15-
o.setPage('users'),
16-
o.setLoadingUsers(true),
17-
o.getUsers,
18-
o.setUsers,
19-
o.setLoadingUsers(false)
20-
)
13+
export const routeUsersPage: Action = async ({ state, api }) => {
14+
state.user = null
15+
state.currentPage = 'users'
16+
state.isLoadingUsers = true
17+
state.users = await api.getUsers()
18+
state.isLoadingUsers = false
19+
}
2120
22-
export const showUserModal: Operator<{ id: string }, any> = pipe(
23-
o.setModalUserId,
24-
o.setLoadingUserWithDetails(true),
25-
o.getUserWithDetails,
26-
o.updateUserWithDetails,
27-
o.setLoadingUserWithDetails(false)
28-
)
21+
export const routeUser: Action<{ id: string }> = async ({
22+
value: params,
23+
state,
24+
api
25+
}) => {
26+
state.isLoadingUserDetails = true
27+
state.modalUser = await api.getUserWithDetails(params.id)
28+
state.isLoadingUserDetails = false
29+
}
2930
`,
3031
},
3132
]
3233
: [
3334
{
3435
fileName: 'overmind/actions.js',
3536
code: `
36-
import { pipe } from 'overmind'
37-
import * as o from './operators'
37+
export const routeHomePage = ({ state }) => {
38+
state.currentPage = 'home'
39+
}
3840
39-
export const showHomePage =
40-
o.setPage('home')
41+
export const routeUsersPage = async ({ state, api }) => {
42+
state.user = null
43+
state.currentPage = 'users'
44+
state.isLoadingUsers = true
45+
state.users = await api.getUsers()
46+
state.isLoadingUsers = false
47+
}
4148
42-
export const showUsersPage = pipe(
43-
o.unsetModalUserId,
44-
o.setPage('users'),
45-
o.setLoadingUsers(true),
46-
o.getUsers,
47-
o.setUsers,
48-
o.setLoadingUsers(false)
49-
)
50-
51-
export const showUserModal = pipe(
52-
o.setModalUserId,
53-
o.setLoadingUserWithDetails(true),
54-
o.getUserWithDetails,
55-
o.updateUserWithDetails,
56-
o.setLoadingUserWithDetails(false)
57-
)
49+
export const routeUser = async ({
50+
value: params,
51+
state,
52+
api
53+
}) => {
54+
state.isLoadingUserDetails = true
55+
state.modalUser = await api.getUserWithDetails(params.id)
56+
state.isLoadingUserDetails = false
57+
}
5858
`,
5959
},
6060
]

0 commit comments

Comments
 (0)