Skip to content

Commit 7cb7ba6

Browse files
committed
Address PR comments
1 parent 52504af commit 7cb7ba6

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

docs/chapter-5.mdx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ export class AppComponent implements OnInit {
5858
In the console, we will see the following:
5959

6060
```js
61-
{category: {name: 'Food', type: '[Category List] Add Category'}}
61+
{
62+
type: "[Category List] Add Category",
63+
category: { name: "Food" }
64+
}
6265
```
6366

6467
So essentially, `createAction` provided us with an easy way of creating a single action. `addCategory` in our case is an `ActionCreator`, a function which produces an action object whenever called, and `props` explained what argument that `ActionCreator` function expects.
@@ -67,7 +70,7 @@ So essentially, `createAction` provided us with an easy way of creating a single
6770

6871
As we just saw, creating an action is pretty straightforward.
6972

70-
However, when dealing with multiple actions, this can led to a more verbose code and prone to typos:
73+
However, when dealing with multiple actions, this can lead to a more verbose code and prone to typos:
7174

7275
```ts title="state/actions.ts"
7376
export const addCategory = createAction(
@@ -87,7 +90,7 @@ With those issues in mind, NgRx published a new function that allows us to creat
8790
Its usage is fairly simple and is based on two parameters:
8891

8992
- The source of the action, in our case `Category List`
90-
- A serie of properties symbolizing our actions and their parameters
93+
- A series of properties symbolizing our actions and their parameters
9194

9295
Let's go back to the previous example to see what is changing:
9396

@@ -108,6 +111,12 @@ categoryActions.addCategory({ category: 'Food' });
108111
categoryActions.addAnotherCategory({ category: 'Food' });
109112
```
110113

114+
:::note
115+
116+
Notice that our action types like `Add Category` written in plain English are converted to `addCategory` - a camel case variable name. This magic is done using [TypeScript's template literal types](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html) and the [mapped types](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html#handbook-content). [The source code for this](https://github.com/ngrx/platform/blob/master/modules/store/src/action_group_creator_models.ts) is pretty fascinating, if you're a TypeScript enthusiast, I strongly recommend checking it out or listen to. You can also listen to [Brandon Robert's video about the "TypeScript magic" behind the scenes](https://www.youtube.com/watch?v=V6eHIvwDFP4).
117+
118+
:::
119+
111120
## Homework
112121

113122
Yes, you've read it correctly: we have learned how to write some basic code in NgRx, so it is time for some homework!
@@ -118,16 +127,16 @@ We **strongly** recommand you not to move on to the next chapter without adding
118127

119128
:::
120129

121-
1. **Create an action for deleting a category**
130+
1. **Create an action for deleting a category**
122131
It should receive a string with the name of the category, and in the next chapter we will use that code to write the actual logic for deleting the category.
123-
2. **Create an action for updating a category**
132+
2. **Create an action for updating a category**
124133
It must receive a `Category` object (`{name: string}`), and again, we will write the code to update the category in the next chapter
125134

126135
> For this homework, assume categories cannot have duplicate names. We will deal with this problem later.
127136
128137
:::note
129138

130-
You will find solution code for all the homeworks in the end of the chapters
139+
You will find solution code for all the homeworks at the end of the chapters
131140

132141
:::
133142

0 commit comments

Comments
 (0)