Skip to content

Commit e22fdea

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

File tree

2 files changed

+8
-94
lines changed

2 files changed

+8
-94
lines changed

README.md

Lines changed: 7 additions & 93 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 necessarily 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 having to implement UI.
1212

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

1515
## A SINGLE STATE TREE
1616

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.
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.
1818

1919
```typescript
2020
{
@@ -32,26 +32,15 @@ Building your application with a single state tree is the most straight forward
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" %}
3735
```typescript
38-
export const fetchItems = async (): Promise<Item[]> {
36+
export const api = {
37+
async fetchItems(): Promise<Item[]> {
3938
const response = await fetch('/api/items')
4039

4140
return response.json()
4241
}
4342
}
4443
```
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 %}
5544

5645
## SAFE AND PREDICTABLE CHANGES
5746

@@ -65,12 +54,10 @@ export const getItems: AsyncAction = async ({ state, effects }) => {
6554
}
6655
```
6756

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

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.
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!
7160

72-
{% tabs %}
73-
{% tab title="Operators" %}
7461
```typescript
7562
export const search: Operator<string> = pipe(
7663
mutate(({ state }, query) => {
@@ -85,79 +72,6 @@ export const search: Operator<string> = pipe(
8572
})
8673
)
8774
```
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 %}
16175

16276
## SNAPSHOT TESTING OF LOGIC
16377

@@ -188,5 +102,5 @@ Overmind has you covered on typing. If you choose to use Typescript the whole AP
188102

189103
![](.gitbook/assets/256x256.png)
190104

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.
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.
192106

introduction.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ Our todo has been added and we can even see how the derived state was affected b
329329

330330
## Managing complexity
331331

332-
Overmind gives you a basic foundation with its **state**, **actions** and **effects**. As mentioned previously you can split these up into multiple namespaces to organize your code. This manages the complexity of scaling. There is also a complexity of reusability and managing execution over time. The **operators** API allows you to split your logic into many different composable parts. With operators like **debounce**, **waitUntil** etc. you are able to manage execution over time. With the latest addition of **statecharts** you have the possiblity to manage the complexity of state and interaction. What interactions should be allowed in what states.
332+
Overmind gives you a basic foundation with its **state**, **actions** and **effects**. As mentioned previously you can split these up into multiple namespaces to organize your code. This manages the complexity of scaling. There is also a complexity of reusability and managing execution over time. The **operators** API allows you to split your logic into many different composable parts. With operators like **debounce**, **waitUntil** etc. you are able to manage execution over time. With the latest addition of **statecharts** you have the possiblity to manage the complexity of state and interaction. What interactions should be allowed in what states. And with state values as **class instances** you are able to co-locate state with logic.
333333

334334
The great thing about Overmind is that none of these concepts are forced upon you. If you want to build your entire app in the root namespace, only using actions, that is perfectly fine. You want to bring in operators for a single action to manage time complexity, do that. Or do you have a concept where you want to safely control what actions can run in certain states, use a statechart. Overmind just gives you tools, it is up to you to determine if they are needed or not.
335335

0 commit comments

Comments
 (0)