Skip to content

Commit 0bca557

Browse files
docs(website): update website to latest changes
1 parent a93c11d commit 0bca557

File tree

17 files changed

+221
-89
lines changed

17 files changed

+221
-89
lines changed

packages/overmind-website/api/action.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The action is built up by **operators**, methods called on the action itself. Th
1212

1313
## attempt
1414
```marksy
15-
h(Example, { name: "api/action_try" })
15+
h(Example, { name: "api/action_attempt" })
1616
```
1717

1818
Typically used to explicitly handle potentially thrown errors from an effect.
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
# OnInitialize
22

3-
If you need to run logic as the application initializes you can use the **onInitialize** hook. This is defined as an action.
3+
If you need to run logic as the application initializes you can use the **onInitialize** hook. This is defined as a callback and it receives the instance of the application. You can do whatever you want here. Run an action, configure a router etc.
44

55
```marksy
66
h(Example, { name: "api/onInitialize" })
77
```
88

9-
Overmind will first run any module defined onInitialize in parallel. After that the main onInitialize runs. You can see this in the devtools as well. The reason it works this way is because you module defined onInitialize indicates that you want to prepare something related to that module specifically, you do not care about the rest. The root onInitialize covers all the modules and allows you to orchestrate logic when those are indeed ready.
9+
Overmind will run this logic as a promise, meaning that you can return an action you want to run and can later outside of the application detect when the initialization is done. This promise is named **initialized** and can be used as such:
10+
11+
When you use **modules** all the *onInitialize* will run in parallel.

