Skip to content

Commit 7a3e955

Browse files
authored
Merge branch 'this-is-angular:main' into aboudard-patch-3
2 parents 5b12bf6 + f0ef5fb commit 7a3e955

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

docs/chapter-2.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ As I mentioned in the previous chapter, we are going to create an Angular financ
2020

2121
1. Open a preferred directory of yours
2222
2. Run the following command `ng new finance-logger`
23-
3. You can select a number of options, add routing, SCSS, and so on. Those options are irrelevant tou this tutorial
23+
3. You can select a number of options, add routing, SCSS, and so on. Those options are irrelevant to this tutorial
2424
4. Wait a bit
2525
5. Application has been created
2626

@@ -48,7 +48,7 @@ And in the `imports` array of the `AppModule` declarations, add this line:
4848
// other metadata
4949
imports: [
5050
// other imports
51-
StoreModule.forRoot(),
51+
StoreModule.forRoot({}),
5252
],
5353
})
5454
export class AppModule {}
@@ -58,4 +58,4 @@ export class AppModule {}
5858
2. Open `http://localhost:4200/`
5959
3. See our fresh Angular app
6060

61-
That's it, we did the basic installations, let's now move on to chapter 3, where we will explore the the
61+
That's it, we did the basic installations, let's now move on to chapter 3, where we will explore the What.

docs/chapter-6.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import Exercise2Reducer from "!!raw-loader!./chapter-6/exercise-2/reducer";
99

1010
## How do we modify the State?
1111

12-
So far, we have learned how to create `Actions`, the building blocks of NgRx, that signal the `Store` about what happened in the application and what needs to be done. But `Actions` are just objects, that don;t hold any functionality; they by themselves cannot make any `State` changes. To make those changes actually happen, we have to use a `Reducer`, next of the core most important concepts of NgRx.
12+
So far, we have learned how to create `Actions`, the building blocks of NgRx, that signal the `Store` about what happened in the application and what needs to be done. But `Actions` are just objects, that don't hold any functionality; they by themselves cannot make any `State` changes. To make those changes actually happen, we have to use a `Reducer`, next of the core most important concepts of NgRx.
1313

1414
## What are Reducers?
1515

16-
Reducers are _pure functions_ that receiver two arguments, the current `State` of the application, an `Action` object, calculate the new state based on the `Action` that happened, and return that new `State`. Usually calculating involves determining which `Action` happened (sometimes via `switch-case` statements, but NgRx provides utilities that reduce boilerplate), copying the previous state into a new object while modifying the relevant properties of the `State`, and returning the new `State` object. Every time an `Action` is dispatched (we will learn more about dispatching in the next chapters, for now "dispatching" an `Action` means the `Action` has happened), NgRx will call the `Reducer` function, providing the old `State` and the `Action` object as arguments, get the returned new `State` and immediately notify all of our components about the change (how neat is that!). Essentially, `Reducers` are the central place where `State` changes happen.
16+
Reducers are _pure functions_ that receive two arguments, the current `State` of the application, an `Action` object, calculate the new state based on the `Action` that happened, and return that new `State`. Usually calculating involves determining which `Action` happened (sometimes via `switch-case` statements, but NgRx provides utilities that reduce boilerplate), copying the previous state into a new object while modifying the relevant properties of the `State`, and returning the new `State` object. Every time an `Action` is dispatched (we will learn more about dispatching in the next chapters, for now "dispatching" an `Action` means the `Action` has happened), NgRx will call the `Reducer` function, providing the old `State` and the `Action` object as arguments, get the returned new `State` and immediately notify all of our components about the change (how neat is that!). Essentially, `Reducers` are the central place where `State` changes happen.
1717

1818
## What are pure functions?
1919

@@ -120,7 +120,7 @@ export function reducer(state: AppState, action: Action) {
120120
Let's understand what goes on here. First of all, we have the `createReducer` function, which does exactly that - creates the resulting `Reducer` function. It receives the initial state of the application, and then an arbitrary amount of handlers for each action (we provided only one, but we can (and will!) have lots of `Actions`, and thus. lots of `on` function calls). The `on` function receives an `Action` as the first argument, and a callback function as a second one, which acts like a mini-`Reducer` for only that specific `Action`. Thus, the need to write huge `switch` statements is eliminated. Now let's understand two specific parts of this code:
121121

122122
1. _Why did we create a `_reducer` function only to call it in the `reducer` function?_ The thing is, in the next chapters we are going to register the `reducer` function in our `AppModule`, and because of how the Angular build process works, it does not allow including anonymous functions like the one returned by `createReducer`, only declared named functions. Thus we wrote a conventional function and called our `_reducer` from it. **Always create `Reducers` like this**.
123-
2. _Why didn't we `import` the `Action` we wanted by name, but rather did `import _ as actions from './actions';`?* Because we can easily have dozens of `Actions`that are handled in a single`Reducer` function, we would like to import them as a single object to avoid too cluttered imports.
123+
2. _Why didn't we `import` the `Action` we wanted by name, but rather did `import * as actions from './actions';`? Because we can easily have dozens of `Actions` that are handled in a single `Reducer` function, we would like to import them as a single object to avoid too cluttered imports.
124124

125125
## Homework
126126

0 commit comments

Comments
 (0)