Skip to content

Commit 77853b6

Browse files
docs(website): improve frontpage code and text
1 parent c8628c8 commit 77853b6

File tree

5 files changed

+101
-19
lines changed

5 files changed

+101
-19
lines changed

now.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

packages/overmind-website/examples/frontpage/actions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
export default () => [
22
{
33
code: `
4-
export const getItems = async ({ state, request }) => {
4+
export const getItems = async ({ state, effects }) => {
55
state.isLoadingItems = true
6-
state.items = await request("/items")
6+
state.items = await effects.api.getItems()
77
state.isLoadingItems = false
88
}
99
`,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export default () => [
2+
{
3+
code: `
4+
import axios from 'axios'
5+
6+
export const api = {
7+
getItems() {
8+
return axios.get('/api/items')
9+
}
10+
}
11+
`,
12+
},
13+
]
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export default () => [
2+
{
3+
code: `
4+
import { createMock } from 'overmind'
5+
import { config } from './'
6+
7+
test('should get items', async () => {
8+
const mock = createMock(config, {
9+
api: {
10+
getItems: () => Promise.resolve([{ id: 0, title: "foo" }])
11+
}
12+
})
13+
14+
const mutations = await actions.getItems()
15+
16+
expect(mutations).toMatchSnapshot()
17+
})
18+
`,
19+
},
20+
]

packages/overmind-website/src/components/FrontPage/index.tsx

Lines changed: 66 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ const FrontPage: SFC = () => {
6363
<h2>A SINGLE STATE TREE</h2>
6464
<p>
6565
Building your application as a single state tree is the most
66-
straight forward mental model. No matter how you choose to
67-
structure it, you will always have access to the state wherever
68-
you need it
66+
straight forward mental model. You get a complete overview, but
67+
can still organize the state by namespacing it into domains
6968
</p>
7069
</div>
7170
<div>
@@ -89,18 +88,18 @@ h(Example, { name: "frontpage/statetree" })
8988
{
9089
compile(`
9190
\`\`\`marksy
92-
h(Example, { name: "frontpage/actions" })
91+
h(Example, { name: "frontpage/effects" })
9392
\`\`\`
9493
`).tree
9594
}
9695
</div>,
9796
<div key="1">
98-
<h2>SAFE AND PREDICTABLE CHANGES</h2>
97+
<h2>SEPARATION OF LOGIC</h2>
9998
<p>
100-
When you build applications that performs many state changes
101-
things can get out of hand. In Overmind you can only perform
102-
state changes from <strong>actions</strong> and all changes are
103-
tracked by the development tool
99+
Separate 3rd party apis and logic not specific to your
100+
application by using <strong>effects</strong>. This will keep
101+
your application logic pure and without low level APIs
102+
cluttering your code
104103
</p>
105104
</div>,
106105
][viewport.isMobile ? 'reverse' : 'slice']()}
@@ -112,19 +111,72 @@ h(Example, { name: "frontpage/actions" })
112111
)}
113112
>
114113
<div>
115-
<h2>FUNCTIONAL ACTIONS</h2>
114+
<h2>SAFE AND PREDICTABLE CHANGES</h2>
116115
<p>
117-
When pieces of logic becomes complex it is beneficial to write
118-
functional code. Overmind provides and API named{' '}
119-
<strong>operators</strong> which gives you functional power as
120-
simple actions
116+
When you build applications that performs many state changes
117+
things can get out of hand. In Overmind you can only perform state
118+
changes from <strong>actions</strong> and all changes are tracked
119+
by the development tool
121120
</p>
122121
</div>
123122
<div>
124123
{
125124
compile(`
126125
\`\`\`marksy
126+
h(Example, { name: "frontpage/actions" })
127+
\`\`\`
128+
`).tree
129+
}
130+
</div>
131+
</div>
132+
<div
133+
className={css(
134+
styles.valueProposition,
135+
viewport.isMobile && styles.valuePropositionMobile
136+
)}
137+
>
138+
{[
139+
<div key="0">
140+
{
141+
compile(`
142+
\`\`\`marksy
127143
h(Example, { name: "frontpage/operators" })
144+
\`\`\`
145+
`).tree
146+
}
147+
</div>,
148+
<div key="1">
149+
<h2>FUNCTIONAL ACTIONS</h2>
150+
<p>
151+
When pieces of logic becomes complex it is beneficial to write
152+
functional code. Overmind provides and API named{' '}
153+
<strong>operators</strong> which gives you functional power as
154+
simple actions
155+
</p>
156+
</div>,
157+
][viewport.isMobile ? 'reverse' : 'slice']()}
158+
}
159+
</div>
160+
<div
161+
className={css(
162+
styles.valueProposition,
163+
viewport.isMobile && styles.valuePropositionMobile
164+
)}
165+
>
166+
<div>
167+
<h2>SNAPSHOT TESTING OF LOGIC</h2>
168+
<p>
169+
Bring in your application configuration of state, effects and
170+
actions. Create mocks for any effects. Take a snapshot of
171+
mutations performed in an action to ensure all intermediate states
172+
are met
173+
</p>
174+
</div>
175+
<div>
176+
{
177+
compile(`
178+
\`\`\`marksy
179+
h(Example, { name: "frontpage/test" })
128180
\`\`\`
129181
`).tree
130182
}

0 commit comments

Comments
 (0)