packages/overmind-website/examples/api/action_try.ts renamed to packages/overmind-website/examples/api/action_attempt.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export default (ts) =>
66
code: `
77
import { Operation } from 'overmind'
88
9-
export const getItems: Operation.Attempt<Promise<Items>> = ({ http }) =>
10-
http.get('/items')
9+
export const getItems: Operation.Attempt<Promise<Items>> = ({ effects }) =>
10+
effects.http.get('/items')
1111
`,
1212
},
1313
{
@@ -32,8 +32,8 @@ export const doThis: Action = action =>
3232
{
3333
fileName: 'app/operations.js',
3434
code: `
35-
export const getItems = ({ http }) =>
36-
http.get('/items')
35+
export const getItems = ({ effects }) =>
36+
effects.http.get('/items')
3737
`,
3838
},
3939
{

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ export default (ts) =>
66
code: `
77
import { Operation } from 'overmind'
88
9-
export const isOnline: Operation.Filter = ({ connection }) =>
10-
connection.isOnline()
9+
export const isOnline: Operation.Filter = ({ effects }) =>
10+
effects.connection.isOnline()
1111
12-
export const isGreatherThan2: Operation.Filter<string> = (_, value) =>
12+
export const isGreatherThan2: Operation.Filter<string> = ({ value }) =>
1313
value.length > 2
1414
`,
1515
},
@@ -29,10 +29,10 @@ export const doThis: Action<string> = action =>
2929
{
3030
fileName: 'app/operations.js',
3131
code: `
32-
export const isOnline = ({ connection }) =>
33-
connection.isOnline()
32+
export const isOnline = ({ effects }) =>
33+
effects.connection.isOnline()
3434
35-
export const isGreaterThan2 = (_, value) =>
35+
export const isGreaterThan2 = ({ value }) =>
3636
value.length > 2
3737
`,
3838
},

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ export default (ts) =>
77
import { Operation } from 'overmind'
88
99
export const getUser: Operation.Map<string, Promise<User>> =
10-
({ http }, id) => http.get(\`/users/\${id}\`)
10+
({ effects, value: id }) => effects.http.get(\`/users/\${id}\`)
1111
1212
export const trim: Operation.Map<string, string> =
13-
(_, value) => value.trim()
13+
({ value }) => value.trim()
1414
`,
1515
},
1616
{
@@ -29,7 +29,7 @@ export const doThis: Action<string> = action =>
2929
{
3030
fileName: 'app/operations.js',
3131
code: `
32-
export const getUser = ({ http }, id) =>
32+
export const getUser = ({ effects, value: id }) =>
3333
http.get(\`/users/\${id}\`)
3434
3535
export const trim = (_, value) =>

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ export default (ts) =>
66
code: `
77
import { Mutate } from 'overmind'
88
9-
export const setLoading: Mutate = state =>
9+
export const setLoading: Mutate = ({ state }) =>
1010
state.isLoading = true
1111
12-
export const setInputValue: Mutate<string> = (state, value) =>
12+
export const setInputValue: Mutate<string> = ({ state, value }) =>
1313
state.inputValue = value
1414
`,
1515
},
@@ -29,10 +29,10 @@ export const doThis: Action<string> = action =>
2929
{
3030
fileName: 'app/mutations.js',
3131
code: `
32-
export const setLoading = state =>
32+
export const setLoading = ({ state }) =>
3333
state.isLoading = true
3434
35-
export const setInputValue = (state, value) =>
35+
export const setInputValue = ({ state, value }) =>
3636
state.inputValue = value
3737
`,
3838
},

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export default (ts) =>
66
code: `
77
import { Operation } from 'overmind'
88
9-
export const trackSubmitForm: Operation.Run = ({ state, track }) =>
10-
track.interaction('login', Boolean(state.user))
9+
export const trackSubmitForm: Operation.Run = ({ state, effects }) =>
10+
effects.track.interaction('login', Boolean(state.user))
1111
`,
1212
},
1313
{
@@ -35,8 +35,8 @@ export const login: Action = (action) =>
3535
{
3636
fileName: 'app/operations.js',
3737
code: `
38-
export const trackSubmitForm = ({ track }) =>
39-
track.interaction('submitForm')
38+
export const trackSubmitForm = ({ effects }) =>
39+
effects.track.interaction('submitForm')
4040
`,
4141
},
4242
{

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export default (ts) =>
66
code: `
77
import { Operation } from 'overmind'
88
9-
export const hasToken: Operation.When = ({ localStorage }) =>
10-
Boolean(localStorage.get('token'))
9+
export const hasToken: Operation.When = ({ effects }) =>
10+
Boolean(effects.localStorage.get('token'))
1111
`,
1212
},
1313
{
@@ -32,8 +32,8 @@ export const doThis: Action = action =>
3232
{
3333
fileName: 'app/operations.js',
3434
code: `
35-
export const hasToken = ({ localStorage }) =>
36-
Boolean(localStorage.get('token'))
35+
export const hasToken = ({ effects }) =>
36+
Boolean(effects.localStorage.get('token'))
3737
`,
3838
},
3939
{

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@ import { tsAppIndex } from '../templates'
33
export default (ts, view) =>
44
ts
55
? [
6+
{
7+
fileName: 'app/onInitialize.ts',
8+
code: `
9+
import { OnInitialize } from 'overmind'
10+
11+
const onInitialize: OnInitialize = (app) => app.actions.loadData()
12+
13+
export default onInitialize
14+
`,
15+
},
616
{
717
fileName: 'app/index.ts',
818
code: tsAppIndex(
919
view,
1020
`
21+
import onInitialize from './onInitialize'
1122
import * as state from './state'
1223
import * as actions from './actions'
1324
14-
const onInitialize: Action = actions.initialize
15-
1625
const config = {
1726
onInitialize,
1827
state,
@@ -23,15 +32,20 @@ const config = {
2332
},
2433
]
2534
: [
35+
{
36+
fileName: 'app/onInitialize.ts',
37+
code: `
38+
export default = (app) => app.actions.loadData()
39+
`,
40+
},
2641
{
2742
fileName: 'app/index.js',
2843
code: `
2944
import App from 'overmind-${view}'
45+
import onInitialize from './onInitialize'
3046
import * as state from './state'
3147
import * as actions from './actions'
3248
33-
const onInitialize = actions.initialize
34-
3549
const app = new App({
3650
onInitialize,
3751
state,

packages/overmind-website/examples/guide/creatingactions/mutations.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ export default (ts) =>
66
code: `
77
import { Mutate } from 'overmind'
88
9-
export const setValue: Mutate = state =>
9+
export const setValue: Mutate = ({ state }) =>
1010
state.value = 'foo'
1111
12-
export const setValueFromAction: Mutate<string> = (state, value) =>
12+
export const setValueFromAction: Mutate<string> = ({ state, value }) =>
1313
state.value2 = value
1414
15-
export const setValueFromState: Mutate = state =>
15+
export const setValueFromState: Mutate = ({ state }) =>
1616
state.value3 = state.value
1717
`,
1818
},
@@ -34,13 +34,13 @@ export const setValues: Action<string> = action =>
3434
{
3535
fileName: 'app/mutations.js',
3636
code: `
37-
export const setValue = state =>
37+
export const setValue = ({ state }) =>
3838
state.value = 'foo'
3939
40-
export const setValueFromAction = (state, value) =>
40+
export const setValueFromAction = ({ state, value }) =>
4141
state.value2 = value
4242
43-
export const setValueFromState = state =>
43+
export const setValueFromState = ({ state }) =>
4444
state.value3 = state.value
4545
`,
4646
},

0 commit comments

Comments
 (0)