You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this terminology action is a function that returns a reducer.
13
+
**In this terminology action is a function that returns a reducer:**
14
14
15
15
```javascript
16
-
constselectUser=userId=>state=> ({
16
+
constincrement=amount=>state=> ({
17
17
...state,
18
-
selectedUser: userId
18
+
counter:state.counter+ amount
19
19
});
20
20
21
-
dispatch(selectUser(123));
21
+
store.dispatch(increment(42));
22
22
```
23
23
24
24
## Installation
@@ -37,7 +37,7 @@ npm install repatch
37
37
```javascript
38
38
importStorefrom'repatch';
39
39
40
-
conststore=newStore(<initialState>);
40
+
conststore=newStore(initialState);
41
41
```
42
42
43
43
In CommonJS format you should use:
@@ -58,18 +58,22 @@ unsubscribe();
58
58
59
59
## Sub-reducers
60
60
61
-
We do not need to reduce always the whole state of the store. A good practice to avoid this effort is using sub-reducers.
61
+
We do not need to reduce always the whole state of the store. Repatch also offers a way to combine sub-reducers, those describe a deeply nested property in the state. We just define a function that takes a nested reducer as argument, and returns a reducer that reduces the whole state:
62
62
63
63
```javascript
64
-
constreduceFoo=reducer=>state=> ({
64
+
constreduceFoo=fooReducer=>state=> ({
65
65
...state,
66
66
bar: {
67
67
...state.bar,
68
-
foo:reducer(state.bar.foo)
68
+
foo:fooReducer(state.bar.foo)
69
69
}
70
70
});
71
+
```
72
+
73
+
Using that we can define easily an action, that sets an `x` property in the `foo` object:
0 commit comments