Skip to content

Commit 005e2cf

Browse files
docs(website): more api docs
1 parent 84693f9 commit 005e2cf

File tree

11 files changed

+244
-24
lines changed

11 files changed

+244
-24
lines changed
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
# Compute
1+
# Compute
2+
3+
```marksy
4+
<Example name="api_compute" view/>
5+
```
6+
7+
You can add computed state values. These state values are functions that takes one argument, `filterNameBy` in the example above. This argument can be whatever you want, but it can only be a single argument. That means if you want to pass in multiple values you would pass those as part of an object. The reason computed state values work like this is because this argument is the cache key. As long as you pass in the same argument and the accessed state is not changed, the cached value is instantly returned.
8+
9+
By default a computed state value allows 10 values to be cached. This can be adjusted with the limit option. When a new value is cached, the last cached value is popped off.
10+
11+
Note that the argument you pass in to calculate the computed state value is stored by reference. That means if you pass in an object as the argument, the cache is only valid when you pass in the exact same object. That means you should only change reference on the object when the object indeed has a change.
12+
13+
You can learn more about computed state values in [the following guide](/guides/computing_like_a_pro).
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
# Connect
1+
# Connect
2+
3+
```marksy
4+
<Example name="api_connect" view/>
5+
```
6+
7+
When you instantiate an Overmind application it exposes the ability to connect components to the state and actions defined. This is simply done by using the **connect** function and pass in the component.
8+
9+
Any state you access in the component is automatically tracked by Overmind and the component will rerender when there is a change.
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
# Derive
1+
# Derive
2+
3+
```marksy
4+
<Example name="api_derive" view />
5+
```
6+
7+
You can add derived state to your application. You access derived state like any other value, there is not need to call it as a function. The derived value is cached and will only update when any accessed state changes.
-100 KB
Binary file not shown.

packages/overmind-website/backend/index.html

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,57 @@
55
<meta charset="UTF-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
77
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8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+
+Hq+8J3K3SJX/FOAO6U/z4+Iad+05EcpfO4uYkjhBpErxgVoF29yUtnTjGk/HYXvPRmmd4icxwRY
48+
K/011nHszXDeaPaKWFJYLXIeE2BNhuP9jb7V5VDEsD/DdA3jAvQkGh9FX4bT2aJPxJRCDyHAUvHq
49+
OoWD9e7wGkkRy8FEs5VY2jYykvoj+t+i3oedeU9LgLIDKJuWAGUHUDYtAcoOoGxaApQdQNm0BCg7
50+
gLJpCVB2AGXT1rF8/VJ8pXol10R2DA70vzBLMWVR6e59ErsSTP7EzQtEHd6xRH8bihObOUERy4ZE
51+
s2M4NboEjiQarxLHVXOFTdLPD48w/htwOMPp5uK4qlSKGDZnmB5mXIBPRBFiCivEWV3ZPCj90PRT
52+
kfOYAMOiAjOVLcVZXSkUvrdkmB5SVI1MvA0eEBWYKbRhW6W7976MIOqi8LlN+knxGZEr/inAt6L8
53+
NJUr8FQzRSh8PSXvhPh9E+qMJ2+E3hNHyKlch13NWA6Fj12Fz1ROihzHaBVItEpkpi6XX4c3cX0d
54+
Dqm9SOpfNLBICs6KyvaaiqRG2YrXNeaBqcwyub9EreOUZXLVGiZexOMNCKJMXsIT0/2xWqXoCVFz
55+
W8/aK5N9opQmu1R2WFRdLxK1t/OJt0Rp//mZLqqlWnxIzIR282cm7BPJ/1Dtwlr7BYZE1fWIaGub
56+
qz0Df+FlMe1n/M+PktIxMixuIxfE7bEjI8DZ5KzoY3pBQm9hTs/QF/hOLImuKtc2iw9EH9O7qYa5
57+
XWPfi9nwq+jcKuv12Em8ItZ7ViNlPX2Df4jNzWdiWVymec1UZ8Qzx3P4UGbPII3pHf6m+PT5n7bO
58+
TianeXo65lXz9HTM6fb5vwEB1kNwNpL0bgAAAABJRU5ErkJggg==" type="image/x-icon" />
859
<title>Overmind</title>
960
<style>
1061
html,

packages/overmind-website/backend/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ app.get('/backend/search', (req, res) => {
9797

9898
res.send(hits.slice(0, 5))
9999
})
100-
app.get('/favicon.ico', (_, res) =>
101-
res.sendFile(path.resolve('backend', 'favicon.ico'))
102-
)
103100
app.get('/*', (_, res) => res.sendFile(path.resolve('dist', 'index.html')))
104101

