Skip to content

Commit df2304b

Browse files
christianalfonigitbook-bot
authored andcommitted
GitBook: [master] one page modified
1 parent 9659358 commit df2304b

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

introduction.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ If you rather want to go right ahead and set up a local project, please have a l
88

99
Before we move on, have a quick look at this sandbox. It is a simple counter application and it gives you some foundation before talking more about Overmind and building applications.
1010

11-
{% embed url="https://codesandbox.io/s/overmind-counter-c4tuh?from-embed" %}
11+
{% embed url="https://codesandbox.io/embed/overmind-counter-c4tuh?fontsize=14&hidenavigation=1&theme=dark&view=editor" %}
12+
13+
14+
15+
1216

1317
## Application state VS Component state
1418

@@ -93,7 +97,7 @@ And as we will see later you will also be using **effects** from the context.
9397

9498
Now we will move to a more complex example. Please have a look:
9599

96-
{% embed url="https://codesandbox.io/s/overmind-todomvc-simple-097zs?from-embed" %}
100+
{% embed url="https://codesandbox.io/embed/overmind-todomvc-simple-097zs?fontsize=14&hidenavigation=1&module=%2Fsrc%2Fapp.js&theme=dark&view=editor" %}
97101

98102
We have now separated out the Overmind related logic into its own file, **app.js**. This file creates the Overmind instance and also exports how the components will interact with the state and the actions, the hook called **useApp**. Vue and Angular has other mechanisms conventional to those frameworks where application state and actions can be accessed.
99103

@@ -183,7 +187,7 @@ Any function you insert into the state tree is treated as derived state. That me
183187

184188
Now let us move into an even more complex application. Here we have added **effects**. Specifically effects to handle routing, storing todos to local storage and producing unique ids for the todos. We have added an **onInitialize** hook which is a special function Overmind runs when the application starts.
185189

186-
{% embed url="https://codesandbox.io/s/overmind-todomvc-2im6p?from-embed" %}
190+
{% embed url="https://codesandbox.io/embed/overmind-todomvc-2im6p?fontsize=14&hidenavigation=1&module=%2Fsrc%2Fapp.js&theme=dark&view=editor" %}
187191

188192
You can think of effects as a contract between your application and the outside world. You write an effect API of **what** your application needs and some 3rd party tool or native JavaScript API will implement **how** to provide it. Let us look at the router:
189193

@@ -223,7 +227,7 @@ This argument passed is transformed into something Page can understand. What thi
223227

224228
Defining all the state, actions and effects on one object would not work very well for a large application. A convention in Overmind is to split these concepts into different files behind folders representing a domain of the application. In this next sandbox you can see how we split up state, actions and effects into different files. They are all exposed through a main file representing that domain, in this case “the root domain”:
225229

226-
{% embed url="https://codesandbox.io/s/overmind-todomvc-split-xdh41?from-embed" %}
230+
{% embed url="https://codesandbox.io/embed/overmind-todomvc-split-xdh41?fontsize=14&hidenavigation=1&module=%2Fsrc%2Fapp%2Findex.js&theme=dark&view=editor" %}
227231

228232
Also notice that we have split up the instantiation of Overmind from the definition of the application. What this allows us to do is reuse the same application configuration for testing purposes and/or server side rendering. We separate the definition from the instantiation.
229233

@@ -239,7 +243,7 @@ Have a look at this new project where we have typed the application:
239243
You have to **OPEN IN EDITOR** to get the full Typescript experience.
240244
{% endhint %}
241245

242-
{% embed url="https://codesandbox.io/s/overmind-todomvc-typescript-39h7y?from-embed" %}
246+
{% embed url="https://codesandbox.io/embed/overmind-todomvc-typescript-39h7y?fontsize=14&hidenavigation=1&module=%2Fsrc%2Fapp%2Findex.ts&theme=dark&view=editor" %}
243247

244248
As you can see we only have to add an **Action** type to our functions and optionally give it an input type. This is enough for the action to give you all information about the application. Try changing some code and even add some code to see how Typescript helps you to explore the application and ensure that you implement new functionality correctly.
245249

0 commit comments

Comments
 (0)