Skip to content

Commit

Permalink
feat(values): add flattenValue decorator
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbonnet committed Jun 2, 2019
1 parent 699fecc commit e5237ec
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()`
Expand Down
13 changes: 12 additions & 1 deletion src/values.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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')

0 comments on commit e5237ec

Please sign in to comment.