Skip to content

Commit 32f57e4

Browse files
docs(website): replace introduction
1 parent 3e188ed commit 32f57e4

File tree

11 files changed

+439
-327
lines changed

11 files changed

+439
-327
lines changed

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

Lines changed: 0 additions & 69 deletions
This file was deleted.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
import { tsAppIndex } from '../../templates'
2+
3+
const javascript = {
4+
react: [
5+
{
6+
fileName: 'overmind/index.js',
7+
code: `
8+
import { createOvermind } from 'overmind'
9+
import { createHook } from 'overmind-react'
10+
11+
export const overmind = createOvermind({
12+
state: {
13+
count: 0
14+
},
15+
actions: {
16+
changeCount({ state }, countChange) {
17+
state.count += countChange
18+
}
19+
}
20+
})
21+
22+
export const useOvermind = createHook(overmind)
23+
`,
24+
},
25+
],
26+
vue: [
27+
{
28+
fileName: 'overmind/index.js',
29+
code: `
30+
import { createOvermind } from 'overmind'
31+
import { createPlugin } from 'overmind-vue'
32+
33+
export const overmind = createOvermind({
34+
state: {
35+
count: 0
36+
},
37+
actions: {
38+
changeCount({ state }, countChange) {
39+
state.count += countChange
40+
}
41+
}
42+
})
43+
44+
export const OvermindPlugin = createPlugin(overmind)
45+
`,
46+
},
47+
],
48+
}
49+
50+
const typescript = {
51+
react: [
52+
{
53+
fileName: 'overmind/actions.ts',
54+
code: `
55+
import { Action } from 'overmind'
56+
57+
export const changeCount: Action<number> = ({ state }, countChange) {
58+
state.count += countChange
59+
}
60+
`,
61+
},
62+
{
63+
fileName: 'overmind/index.ts',
64+
code: tsAppIndex(
65+
'react',
66+
`
67+
import { state } from './state'
68+
import * as actions from './actions'
69+
70+
const config = {
71+
state,
72+
actions
73+
}
74+
`
75+
),
76+
},
77+
],
78+
vue: javascript.vue,
79+
angular: [
80+
{
81+
fileName: 'overmind/actions.ts',
82+
code: `
83+
import { Action } from 'overmind'
84+
85+
export const changeCount: Action<number> = ({ state }, countChange) {
86+
state.count += countChange
87+
}
88+
`,
89+
},
90+
{
91+
fileName: 'overmind/index.ts',
92+
code: tsAppIndex(
93+
'angular',
94+
`
95+
import { state } from './state'
96+
import * as actions from './actions'
97+
98+
const config = {
99+
state,
100+
actions
101+
}
102+
`
103+
),
104+
},
105+
],
106+
}
107+
108+
export default (ts, view) => (ts ? typescript[view] : javascript[view])

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

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
const javascript = {
22
react: [
33
{
4-
fileName: 'Posts.js',
4+
fileName: 'Count.js',
55
target: 'jsx',
66
code: `
77
import React from 'react'
88
import { useOvermind } from '../overmind'
99
10-
const Posts = () => {
10+
const Count = () => {
1111
const { state } = useOvermind()
1212
13-
if (state.isLoadingPosts) {
14-
return <h4>Loading posts...</h4>
15-
}
16-
17-
return <div />
13+
return (
14+
<div>
15+
{state.count}
16+
</div>
17+
)
1818
}
1919
20-
export default Posts
20+
export default Count
2121
`,
2222
},
2323
],
@@ -27,13 +27,13 @@ export default Posts
2727
code: `
2828
import Vue from 'vue'
2929
import { OvermindPlugin } from './overmind'
30-
import Posts from './components/Posts'
30+
import Count from './components/Count'
3131
3232
Vue.use(OvermindPlugin)
3333
3434
new Vue({
3535
el: '#app',
36-
render: (h) => h(App),
36+
render: (h) => h(Count),
3737
})
3838
3939
`,
@@ -44,45 +44,46 @@ new Vue({
4444
const typescript = {
4545
react: [
4646
{
47-
fileName: 'components/Posts.tsx',
47+
fileName: 'components/Count.tsx',
4848
code: `
4949
import * as React from 'react'
5050
import { useOvermind } from '../overmind'
5151
52-
const Posts: React.FunctionComponent = () => {
52+
const Count: React.FunctionComponent = () => {
5353
const { state } = useOvermind()
5454
55-
if (state.isLoadingPosts) {
56-
return <h4>Loading posts...</h4>
57-
}
58-
59-
return <div />
55+
return (
56+
<div>
57+
{state.count}
58+
</div>
59+
)
6060
}
6161
6262
63-
export default Posts
63+
export default Count
6464
`,
6565
},
6666
],
6767
vue: javascript.vue,
6868
angular: [
6969
{
70-
fileName: 'posts.component.ts',
70+
fileName: 'count.component.ts',
7171
code: `
7272
import { Component } from '@angular/core';
73-
import { connect } from '../overmind'
73+
import { Store } from '../overmind'
7474
7575
@Component({
76-
selector: 'posts-list',
76+
selector: 'count-component',
7777
template: \`
78-
<h4 *ngIf="overmind.state.isLoadingPosts">
79-
Loading posts...
80-
</h4>
81-
<div *ngIf="!overmind.state.isLoadingPosts"></div>
78+
<div *track>
79+
{{ state.count }}
80+
</div>
8281
\`
8382
})
84-
@connect()
85-
export class PostsList {}
83+
export class CountComponent {
84+
state = this.store.select()
85+
constructor (private store: Store) {}
86+
}
8687
`,
8788
},
8889
],
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
const javascript = {
2+
react: [
3+
{
4+
fileName: 'Count.js',
5+
target: 'jsx',
6+
code: `
7+
import React from 'react'
8+
9+
const Count = () => {
10+
return (
11+
<div>
12+
{state.count}
13+
</div>
14+
)
15+
}
16+
17+
export default Count
18+
`,
19+
},
20+
],
21+
vue: [
22+
{
23+
fileName: 'Count.vue (template)',
24+
target: 'markup',
25+
code: `
26+
<div>
27+
{{ state.count }}
28+
</div>
29+
`,
30+
},
31+
],
32+
}
33+
34+
const typescript = {
35+
react: [
36+
{
37+
fileName: 'components/Count.tsx',
38+
code: `
39+
import * as React from 'react'
40+
41+
const Count: React.FunctionComponent = () => {
42+
return (
43+
<div>
44+
{state.count}
45+
</div>
46+
)
47+
}
48+
49+
export default Posts
50+
`,
51+
},
52+
],
53+
vue: javascript.vue,
54+
angular: [
55+
{
56+
fileName: 'count.component.ts',
57+
code: `
58+
import { Component } from '@angular/core';
59+
60+
@Component({
61+
selector: 'count-component',
62+
template: \`
63+
<div>
64+
{{ state.count }}
65+
</div>
66+
\`
67+
})
68+
export class CountComponent {}
69+
`,
70+
},
71+
],
72+
}
73+
74+
export default (ts, view) => (ts ? typescript[view] : javascript[view])

0 commit comments

Comments
 (0)