Skip to content

Commit fde28fe

Browse files
christianalfonigitbook-bot
authored andcommitted
GitBook: [master] 2 pages modified
1 parent e22fdea commit fde28fe

File tree

2 files changed

+110
-8
lines changed

2 files changed

+110
-8
lines changed

README.md

Lines changed: 93 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ description: frictionless state management
88
99
## APPLICATION INSIGHT
1010

11-
Develop the application state, effects and actions without leaving [VS Code](https://code.visualstudio.com/), or use the standalone development tool. Everything that happens in your app is tracked and you can seamlessly code and run logic to verify that everything works as expected without having to implement UI.
11+
Develop the application state, effects and actions without leaving [VS Code](https://code.visualstudio.com/), or use the standalone development tool. Everything that happens in your app is tracked and you can seamlessly code and run logic to verify that everything works as expected without necessarily having to implement UI.
1212

1313
![](.gitbook/assets/amazing_devtools.png)
1414

1515
## A SINGLE STATE TREE
1616

17-
Building your application as a single state tree is the most straight forward mental model. You get a complete overview, but can still organize the state by namespacing it into domains. The devtools allows you to edit and mock out state.
17+
Building your application with a single state tree is the most straight forward mental model. You get a complete overview, but can still organize the state by namespacing it into domains. The devtools allows you to edit and mock out state.
1818

1919
```typescript
2020
{
@@ -32,15 +32,26 @@ Building your application as a single state tree is the most straight forward me
3232

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

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

4041
return response.json()
4142
}
4243
}
4344
```
45+
{% endtab %}
46+
47+
{% tab title="actions.ts" %}
48+
```typescript
49+
export const loadApp: AsyncAction = ({ state, effects }) => {
50+
state.items = await effects.api.fetchItems()
51+
}
52+
```
53+
{% endtab %}
54+
{% endtabs %}
4455

4556
## SAFE AND PREDICTABLE CHANGES
4657

@@ -54,10 +65,12 @@ export const getItems: AsyncAction = async ({ state, effects }) => {
5465
}
5566
```
5667

57-
## FUNCTIONAL ACTIONS
68+
## COMPLEXITY TOOLS
5869

59-
When pieces of logic become complex it is beneficial to write functional code. Overmind provides an API named **operators** which gives you functional power. Ignore it, use it where it makes sense or make your whole codebase functional. It is up to you!
70+
Even though Overmind can create applications with only plain **state** and **actions**, you can use **opt-in** tools like **functional operators**, **statecharts** and state values defined as a **class,** to manage complexities of your application.
6071

72+
{% tabs %}
73+
{% tab title="Operators" %}
6174
```typescript
6275
export const search: Operator<string> = pipe(
6376
mutate(({ state }, query) => {
@@ -72,6 +85,79 @@ export const search: Operator<string> = pipe(
7285
})
7386
)
7487
```
88+
{% endtab %}
89+
90+
{% tab title="Statechart" %}
91+
```typescript
92+
const loginChart: Statechart<
93+
typeof config,
94+
{
95+
LOGIN: void
96+
AUTHENTICATING: void
97+
AUTHENTICATED: void
98+
ERROR: void
99+
}
100+
> = {
101+
initial: 'LOGIN',
102+
states: {
103+
LOGIN: {
104+
on: {
105+
changeUsername: null,
106+
changePassword: null,
107+
login: 'AUTHENTICATING'
108+
}
109+
},
110+
AUTHENTICATING: {
111+
on: {
112+
resolveUser: 'AUTHENTICATED',
113+
rejectUser: 'ERROR'
114+
}
115+
},
116+
AUTHENTICATED: {
117+
on: {
118+
logout: 'LOGIN'
119+
}
120+
},
121+
ERROR: {
122+
on: {
123+
tryAgain: 'LOGIN'
124+
}
125+
}
126+
}
127+
}
128+
```
129+
{% endtab %}
130+
131+
{% tab title="Class state" %}
132+
```typescript
133+
class LoginForm() {
134+
private username: string = ''
135+
private password: string = ''
136+
private validationError: string = ''
137+
changeUsername(username: string) {
138+
this.username = username
139+
}
140+
changePassword(password: string) {
141+
if (!password.match([0-9]) {
142+
this.validationError = 'You need some numbers in your password'
143+
}
144+
this.password = password
145+
}
146+
isValid() {
147+
return Boolean(this.username && this.password)
148+
}
149+
}
150+
151+
type State = {
152+
loginForm: LoginForm
153+
}
154+
155+
export const state: State = {
156+
loginForm: new LoginForm()
157+
}
158+
```
159+
{% endtab %}
160+
{% endtabs %}
75161
76162
## SNAPSHOT TESTING OF LOGIC
77163
@@ -102,5 +188,5 @@ Overmind has you covered on typing. If you choose to use Typescript the whole AP
102188
103189
![](.gitbook/assets/256x256.png)
104190
105-
Overmind is running the main application of [codesandbox.io](https://codesandbox.io). With its state and effects complexity Codesandbox benefits greatly by Overmind using Typescript.
191+
Overmind is running the main application of [codesandbox.io](https://codesandbox.io). Codesandbox, with its state and effects complexity, benefits greatly combining Overmind and Typescript.
106192

quickstart.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,25 @@
22

33
From the command line install the Overmind package:
44

5+
{% tabs %}
6+
{% tab title="React" %}
7+
```
8+
npm install overmind overmind-react
9+
```
10+
{% endtab %}
11+
12+
{% tab title="Vue" %}
13+
```
14+
npm install overmind overmind-vue
15+
```
16+
{% endtab %}
17+
18+
{% tab title="Angular" %}
519
```text
6-
npm install overmind
20+
npm install overmind overmind-angular
721
```
22+
{% endtab %}
23+
{% endtabs %}
824

925
### Setup
1026

0 commit comments

Comments
 (0)