105102
app.listen(5000, () => console.log('Example app listening on port 5000!'))
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
function createJsCode(view) {
2+
return [
3+
{
4+
code: `
5+
import { compute } from '${view}'
6+
7+
compute(
8+
filterNameBy =>
9+
state =>
10+
state.items.filter(item => item.name === filterNameBy),
11+
{
12+
limit: 10
13+
}
14+
)
15+
`,
16+
},
17+
]
18+
}
19+
20+
function createTsCode(view) {
21+
return [
22+
{
23+
code: `
24+
import { compute } from '${view}'
25+
import { State } from '../app'
26+
27+
compute(
28+
(filterNameBy: string) =>
29+
(state: State) =>
30+
state.items.filter(item => item.name === filterNameBy),
31+
{
32+
limit: 10
33+
}
34+
)
35+
`,
36+
},
37+
]
38+
}
39+
40+
export const react = createJsCode('react-overmind')
41+
42+
export const reactTs = createTsCode('react-overmind')
43+
44+
export const vue = createJsCode('vue-overmind')
45+
46+
export const vueTs = createTsCode('vue-overmind')
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
export const react = [
2+
{
3+
fileName: 'components/SomeComponent.js',
4+
code: `
5+
import React from 'react'
6+
import { connect } from '../app'
7+
8+
const SomeComponent = ({ app }) => {
9+
return (
10+
<div onClick={app.actions.onClick}>
11+
{app.state.foo}
12+
</div>
13+
)
14+
}
15+
16+
export default connect(MyComponent)
17+
`,
18+
},
19+
]
20+
21+
export const reactTs = [
22+
{
23+
fileName: 'MyComponent.tsx',
24+
code: `
25+
import * as React from 'react'
26+
import { connect, Connect } from '../app'
27+
28+
const SomeComponent: React.SFC<Connect, {}> = ({ app }) => {
29+
return (
30+
<div onClick={app.actions.onClick}>
31+
{app.state.foo}
32+
</div>
33+
)
34+
}
35+
36+
export default connect(MyComponent)
37+
`,
38+
},
39+
]
40+
41+
export const vue = [
42+
{
43+
fileName: 'SomeComponent.vue (template)',
44+
code: `
45+
<div v-on:click="app.actions.onClick">
46+
{{app.state.foo}}
47+
</div>
48+
`,
49+
},
50+
{
51+
fileName: 'SomeComponent.vue (script)',
52+
code: `
53+
import { connect } from '../app'
54+
55+
export default connect({})
56+
`,
57+
},
58+
]
59+
60+
export const vueTs = vue
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function createJsCode(view) {
2+
return [
3+
{
4+
code: `
5+
import { derive } from '${view}'
6+
7+
derive(
8+
state => state.items.filter(item => item.completed)
9+
)
10+
`,
11+
},
12+
]
13+
}
14+
15+
function createTsCode(view) {
16+
return [
17+
{
18+
code: `
19+
import { derive } from '${view}'
20+
import { State } from '../app'
21+
22+
derive(
23+
(state: State) => state.items.filter(item => item.completed)
24+
)
25+
`,
26+
},
27+
]
28+
}
29+
30+
export const react = createJsCode('react-overmind')
31+
32+
export const reactTs = createTsCode('react-overmind')
33+
34+
export const vue = createJsCode('vue-overmind')
35+
36+
export const vueTs = createTsCode('vue-overmind')

packages/overmind-website/package.json

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@
1313
"typecheck": "tsc --noEmit",
1414
"prepare": "npm run build",
1515
"posttest": "npm run typecheck"
16-
},
17-
"now": {
18-
"files": [
19-
"api",
20-
"backend",
21-
"examples",
22-
"guides",
23-
"src",
24-
"package.json",
25-
"tsconfig.json",
26-
"videos.json",
27-
"webpack.config.js"
28-
]
29-
},
16+
},
17+
"now": {
18+
"files": [
19+
"api",
20+
"backend",
21+
"examples",
22+
"guides",
23+
"src",
24+
"package.json",
25+
"tsconfig.json",
26+
"videos.json",
27+
"webpack.config.js"
28+
]
29+
},
3030
"keywords": [
3131
"overmind",
3232
"demo"
3333
],
3434
"dependencies": {
3535
"@types/node": "^10.5.1",
36-
"express": "^4.16.3",
37-
"overmind-themes": "next",
36+
"express": "^4.16.3",
3837
"install": "^0.12.1",
3938
"marksy": "^6.0.3",
4039
"npm": "^6.3.0",
40+
"overmind-themes": "next",
4141
"page": "^1.8.6",
4242
"prismjs": "^1.15.0",
4343
"react": "^16.4.1",
@@ -56,7 +56,7 @@
5656
"url-loader": "^1.0.1",
5757
"webpack": "^4.15.1",
5858
"webpack-cli": "^3.0.8",
59-
"webpack-dev-server": "^3.1.5",
60-
"html-webpack-plugin": "^3.2.0"
59+
"webpack-dev-server": "^3.1.5",
60+
"html-webpack-plugin": "^3.2.0"
6161
}
6262
}

0 commit comments

Comments
 (0)