|
@@ -12,7 +12,7 @@ Rest of the state is left untouched.
|
|
```js
|
|
```js
|
|
const r = subReducer("persons", personReducer);
|
|
const r = subReducer("persons", personReducer);
|
|
|
|
|
|
- r({persons: ["John", "Jill"], cars: ["Honda"]}, action);
|
|
|
|
|
|
+ r({persons: ["John", "Jill"], cars: ["Honda"]}, cityon);
|
|
// => {
|
|
// => {
|
|
// persons: personReducer(["John", "Jill"], action),
|
|
// persons: personReducer(["John", "Jill"], action),
|
|
// cars: ["Honda"]
|
|
// cars: ["Honda"]
|
|
@@ -59,3 +59,33 @@ Useful to "concatenate" a few `subReducer`s. like:
|
|
baseReducer
|
|
baseReducer
|
|
)
|
|
)
|
|
```
|
|
```
|
|
|
|
+
|
|
|
|
+## `cowValueModel(key)`
|
|
|
|
+
|
|
|
|
+Creates an object with set of functions allowing
|
|
|
|
+to `set` or `get` specified key from any object.
|
|
|
|
+You can use dot notation.
|
|
|
|
+
|
|
|
|
+Setting return a copy with specified (sub-)property changed;
|
|
|
|
+in case no change actually happens, returns the original object.
|
|
|
|
+
|
|
|
|
+```js
|
|
|
|
+ const name = cowValueModel("name");
|
|
|
|
+
|
|
|
|
+ name.get({name: "Tom"});
|
|
|
|
+ // => "Tom"
|
|
|
|
+ name.set({name: "Tom"}, "Jerry");
|
|
|
|
+ // => {name: "Jerry"}
|
|
|
|
+
|
|
|
|
+ const city = cowValueModel("address.city");
|
|
|
|
+ const object = {address: {city: "New York"}};
|
|
|
|
+
|
|
|
|
+ city.get(object);
|
|
|
|
+ // => "New York"
|
|
|
|
+ city.set(object, "London");
|
|
|
|
+ // => {address: {city: "London"}}
|
|
|
|
+ object;
|
|
|
|
+ // => {address: {city: "New York"}}
|
|
|
|
+ city.set(object, "New York") === object;
|
|
|
|
+ // => true
|
|
|
|
+```
|