Skip to content

Commit 75ab789

Browse files
docs(website): update router docs
1 parent 21ec9ec commit 75ab789

File tree

7 files changed

+18
-42
lines changed

7 files changed

+18
-42
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ import { Operator, pipe } from 'overmind'
4444
import { Page } from './types'
4545
import * as o from './operators'
4646
47-
export const showHomePage: Operator<{}> = o.setPage(Page.HOME)
47+
export const showHomePage: Operator<void> = o.setPage(Page.HOME)
4848
49-
export const showUsersPage: Operator<{}> = pipe(
49+
export const showUsersPage: Operator<void> = pipe(
5050
o.setPage(Page.USERS),
5151
o.closeUserModal(),
5252
o.shouldLoadUsers(),

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ export default (ts) =>
66
code: `
77
import page from 'page'
88
9-
interface IParams {
9+
// We allow void type which is used to define "no params"
10+
type IParams = {
1011
[param: string]: string
11-
}
12+
} | void
1213
1314
export const router = {
1415
initialize(routes: { [url: string]: (params: IParams) => void }) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import { Operator, pipe, parallel } from 'overmind'
88
import { Page } from './types'
99
import * as o from './operators'
1010
11-
export const showHomePage: Operator<{}> = o.setPage(Page.HOME)
11+
export const showHomePage: Operator<void> = o.setPage(Page.HOME)
1212
13-
export const showUsersPage: Operator<{}> = pipe(
13+
export const showUsersPage: Operator<void> = pipe(
1414
o.setPage(Page.USERS),
1515
o.closeUserModal(),
1616
o.shouldLoadUsers(),

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ export default (ts) =>
77
import page from 'page'
88
import queryString from 'query-string'
99
10-
interface IParams {
11-
[param: string]: string
12-
}
10+
type IParams = {
11+
[param: string]: string
12+
} | void
1313
1414
export const router = {
1515
initialize(routes: { [url: string]: (IParams) => void }) {

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

Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -7,41 +7,16 @@ export default (ts) =>
77
import { Operator, mutate, filter } from 'overmind'
88
import { Page } from './types'
99
10-
export const closeUserModal: <T>() => Operator<T> = () =>
11-
mutate(function closeUserModal({ state }) {
12-
state.modalUser = null
13-
})
14-
15-
export const setPage: <T>(page: Page) => Operator<T> = () =>
16-
mutate(function setPage({ state }) {
17-
state.currentPage = page
18-
})
19-
20-
export const shouldLoadUsers: <T>() => Operator<T> = () =>
21-
filter(function shouldLoadUsers({ state }) {
22-
return !Boolean(state.users.length)
23-
})
24-
25-
export const loadUsers: <T>() => Operator<T> = () =>
26-
mutate(async function loadUsers({ state, effects }) {
27-
state.isLoadingUsers = true
28-
state.users = await effects.api.getUsers()
29-
state.isLoadingUsers = false
30-
})
10+
...
3111
32-
export const loadUserWithDetails: () => Operator<{ id: string }> = () =>
12+
export const loadUserWithDetails: <T extends { id: string }>() => Operator<T> = () =>
3313
mutate(async function loadUserWithDetails({ state, effects }, params) {
3414
state.isLoadingUserDetails = true
3515
state.modalUser = await effects.api.getUserWithDetails(params.id)
3616
state.isLoadingUserDetails = false
3717
})
3818
39-
export const shouldLoadUserWithDetails: <T>() => Operator<{ id: string }, T> = () =>
40-
filter(function shouldLoadUserWithDetails({ state }, params) {
41-
return !state.modalUser || state.modalUser.id !== params.id
42-
})
43-
44-
export const setCurrentUserModalTabIndex: <T>() => Operator<{ tab: string }, T> = () =>
19+
export const setCurrentUserModalTabIndex: <T extends { tab: string }>() => Operator<T> = () =>
4520
mutate(function setCurrentUserModalTabIndex({ state }, params) {
4621
state.currentUserModalTabIndex = Number(params.tab)
4722
})
@@ -54,9 +29,9 @@ import { Operator, pipe, parallel } from 'overmind'
5429
import { Page } from './types'
5530
import * as o from './operators'
5631
57-
export const showHomePage: Operator<{}> = o.setPage(Page.HOME)
32+
export const showHomePage: Operator<void> = o.setPage(Page.HOME)
5833
59-
export const showUsersPage: Operator<{}> = pipe(
34+
export const showUsersPage: Operator<void> = pipe(
6035
o.setPage(Page.USERS),
6136
o.closeUserModal(),
6237
o.shouldLoadUsers(),

packages/overmind-website/guides/intermediate/02_routing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ A straight forward way to solve this is to simply also change the page in the **
5757
h(Example, { name: "guide/routing/compose" })
5858
```
5959

60-
By splitting up all our logic into operators we were able to make our actions completely declarative and at the same time reuse logic across them. Very often applications share some, but not all logic. The *operators* file gives use maintaineable code and the *actions* file gives us readable code.
60+
By splitting up all our logic into operators we were able to make our actions completely declarative and at the same time reuse logic across them. The *operators* file gives use maintaineable code and the *actions* file gives us readable code.
6161

62-
We could actually make this better though. There is no reason to wait for the user of the modal to load before we load the users list in the background. We can fix this with the **parallel** operator. Now the list of users and the single user loads at the same time. That makes sense as loading a single user is probably faster than loading the whole list.
62+
We could actually make this better though. There is no reason to wait for the user of the modal to load before we load the users list in the background. We can fix this with the **parallel** operator. Now the list of users and the single user loads at the same time.
6363

6464
```marksy
6565
h(Example, { name: "guide/routing/parallel" })

packages/overmind-website/src/overmind/effects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export const router = (() => {
4242
getPath() {
4343
return currentPath
4444
},
45-
route(url: string, action: (payload: RouteContext<any>) => void) {
45+
route(url: string, action: (payload: RouteContext<{} | void>) => void) {
4646
page(url, ({ params, pathname, querystring }) => {
4747
// We want to preserve the query
4848
const query = queryString.parse(querystring)

0 commit comments

Comments
 (0)