Skip to content

Commit acffb45

Browse files
authored
Tweak 05_runningsideeffects for fluency
1 parent 0ddaaf4 commit acffb45

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

packages/overmind-website/guides/beginner/05_runningsideeffects.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Running side effects
22

3-
Developing applications is not only about managing state, but also managing side effects. A side effect is typically exampled with an http request or talking to local storage. In Overmind we just call this **effects**. There are several reasons why you would want to use effects:
3+
Developing applications is not only about managing state, but also managing side effects. A typical side effect would be an HTTP request or talking to localStorage. In Overmind we just call these **effects**. There are several reasons why you would want to use effects:
44

55
1. All the code in your actions will be domain specific, no low level generic APIs
6-
2. Your actions will have less code and you avoid leaking out things like urls, types etc.
7-
3. You decouple the underlying tool from the usage of it, meaning that you can replace it at any time without changing your application logic
8-
4. You can more easily expand functionality of an effect. For example you want to introduce caching or a base url to an http effect
6+
2. Your actions will have less code and you avoid leaking out things like URLs, types etc.
7+
3. You decouple the underlying tool from its usage, meaning that you can replace it at any time without changing your application logic
8+
4. You can more easily expand the functionality of an effect. For example you want to introduce caching or a base URL to an HTTP effect
99
5. The devtool tracks its execution
10-
6. If you write Overmind tests you can easily mock them
11-
7. You can lazy load the effect, reducing the initial payload of the app
10+
6. If you write Overmind tests, you can easily mock them
11+
7. You can lazy-load the effect, reducing the initial payload of the app
1212

1313
## Exposing an existing tool
1414

@@ -18,15 +18,15 @@ Let us just expose the [axios](https://github.com/axios/axios) library as an **h
1818
h(Example, { name: "guide/runningsideeffects/axios" })
1919
```
2020

21-
We are just exporting the existing library from our effects file and include it in the application config. Now Overmind is aware of an **http** effect. It can track it for debugging and all actions and operators will have it injected.
21+
We are just exporting the existing library from our effects file and including it in the application config. Now Overmind is aware of an **http** effect. It can track it for debugging and all actions and operators will have it injected.
2222

2323
Let us put it to use in an action that grabs the current user of the application.
2424

2525
```marksy
2626
h(Example, { name: "guide/runningsideeffects/getuser" })
2727
```
2828

29-
That was basically it. As you can see we are exposing some low level details like the http method used and the url. Let us follow the encouraged way of doing things and create our own **api** effect.
29+
That was basically it. As you can see we are exposing some low level details like the http method used and the URL. Let us follow the encouraged way of doing things and create our own **api** effect.
3030

3131
## Specific API
3232

@@ -44,13 +44,13 @@ h(Example, { name: "guide/runningsideeffects/changestate" })
4444

4545
## Initializing effects
4646

47-
It can be a good idea to not allow your side effects to initialize when they are defined. This makes sure that they do not leak into tests or server side rendering. For example if you want to use Firebase. Instead of initializing the Firebase application immediately we rather do it behind an **initialize** method:
47+
It can be a good idea to not allow your side effects to initialize when they are defined. This makes sure that they do not leak into tests or server side rendering. For example if you want to use Firebase, instead of initializing the Firebase application immediately we rather do it behind an **initialize** method:
4848

4949
```marksy
5050
h(Example, { name: "guide/runningsideeffects/initialize" })
5151
```
5252

53-
We are doing 2 things here:
53+
We are doing two things here:
5454

5555
1. We use an [IIFE](https://developer.mozilla.org/en-US/docs/Glossary/IIFE) to create a scoped internal variable to be used for that specific effect
5656
2. We have created an **initialize** method which we can call from the Overmind **onInitialize** action, which runs when the Overmind instance is created
@@ -80,7 +80,7 @@ You can also lazily load your effects in the **initialize** method. Let us say w
8080
h(Example, { name: "guide/runningsideeffects/lazy" })
8181
```
8282

83-
In our initialize we would just have to wait for the initialize to finish before using the API:
83+
In our initialize() we would just have to wait for the initialization to finish before using the API:
8484

8585

8686
```marksy
@@ -101,4 +101,4 @@ h(Example, { name: "guide/runningsideeffects/class" })
101101
We export an instance of our **Api** to the application. This allows us to also create instances in isolation for testing purposes, making sure our Api class works as we expect.
102102

103103
## Summary
104-
Importing side effects directly into your code should be considered bad practice. If you think about it from an application standpoint it is kinda weird that it runs http verb methods with a string url. It is better to create an abstraction around it to make your code more consistent with the domain, and by doing so also improve maintainability.
104+
Importing side effects directly into your code should be considered bad practice. If you think about it from an application standpoint it is kinda weird that it runs HTTP verb methods with a URL string passed in. It is better to create an abstraction around it to make your code more consistent with the domain, and by doing so also improve maintainability.

0 commit comments

Comments
 (0)