Skip to content

Commit a232b20

Browse files
docs(website): fix state docs
1 parent 0a16bec commit a232b20

File tree

10 files changed

+86
-43
lines changed

10 files changed

+86
-43
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export default (ts, view) =>
88
code: tsAppIndex(
99
view,
1010
`
11-
import * as state from './state'
11+
import { state } from './state'
1212
import * as effects from './effects'
1313
import * as actions from './actions'
1414
@@ -27,7 +27,7 @@ const config = {
2727
code: `
2828
import { Overmind } from 'overmind'
2929
import { createConnect } from 'overmind-${view}'
30-
import * as state from './state'
30+
import state from './state'
3131
import * as effects from './effects'
3232
import * as actions from './actions'
3333

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

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,16 @@ export type Item = {
1111
completed: boolean
1212
}
1313
14-
export const items: Item[] = []
14+
export type State = {
15+
items: Item[]
16+
completedItems: Derive<State, Item[]>
17+
}
1518
16-
export const completedItems: Derive<Item[]> = (state, rootState) =>
17-
state.items.filter(item => item.completed)
19+
export const state: State = {
20+
items: [],
21+
completedItems: (state, rootState) =>
22+
state.items.filter(item => item.completed)
23+
}
1824
`,
1925
},
2026
]
@@ -24,10 +30,11 @@ export const completedItems: Derive<Item[]> = (state, rootState) =>
2430
code: `
2531
import * as derived from './derived'
2632
27-
export const items = []
28-
29-
export const completedItems = (state, rootState) =>
30-
state.items.filter(item => item.completed)
33+
export default {
34+
items: [],
35+
completedItems: (state, rootState) =>
36+
state.items.filter(item => item.completed)
37+
}
3138
`,
3239
},
3340
]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default onInitialize
2222
view,
2323
`
2424
import onInitialize from './onInitialize'
25-
import * as state from './state'
25+
import { state } from './state'
2626
import * as actions from './actions'
2727
2828
const config = {
@@ -51,7 +51,7 @@ export default onInitialize
5151
code: `
5252
import { Overmind } from 'overmind'
5353
import onInitialize from './onInitialize'
54-
import * as state from './state'
54+
import { state } from './state'
5555
import * as actions from './actions'
5656
5757
const app = new Overmind({

packages/overmind-website/examples/guide/definingstate/define.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,26 @@ export type User = {
99
bio: string
1010
}
1111
12-
export let isLoading: boolean = false
12+
export type State = {
13+
isLoading: boolean
14+
user: User
15+
}
1316
14-
export let user: User = null
17+
export const state: State = {
18+
isLoading: false,
19+
user: null
20+
}
1521
`,
1622
},
1723
]
1824
: [
1925
{
2026
fileName: 'app/state.js',
2127
code: `
22-
export let isLoading = false
23-
24-
export let user = null
28+
export default {
29+
isLoading: false,
30+
user: null
31+
}
2532
`,
2633
},
2734
]

packages/overmind-website/examples/guide/definingstate/namespaces.ts

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,31 @@ export type Users = {
1313
[username: string]: User
1414
}
1515
16-
export let isLoadingUsers: boolean = false
16+
export type State = {
17+
isLoadingUsers: boolean
18+
users: Users
19+
}
1720
18-
export const users: Users = {}
21+
export const state: State = {
22+
isLoadingUsers: false,
23+
users: {}
24+
}
1925
`,
2026
},
2127
{
2228
fileName: 'app/issues/state.ts',
2329
code: `
30+
export type Issue = {
31+
id: string
32+
username: string
33+
title: string
34+
description: string
35+
}
36+
37+
export type Issues = {
38+
[id: string]: Issue
39+
}
40+
2441
export enum SortKey = {
2542
Date = 'date',
2643
Title = 'title'
@@ -36,13 +53,18 @@ export type Sorting {
3653
type: SortDirection
3754
}
3855
39-
export let isLoading = false
40-
41-
export const issues = {}
56+
export type State = {
57+
isLoading: boolean
58+
issues: Issues
59+
}
4260
43-
export const sorting: Sorting = {
44-
key: SortKey.Date,
45-
direction: SortDirection.Asc
61+
export const state: State = {
62+
isLoading: false,
63+
issues: {},
64+
sorting: {
65+
key: SortKey.Date,
66+
direction: SortDirection.Asc
67+
}
4668
}
4769
`,
4870
},
@@ -51,21 +73,22 @@ export const sorting: Sorting = {
5173
{
5274
fileName: 'app/admin/state.js',
5375
code: `
54-
export let isLoadingUsers = false
55-
56-
export const users = {}
76+
export default {
77+
isLoadingUsers: false,
78+
users: {}
79+
}
5780
`,
5881
},
5982
{
6083
fileName: 'app/issues/state.js',
6184
code: `
62-
export let isLoading = false
63-
64-
export const issues = {}
65-
66-
export const sorting = {
67-
key: 'date',
68-
type: 'asc'
85+
export default {
86+
isLoading: false,
87+
issues: {},
88+
sorting: {
89+
key: 'date',
90+
type: 'asc'
91+
}
6992
}
7093
`,
7194
},

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const loadPosts: Action = async ({ state, jsonPlaceholder }) => {
2020
code: tsAppIndex(
2121
view,
2222
`
23-
import * as state from './state'
23+
import { state } from './state'
2424
import * as actions from './actions'
2525
2626
const config = {

packages/overmind-website/examples/guide/getstarted/createapp.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@ export type Post = {
1111
body: string
1212
}
1313
14-
export let isLoadingPosts: boolean = false
14+
export type State = {
15+
isLoadingPosts: boolean
16+
posts: Post[]
17+
}
1518
16-
export let posts: Post[] = []
19+
export const state: State = {
20+
isLoadingPosts: false,
21+
posts: []
22+
}
1723
`,
1824
},
1925
{
2026
fileName: 'app/index.ts',
2127
code: tsAppIndex(
2228
view,
2329
`
24-
import * as state from './state'
30+
import { state } from './state'
2531
2632
const config = {
2733
state,

packages/overmind-website/examples/guide/getstarted/effects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const jsonPlaceholder = {
2121
code: tsAppIndex(
2222
view,
2323
`
24-
import * as state from './state'
24+
import state from './state'
2525
import * as actions from './actions'
2626
import * as effects from './effects'
2727

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default (ts, view) =>
77
import { Overmind, TApp } from 'overmind'
88
import { createConnect, TConnect } from 'overmind-${view}'
99
import * as page from 'page'
10-
import * as state from './state'
10+
import { state } from './state'
1111
import * as actions from './actions'
1212
import * as effects from './effects'
1313
@@ -44,7 +44,7 @@ export connect = createConnect(app)
4444
import { Overmind } from 'overmind'
4545
import { createConnect } from 'overmind-${view}'
4646
import page from 'page'
47-
import * as state from './state'
47+
import state from './state'
4848
import * as actions from './actions'
4949
import * as effects from './effects'
5050

packages/overmind-website/examples/guide/runningsideeffects/axios.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export { default as http } from 'axios'
1414
code: tsAppIndex(
1515
view,
1616
`
17-
import * as state from './state'
17+
import { state } from './state'
1818
import * as actions from './actions'
1919
import * as effects from './effects'
2020
@@ -39,7 +39,7 @@ export { default as http } from 'axios'
3939
code: `
4040
import { Overmind } from 'overmind'
4141
import { createConnect } from 'overmind-${view}'
42-
import * as state from './state'
42+
import state from './state'
4343
import * as actions from './actions'
4444
import * as effects from './effects'
4545

0 commit comments

Comments
 (0)