main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
826 bytes
|
Rev | Line | |
---|
[d24f17c] | 1 | import { curryN, pipe, mergeAll, props } from 'ramda';
|
---|
| 2 |
|
---|
| 3 | /**
|
---|
| 4 | * Functional equivalent of merging object properties with object spread operator.
|
---|
| 5 | *
|
---|
| 6 | * @func mergeProps
|
---|
| 7 | * @memberOf RA
|
---|
| 8 | * @since {@link https://char0n.github.io/ramda-adjunct/1.17.0|v1.17.0}
|
---|
| 9 | * @category Object
|
---|
| 10 | * @sig [k] -> {k: {a}} -> {a}
|
---|
| 11 | * @see {@link RA.mergePaths|mergePaths}
|
---|
| 12 | * @param {!Array} ps The property names to merge
|
---|
| 13 | * @param {!Object} obj The object to query
|
---|
| 14 | * @return {!Object} The object composed of merged properties of obj
|
---|
| 15 | * @example
|
---|
| 16 | *
|
---|
| 17 | * const obj = {
|
---|
| 18 | * foo: { fooInner: 1 },
|
---|
| 19 | * bar: { barInner: 2 }
|
---|
| 20 | * };
|
---|
| 21 | *
|
---|
| 22 | * { ...obj.foo, ...obj.bar }; //=> { fooInner: 1, barInner: 2 }
|
---|
| 23 | * RA.mergeProps(['foo', 'bar'], obj); //=> { fooInner: 1, barInner: 2 }
|
---|
| 24 | */
|
---|
| 25 | const mergeProps = curryN(2, pipe(props, mergeAll));
|
---|
| 26 |
|
---|
| 27 | export default mergeProps;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.