From e5237ecbe5d82d045c2a315a56e5a831e32f7f38 Mon Sep 17 00:00:00 2001 From: David Bonnet Date: Sun, 2 Jun 2019 19:20:23 +0200 Subject: [PATCH] feat(values): add flattenValue decorator --- README.md | 9 +++++++++ src/values.js | 13 ++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1bcc5df7..d145beb3 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ The `realue` module exposes the following functions: - [`promised`](#promised) - [`toggledEditing`](#toggledediting) - [`fromValue()`](#fromvalue) + - [`flattenValue`](#flattenvalue) - [Tooling decorators](#tooling-decorators) - [`logProps()`](#logprops) - [`omitProps()`](#omitprops) @@ -312,6 +313,14 @@ Sets the `editing` prop and enables its toggling through the `onToggleEditing()` Adapts `onChange` for components that call it by providing the `value` as a first argument. If the `path` is not `nil`, extracts the value from `get(value, path)`. +#### `flattenValue` + +> ⬆️ `{ value }` + +> ⬇️ `{ ...value }` + +Merges the properties of the `value` object prop into the props. + ### Tooling decorators #### `logProps()` diff --git a/src/values.js b/src/values.js index 45ac4b8b..6a502923 100644 --- a/src/values.js +++ b/src/values.js @@ -1,5 +1,11 @@ import { Component as BaseComponent } from 'react' -import { compose, branch, withHandlers, withPropsOnChange } from 'recompose' +import { + compose, + branch, + withHandlers, + withPropsOnChange, + flattenProp, +} from 'recompose' import { memoize, get } from 'lodash' import { $, hasProp, hasProps, lazyProperty, setWrapperName } from './tools' @@ -244,3 +250,8 @@ export const fromValue = memoize((path) => { withHandlers({ onChange: onChangeFromPath(path) }), ) }) + +/* +Merges the properties of the `value` object prop into the props. +*/ +export const flattenValue = flattenProp('value')