Skip to content

Commit 7314793

Browse files
christianalfonigitbook-bot
authored andcommitted
GitBook: [master] 16 pages modified
1 parent 6efa20f commit 7314793

16 files changed

+2434
-275
lines changed

README.md

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ Building your application with a single state tree is the most straight forward
3333
Separate 3rd party APIs and logic not specific to your application by using **effects**. This will keep your application logic pure and without low level APIs cluttering your code.
3434

3535
{% tabs %}
36-
{% tab title="api.js" %}
37-
```javascript
38-
export const fetchItems = async () {
36+
{% tab title="api.ts" %}
37+
```typescript
38+
export const fetchItems = async (): Promise<Item[]> {
3939
const response = await fetch('/api/items')
4040

4141
return response.json()
@@ -44,9 +44,9 @@ export const fetchItems = async () {
4444
```
4545
{% endtab %}
4646

47-
{% tab title="actions.js" %}
47+
{% tab title="actions.ts" %}
4848
```typescript
49-
export const loadApp = ({ state, effects }) => {
49+
export const loadApp: AsyncAction = ({ state, effects }) => {
5050
state.items = await effects.api.fetchItems()
5151
}
5252
```
@@ -57,8 +57,8 @@ export const loadApp = ({ state, effects }) => {
5757

5858
When you build applications that perform many state changes things can get out of hand. In Overmind you can only perform state changes from **actions** and all changes are tracked by the development tool.
5959

60-
```javascript
61-
export const getItems = async ({ state, effects }) => {
60+
```typescript
61+
export const getItems: AsyncAction = async ({ state, effects }) => {
6262
state.isLoadingItems = true
6363
state.items = await effects.api.fetchItems()
6464
state.isLoadingItems = false
@@ -71,8 +71,8 @@ Even though Overmind can create applications with only plain **state** and **act
7171

7272
{% tabs %}
7373
{% tab title="Operators" %}
74-
```javascript
75-
export const search = pipe(
74+
```typescript
75+
export const search: Operator<string> = pipe(
7676
mutate(({ state }, query) => {
7777
state.query = query
7878
}),
@@ -88,8 +88,16 @@ export const search = pipe(
8888
{% endtab %}
8989

9090
{% tab title="Statechart" %}
91-
```javascript
92-
const loginChart = {
91+
```typescript
92+
const loginChart: Statechart<
93+
typeof config,
94+
{
95+
LOGIN: void
96+
AUTHENTICATING: void
97+
AUTHENTICATED: void
98+
ERROR: void
99+
}
100+
> = {
93101
initial: 'LOGIN',
94102
states: {
95103
LOGIN: {
@@ -121,15 +129,15 @@ const loginChart = {
121129
{% endtab %}
122130

123131
{% tab title="Class state" %}
124-
```javascript
132+
```typescript
125133
class LoginForm() {
126-
private username = ''
127-
private password = ''
128-
private validationError = ''
129-
changeUsername(username) {
134+
private username: string = ''
135+
private password: string = ''
136+
private validationError: string = ''
137+
changeUsername(username: string) {
130138
this.username = username
131139
}
132-
changePassword(password) {
140+
changePassword(password: string) {
133141
if (!password.match([0-9]) {
134142
this.validationError = 'You need some numbers in your password'
135143
}
@@ -140,7 +148,11 @@ class LoginForm() {
140148
}
141149
}
142150

143-
export const state = {
151+
type State = {
152+
loginForm: LoginForm
153+
}
154+
155+
export const state: State = {
144156
loginForm: new LoginForm()
145157
}
146158
```
@@ -151,7 +163,7 @@ export const state = {
151163
152164
Bring in your application configuration of state, effects and actions. Create mocks for any effects. Take a snapshot of mutations performed in an action to ensure all intermediate states are met.
153165
154-
```javascript
166+
```typescript
155167
import { createOvermindMock } from 'overmind'
156168
import { config } from './'
157169

SUMMARY.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@
1111
* [State](core/defining-state.md)
1212
* [Actions](core/writing-application-logic.md)
1313
* [Effects](core/running-side-effects.md)
14-
* [Operators](core/going-functional.md)
15-
* [Statecharts](core/statecharts.md)
14+
* [Operators](features/going-functional.md)
15+
* [Statecharts](features/statecharts.md)
1616
* [Typescript](core/typescript.md)
1717

1818
## Features
1919

2020
## Addons
2121

22-
* [React](addons/react.md)
23-
* [Angular](addons/angular.md)
24-
* [Vue](addons/vue.md)
25-
* [GraphQL](addons/graphql.md)
22+
* [React](view-layers/react.md)
23+
* [Angular](view-layers/angular.md)
24+
* [Vue](view-layers/vue.md)
25+
* [GraphQL](features/graphql.md)
2626

2727
## Guides <a id="guides-1"></a>
2828

29-
* [Testing](guides-1/testing.md)
29+
* [Testing](features/testing.md)
3030
* [Structuring the app](guides-1/structuring-the-app.md)
3131
* [Connecting components](guides-1/connecting-components.md)
3232
* [Managing lists](guides-1/managing-lists.md)
3333
* [State first routing](guides-1/state-first-routing.md)
34-
* [Server Side Rendering](guides-1/server-side-rendering.md)
34+
* [Server Side Rendering](features/server-side-rendering.md)
3535

3636
## API <a id="api-1"></a>
3737

0 commit comments

Comments
 (0)