Redux: Service Calls
diff --git a/package-lock.json b/package-lock.json
index 5e52d08..f73efe1 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -8527,6 +8527,11 @@
"json-stringify-safe": "^5.0.1"
}
},
+ "redux-react-hook": {
+ "version": "3.2.0",
+ "resolved": "https://registry.npmjs.org/redux-react-hook/-/redux-react-hook-3.2.0.tgz",
+ "integrity": "sha512-GibqTO/Cgl2nRuhw2wacyfd2Nds8pYAPU/eYuTqXZ9v01CT7s7LSwDfPdtQua7TBqE8XNjrwKZqfDyEtfXt7vQ=="
+ },
"redux-starter-kit": {
"version": "0.4.3",
"resolved": "https://registry.npmjs.org/redux-starter-kit/-/redux-starter-kit-0.4.3.tgz",
diff --git a/step2-05/demo/src/reducers/index.ts b/step2-05/demo/src/reducers/index.ts
index 3fac61f..757ac54 100644
--- a/step2-05/demo/src/reducers/index.ts
+++ b/step2-05/demo/src/reducers/index.ts
@@ -14,10 +14,6 @@ export const todosReducer = createReducer
(
},
clear(state, action) {
- state[action.id].completed = !state[action.id].completed;
- },
-
- complete(state, action) {
Object.keys(state).forEach(key => {
if (state[key].completed) {
delete state[key];
@@ -25,6 +21,10 @@ export const todosReducer = createReducer(
});
},
+ complete(state, action) {
+ state[action.id].completed = !state[action.id].completed;
+ },
+
edit(state, action) {
state[action.id].label = action.label;
}
diff --git a/step2-06/demo/README.md b/step2-06/demo/README.md
index 29823ba..20aa091 100644
--- a/step2-06/demo/README.md
+++ b/step2-06/demo/README.md
@@ -1,68 +1,14 @@
-# Step 2.6 - Redux: Dispatching actions and examining state (Demo)
+# Step 2.6: Redux: React Binding (Demo)
[Lessons](../) | [Exercise](./exercise/) | [Demo](./demo/)
-In this step, we learn about the Redux methods `dispatch()` and `getState()`. Dispatching action messages to the store is the only means by which to instruct the reducers to modify the shared state tree.
+In this step, we will continue with Redux. Step 2.5 code can be used with any other web frameworks. This step, we will hook up the Redux store with React components.
-We also see how to compose reducers to make up the complete state shape.
+We will demonstrate how to:
-## Dispatch
+1. Bind Redux store to Class Components
+2. Bind Redux store to Functional Components
-Given a store reference, you can [dispatch](https://redux.js.org/api/store#dispatch) an action to trigger the middleware and reducers. This changes the store and causes the view to re-render. (We'll look at how to pass the store and the dispatch function into the view later.)
+## Bind Redux store to Class Components
-```ts
-const store = createStore(reducers);
-store.dispatch(actions.addTodo('id0', 'hello world'));
-```
-
-> Important note: Dispatches generally have a "fire and forget" approach. We expect React to re-render the UI correctly of its own accord. (Rendering isn't necessarily synchronous in React! Chaining async action creators is a topic for Step 9.)
-
-## Reducers scoped to a portion of the state tree
-
-In general, when an application grows, so does the complexity of the state tree. In a Redux application, it is best to have reducers that deal with only a sub-portion of the tree.
-
-In our example, we have two parts of our state: `todos` and `filter`. We will [split the reducer](https://redux.js.org/basics/reducers#splitting-reducers) to pass the todos to a `todosReducer()` function and just return `all` to the `filter` key for now. This organization helps in navigating and understanding the reducers because it matches the shape of the state one-to-one: there's a separate reducer for each key in state.
-
-Compare this example which handles the whole state in one reducer...
-
-```ts
-// remember the shape of the store
-{
- todos: {
- id0: {...},
- id1: {...},
- },
-
- filter: 'all'
-}
-```
-
-...to this one which splits it up.
-
-```ts
-function reducers(state, action) {
- return {
- todos: function todoReducers(state['todos'], action) {
- ...
- },
-
- filter: function filterReducers(state['filter'], action) {
- ...
- }
- }
-}
-```
-
-With the second example, it is easy to understand which reducer changed a given part of the state.
-
-## `getState()`
-
-To examine the state of the store, you can call `store.getState()` to get a snapshot of the current state.
-
-In general, you should only include serializable things in the state so that you can easily save or transfer it. You can even save this state into a browser's local storage and restore for the next boot of your application!
-
-## Visualizing the reducer and store change
-
-If you want a really neat UI to show what the store looks when actions are dispatched to the store, use the [Redux DevTools extension](https://chrome.google.com/webstore/detail/redux-devtools/lmhkpmbekcpmknklioeibfkpmmfibljd).
-
-This extension (available for Chrome and Firefox) is a work of genius! It lets you replay actions and step backwards to debug the current state of a Redux application. In a large enough application, this kind of debuggability is invaluable. It also helps developers who are not familiar with your application to quickly get a handle on how the state changes in response to some actions.
+## Bind Redux store to Functional Components
diff --git a/step2-06/demo/index.html b/step2-06/demo/index.html
index 92a9499..e848070 100644
--- a/step2-06/demo/index.html
+++ b/step2-06/demo/index.html
@@ -5,11 +5,7 @@
-
- For this step, we look at unit testing. Run
-
npm test
- in the command line.
-
+