Skip to content

Commit

Permalink
feat(child): add destination parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbonnet committed Jan 17, 2019
1 parent 9ef1dd0 commit 999e70d
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,9 +371,10 @@ export function withChildren(
childProps = DEFAULT_CHILDREN_PROPS,
shouldUpdateOrKeys = DEFAULT_KEYS,
valueName = 'value',
destination = 'children',
) {
/*
Builds an array that maps every item from the `[valueName]` prop with the result of `<Component {...childProps(props)(itemValue, itemIndex)}` and injects it as a `children` prop.
Builds an array that maps every item from the `[valueName]` prop with the result of `<Component {...childProps(props)(itemValue, itemIndex)}` and injects it as a `[destination]` prop.
The prop is only updated if `shouldUpdateOrKeys` returns `true` or if a prop whose name is listed in it changes.
Example:
Expand All @@ -384,7 +385,7 @@ export function withChildren(
const List = withChildren(Item, () => value => ({ value }))('ul')
*/
return withPropsOnChange(shouldUpdateOrKeys, props => ({
children: map(
[destination]: map(
props[valueName],
(childProps => (value, index) =>
$(Component, {
Expand All @@ -399,13 +400,14 @@ export function withChild(
Component,
childProps = identity,
shouldUpdateOrKeys = DEFAULT_KEYS,
destination = 'children',
) {
/*
Builds a child from the provided `Component` with the props from `childProps(props)` and injects it as a `children` prop.
Builds an element from the provided `Component` with the props from `childProps(props)` and injects it as a `[destination]` prop.
The prop is only updated if `shouldUpdateOrKeys` returns `true` or if a prop whose name is listed in it changes.
*/
return withPropsOnChange(shouldUpdateOrKeys, props => ({
children: $(Component, childProps(props)),
[destination]: $(Component, childProps(props)),
}))
}

Expand Down

0 comments on commit 999e70d

Please sign in to comment.