|
@@ -60,11 +60,12 @@ Useful to "concatenate" a few `subReducer`s. like:
|
|
|
)
|
|
|
```
|
|
|
|
|
|
-## `cowValueModel(key)`
|
|
|
+## `cowValueModel(key, ...)`
|
|
|
|
|
|
Creates an object with set of functions allowing
|
|
|
to set or get specified key from any object.
|
|
|
Get when one arg, set when two args.
|
|
|
+Specify keys by passing a list of keys to `cowValueModel`.
|
|
|
You can use dot notation.
|
|
|
|
|
|
Setting return a copy with specified (sub-)property changed;
|
|
@@ -79,25 +80,29 @@ in case no change actually happens, returns the original object.
|
|
|
// => {name: "Jerry"}
|
|
|
|
|
|
const city = cowValueModel("address.city");
|
|
|
+ const city2 = cowValueModel("address", "city");
|
|
|
const object = {address: {city: "New York"}};
|
|
|
|
|
|
city(object);
|
|
|
// => "New York"
|
|
|
+ city2(object);
|
|
|
+ // => "New York"
|
|
|
city(object, "London");
|
|
|
// => {address: {city: "London"}}
|
|
|
+ city2(object, "London");
|
|
|
+ // => {address: {city: "London"}}
|
|
|
object;
|
|
|
// => {address: {city: "New York"}}
|
|
|
city(object, "New York") === object;
|
|
|
// => true
|
|
|
+ city2(object, "New York") === object;
|
|
|
+ // => true
|
|
|
```
|
|
|
|
|
|
-In case you pass second argument to `cowValueModel`,
|
|
|
-it is used as a parsed list of keys instead of default `firstArg.split('.')`.
|
|
|
-
|
|
|
If you put a number in a list of keys to use,
|
|
|
an object will be treated as an array (unlike the default string case,
|
|
|
where it is treated as an object), so copy wil be created
|
|
|
using `[...obj]`, not using `{...obj}`.
|
|
|
|
|
|
-That way you can create eg. `const c = cowValueObject("name of 34th person", ["person", 34, "name"])`
|
|
|
+That way you can create eg. `const c = cowValueObject("person", 34, "name")`
|
|
|
to access `obj.person[34].name` with `c(obj)` / `c(obj, val)`.
|