Skip to content

Commit 7338263

Browse files
christianalfonigitbook-bot
authored andcommitted
GitBook: [v28] 45 pages modified
1 parent 5eaffb3 commit 7338263

25 files changed

+508
-718
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export const fetchItems = async () {
5050

5151
{% tab title="actions.js" %}
5252
```typescript
53-
export const loadApp = ({ state, effects }) => {
53+
export const loadApp = async ({ state, effects }) => {
5454
state.items = await effects.api.fetchItems()
5555
}
5656
```
@@ -80,11 +80,11 @@ export const search = pipe(
8080
({ state }, query) => {
8181
state.query = query
8282
},
83-
filter((_, query) => query.length > 2),
83+
filter(({ state }) => state.query.length > 2),
8484
debounce(200),
85-
async ({ state, effects }, query) => {
85+
async ({ state, effects }) => {
8686
state.isSearching = true
87-
state.searchResult = await effects.getSearchResult(query)
87+
state.searchResult = await effects.getSearchResult(state.query)
8888
state.isSearching = false
8989
}
9090
)

SUMMARY.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
## Guides <a id="guides-1"></a>
3434

3535
* [Using state machines](guides-1/using-state-machines.md)
36+
* [Using classes](guides-1/using-classes.md)
3637
* [Connecting components](guides-1/connecting-components.md)
3738
* [Managing lists](guides-1/managing-lists.md)
3839
* [State first routing](guides-1/state-first-routing.md)
39-
* [Move to Typescript](guides-1/move-to-typescript.md)
4040
* [Testing](guides-1/testing.md)
4141
* [Connecting to React Native](https://dev.to/brasilikum/how-to-setup-overmind-with-react-native-expo-optional-4mk5)
4242

@@ -55,7 +55,7 @@
5555
* [lazy](api-1/lazy.md)
5656
* [merge](api-1/merge.md)
5757
* [namespaced](api-1/namespaced.md)
58-
* [onInitialize](api-1/oninitialize.md)
58+
* [onInitializeOvermind](api-1/oninitialize.md)
5959
* [operators](api-1/operators.md)
6060
* [reaction](api-1/reaction.md)
6161
* [rehydrate](api-1/rehydrate.md)

api-1/action.md

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# action
22

33
```typescript
4-
import { AsyncAction } from 'overmind'
5-
6-
export const getPosts: AsyncAction = async ({ state, actions, effects }) => {
4+
export const getPosts = async ({ state, actions, effects }) => {
75
state.isLoadingPosts = true
86
state.posts = await effects.api.getPosts()
97
state.isLoadingPosts = false
@@ -16,16 +14,14 @@ An action is where you write the logic of the application. Every action receives
1614

1715
This _injected_ context allows Overmind to understand from where you are changing state and running effects. You can also use other actions defined in your application. Additionally with _injection_ your actions become highly testable as it can easily be mocked.
1816

19-
State changes are restricted to these actions. That means if you try to change the state outside of an action you will get an error. The state changes are also scoped to the action. That means it does not matter if you perform the state change asynchronously, either by defining the action as an **async** function or for example use a **setTimeout**. You can change the state at any time within the action.
17+
State changes are restricted to these actions. That means if you try to change the state outside of an action you will get an error. The state changes are also scoped to the action. That means it does not matter if you perform the state change asynchronously, either by defining the action as an **async** function or for example use a **setTimeout**, returning a promise which is resolved when it times out.
2018

2119
## Payload
2220

2321
When an action is called you can optionally pass it a payload. This payload is received as the second argument to the action.
2422

2523
```typescript
26-
import { Action } from 'overmind'
27-
28-
export const setTitle: Action<string> = ({ state }, title) => {
24+
export const setTitle = ({ state }, title) => {
2925
state.title = title
3026
}
3127
```
@@ -34,13 +30,3 @@ export const setTitle: Action<string> = ({ state }, title) => {
3430
There is only one argument, which means if you want to pass multiple values you have to do so with an object
3531
{% endhint %}
3632

37-
## Typing
38-
39-
There are two different action types in Overmind, **Action** and **AsyncAction**. Both of them takes an Input param and an Output param where both of them default to **void**.
40-
41-
`Action<void, void>`
42-
43-
`AsyncAction<void, void>`.
44-
45-
The difference is that **AsyncAction** returns a Promise of the output, **Promise&lt;void&gt;**. Basically whenever you use an **async** action or explicitly return a promise from an action you should use the **AsyncAction** type.
46-

api-1/addflushlistener.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@
33
The **addMutationListener** triggers whenever there is a mutation. The **addFlushListener** triggers whenever Overmind tells components to render again. It can have multiple mutations related to it.
44

55
{% tabs %}
6-
{% tab title="overmind/onInitialize.ts" %}
6+
{% tab title="overmind/actions.js" %}
77
```typescript
8-
import { OnInitialize } from 'overmind'
9-
10-
const onInitialize: OnInitialize = async ({ state, effects }, overmind) => {
8+
export const onInitializeOvermind = async ({ state, effects }, overmind) => {
119
overmind.addFlushListener(effects.history.addMutations)
1210
}
13-
14-
export default onInitialize
1511
```
1612
{% endtab %}
1713
{% endtabs %}

api-1/addmutationlistener.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33
It is possible to listen to all mutations performed in Overmind. This allows you to create special effects based on mutations within a certain domain of your app, or whatever else you come up with. Note that this method triggers right after any mutation occurs, you might rather want to use **addFlushListener** to be notified about batched changes, like the components does.
44

55
{% tabs %}
6-
{% tab title="overmind/onInitialize.ts" %}
6+
{% tab title="overmind/actions.js" %}
77
```typescript
8-
import { OnInitialize } from 'overmind'
9-
10-
const onInitialize: OnInitialize = async ({ state, localStorage }, overmind) => {
8+
export const onInitializeOvermind = async ({ state, localStorage }, overmind) => {
119
overmind.addMutationListener((mutation) => {
1210
if (mutation.path.indexOf('todos') === 0) {
1311
localStorage.set('todos', state.todos)
1412
}
1513
})
1614
}
17-
18-
export default onInitialize
1915
```
2016
{% endtab %}
2117
{% endtabs %}

api-1/createovermind.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ The **createOvermind** factory is used to create the application instance. You n
55
{% tabs %}
66
{% tab title="overmind/index.ts" %}
77
```typescript
8-
import { IConfig } from 'overmind'
98
import { state } from './state'
109
import * as effects from './effects'
1110
import * as actions from './actions'
@@ -15,11 +14,6 @@ export const config = {
1514
effects,
1615
actions
1716
}
18-
19-
// For explicit typing check the Typescript guide
20-
declare module 'overmind' {
21-
interface Config extends IConfig<typeof config> {}
22-
}
2317
```
2418
{% endtab %}
2519
{% endtabs %}

api-1/derive.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
You can add derived state to your application. You access derived state like any other value, there is no need to call it as a function. The derived value is cached and will only update when any accessed state changes.
44

55
{% tabs %}
6-
{% tab title="overmind/state.ts" %}
6+
{% tab title="overmind/state.js" %}
77
```typescript
88
import { derived } from 'overmind'
99

10-
export const state: State = {
10+
export const state = {
1111
items: [],
1212
completedItems: derived((state, rootState) => {
1313
return state.items.filter(item => item.completed)

api-1/effects.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
# effects
22

33
{% tabs %}
4-
{% tab title="overmind/effects.ts" %}
4+
{% tab title="overmind/effects.js" %}
55
```typescript
6-
import { User, Item } from './state'
7-
86
export const api = {
9-
async getUser(): Promise<User> {
7+
async getUser() {
108
const response = await fetch('/user')
119

1210
return response.json()
1311
},
14-
async getItem(id: number): Promise<Item> {
12+
async getItem(id) {
1513
const response = await fetch(`/items/${id}`)
1614

1715
return response.json()

api-1/merge.md

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@
33
Allows you to merge configurations together.
44

55
{% tabs %}
6-
{% tab title="overmind/index.ts" %}
6+
{% tab title="overmind/index.js" %}
77
```typescript
8-
import {IConfig } from 'overmind'
98
import { merge } from 'overmind/config'
109
import * as moduleA from './moduleA'
1110
import * as moduleB from './moduleB'
1211

1312
export const config = merge(moduleA, moduleB)
14-
15-
declare module 'overmind' {
16-
interface Config extends IConfig<typeof config> {}
17-
}
1813
```
1914
{% endtab %}
2015
{% endtabs %}
@@ -24,11 +19,9 @@ Note that merge can be useful to combine a root configuration with **namespaced*
2419
{% tabs %}
2520
{% tab title="overmind/index.ts" %}
2621
```typescript
27-
import {IConfig } from 'overmind'
2822
import { merge, namespaced, lazy } from 'overmind/config'
2923
import { state } from './state'
3024
import * as moduleA from './moduleA'
31-
import { Config as ModuleB } from './moduleB'
3225

3326
export const config = merge(
3427
{
@@ -38,13 +31,9 @@ export const config = merge(
3831
moduleA
3932
}),
4033
lazy({
41-
moduleB: async (): Promise<ModuleB> => await import('./moduleB').config
34+
moduleB: async () => await import('./moduleB').config
4235
})
4336
)
44-
45-
declare module 'overmind' {
46-
interface Config extends IConfig<typeof config> {}
47-
}
4837
```
4938
{% endtab %}
5039
{% endtabs %}

api-1/namespaced.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ So in Overmind isolation is a discipline, not a technical restriction.
99
{% tabs %}
1010
{% tab title="overmind/index.ts" %}
1111
```typescript
12-
import {IConfig } from 'overmind'
1312
import { namespaced } from 'overmind/config'
1413
import * as moduleA from './moduleA'
1514
import * as moduleB from './moduleB'
@@ -18,10 +17,6 @@ export const config = namespaced({
1817
moduleA,
1918
moduleB
2019
})
21-
22-
declare module 'overmind' {
23-
interface Config extends IConfig<typeof config> {}
24-
}
2520
```
2621
{% endtab %}
2722
{% endtabs %}

0 commit comments

Comments
 (0)