How to use the recompose/withPropsOnChange function in recompose

To help you get started, we’ve selected a few recompose examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github istarkov / revue / src / prism / FileHeaders.js View on Github external
? Math.min(
            headersReversed[currentHeaderIdx - 1].lineNumber * rowHeight - scrollTop - rowHeight,
            0
          )
        : 0;

      return {
        offset,
        currentHeader: headersReversed[currentHeaderIdx] || {
          href: '',
          content: '',
        },
      };
    }
  ),
  withPropsOnChange(
    ['offset'],
    ({ offset, rowHeight }) => ({
      posStyle: {
        top: offset,
        height: rowHeight,
        paddingRight: scrollbarSize(), // memoized in lib
      },
    })
  ),
  // omit scrollParams
  mapProps(({ scrollParams, ...props }) => props), // eslint-disable-line
  pure
);

export default toClass(fileHeadersHOC(fileHeaders));
github plouc / nivo / packages / nivo-sunburst / src / SunburstArc.js View on Github external
onMouseLeave={hideTooltip}
    />
)

SunburstArc.propTypes = {
    node: PropTypes.shape({}).isRequired,
    arcGenerator: PropTypes.func.isRequired,
    borderWidth: PropTypes.number.isRequired,
    borderColor: PropTypes.string.isRequired,
    showTooltip: PropTypes.func.isRequired,
    hideTooltip: PropTypes.func.isRequired,
    theme: PropTypes.object.isRequired,
}

const enhance = compose(
    withPropsOnChange(['node', 'arcGenerator'], ({ node, arcGenerator }) => ({
        path: arcGenerator(node),
    })),
    withPropsOnChange(['node', 'showTooltip', 'theme'], ({ node, showTooltip, theme }) => ({
        showTooltip: e => {
            showTooltip(
                ,
                e
            )
        },
    })),
github plouc / nivo / packages / heatmap / src / enhance.js View on Github external
['sizeVariation', 'minValue', 'maxValue'],
            ({ sizeVariation, minValue, maxValue }) => {
                let sizeScale
                if (sizeVariation > 0) {
                    sizeScale = scaleLinear()
                        .range([1 - sizeVariation, 1])
                        .domain([minValue, maxValue])
                }

                return { sizeScale }
            }
        ),
        withPropsOnChange(['cellBorderColor', 'theme'], ({ cellBorderColor, theme }) => ({
            getCellBorderColor: getInheritedColorGenerator(cellBorderColor, theme),
        })),
        withPropsOnChange(['labelTextColor', 'theme'], ({ labelTextColor, theme }) => ({
            getLabelTextColor: getInheritedColorGenerator(labelTextColor, theme),
        })),
        pure
    )(Component)
github plouc / nivo / packages / core / src / hocs / withMotion.js View on Github external
export default () =>
    compose(
        setPropTypes(motionPropTypes),
        defaultProps({
            animate: defaultAnimate,
            motionDamping: defaultMotionDamping,
            motionStiffness: defaultMotionStiffness,
        }),
        withPropsOnChange(
            ['motionDamping', 'motionStiffness'],
            ({ motionDamping, motionStiffness }) => ({
                boundSpring: partialRight(spring, {
                    damping: motionDamping,
                    stiffness: motionStiffness,
                }),
            })
        )
    )
github plouc / nivo / packages / nivo-sunburst / src / Sunburst.js View on Github external
.outerRadius(d => Math.sqrt(d.y1))
            .cornerRadius(cornerRadius),
    })),
    withPropsOnChange(['identity'], ({ identity }) => ({
        getIdentity: getAccessorFor(identity),
    })),
    withPropsOnChange(['value'], ({ value }) => ({
        getValue: getAccessorFor(value),
    })),
    withPropsOnChange(['data', 'getValue'], ({ data, getValue }) => ({
        data: hierarchy(data).sum(getValue),
    })),
    withPropsOnChange(['childColor'], ({ childColor }) => ({
        getChildColor: getInheritedColorGenerator(childColor),
    })),
    withPropsOnChange(
        ['data', 'partition', 'getIdentity', 'getChildColor'],
        ({ data, partition, getIdentity, getColor, getChildColor }) => {
            const total = data.value

            const nodes = sortBy(partition(cloneDeep(data)).descendants(), 'depth')
            nodes.forEach(node => {
                const ancestor = getAncestor(node).data

                delete node.children
                delete node.data.children

                Object.assign(node.data, {
                    id: getIdentity(node.data),
                    value: node.value,
                    percentage: 100 * node.value / total,
                    depth: node.depth,
github guzmonne / nivo-with-brush / src / App / LineChart / LineChart.js View on Github external
onBrush: ({ update, invertScale, xRange, data }) => (minEdge, maxEdge) => {
      this.minEdge = indexOf(xRange, invertScale(minEdge));
      this.maxEdge = indexOf(xRange, invertScale(maxEdge));
      requestAnimationFrame(update);
    }
  }),
  withPropsOnChange(['innerWidth'], ({ innerWidth }) => ({
    maxPoints: Math.round(innerWidth / POINTS_PER_WIDTH)
  })),
  withPropsOnChange(['data', 'min', 'max'], ({ data, min, max }) => ({
    visibleData: data.map(d => ({
      ...d,
      ...{ data: d.data.slice(min, max) }
    }))
  })),
  withPropsOnChange(['visibleData'], ({ visibleData, maxPoints }) => ({
    drawData: visibleData.map(d => {
      if (d.data.length < maxPoints) return d;

      var filterEvery = Math.ceil(d.data.length / maxPoints);

      return {
        ...d,
        ...{ data: d.data.filter((_, i) => i % filterEvery === 0) }
      };
    })
  })),
  withPropsOnChange(['data'], ({ data, maxPoints }) => ({
    brushData: data.map(d => {
      if (d.data.length < maxPoints) return d;

      var filterEvery = Math.ceil(d.data.length / maxPoints);
github plouc / nivo / packages / nivo-sankey / src / SankeyNodesItem.js View on Github external
}

const enhance = compose(
    withPropsOnChange(['node', 'theme', 'tooltip'], ({ node, theme, tooltip }) => {
        if (tooltip) {
            return {
                tooltip: ,
            }
        }
        return {
            tooltip: (
                
            ),
        }
    }),
    withPropsOnChange(['onClick', 'node'], ({ onClick, node }) => ({
        onClick: event => onClick(node, event),
    })),
    withHandlers({
        handleMouseEnter: ({ showTooltip, setCurrent, node, tooltip }) => e => {
            setCurrent(node)
            showTooltip(tooltip, e)
        },
        handleMouseMove: ({ showTooltip, tooltip }) => e => {
            showTooltip(tooltip, e)
        },
        handleMouseLeave: ({ hideTooltip, setCurrent }) => () => {
            setCurrent(null)
            hideTooltip()
        },
    }),
    pure
github plouc / nivo / packages / nivo-sankey / src / enhance.js View on Github external
export default Component =>
    compose(
        defaultProps(SankeyDefaultProps),
        withState('currentNode', 'setCurrentNode', null),
        withState('currentLink', 'setCurrentLink', null),
        withColors(),
        withColors({
            colorByKey: 'linkColorBy',
            destKey: 'getLinkColor',
            defaultColorBy: 'source.id',
        }),
        withTheme(),
        withDimensions(),
        withMotion(),
        withPropsOnChange(['nodeBorderColor'], ({ nodeBorderColor }) => ({
            getNodeBorderColor: getInheritedColorGenerator(nodeBorderColor),
        })),
        withPropsOnChange(['labelTextColor'], ({ labelTextColor }) => ({
            getLabelTextColor: getInheritedColorGenerator(labelTextColor),
        })),
        withPropsOnChange(['label', 'labelFormat'], ({ label, labelFormat }) => ({
            getLabel: getLabelGenerator(label, labelFormat),
        })),
        pure
    )(Component)
github plouc / nivo / packages / nivo-stream / src / enhance.js View on Github external
export default Component =>
    compose(
        defaultProps(StreamDefaultProps),
        withTheme(),
        withCurve(),
        withDimensions(),
        withMotion(),
        withPropsOnChange(['curveInterpolator'], ({ curveInterpolator }) => ({
            areaGenerator: area()
                .x(({ x }) => x)
                .y0(({ y1 }) => y1)
                .y1(({ y2 }) => y2)
                .curve(curveInterpolator),
        })),
        withPropsOnChange(['colors'], ({ colors }) => ({
            getColor: getColorRange(colors),
        })),
        withPropsOnChange(['borderColor'], ({ borderColor }) => ({
            getBorderColor: getInheritedColorGenerator(borderColor),
        })),
        withPropsOnChange(['keys', 'offsetType', 'order'], ({ keys, offsetType, order }) => ({
            stack: d3Stack()
                .keys(keys)
                .offset(stackOffsetFromProp(offsetType))
github plouc / nivo / packages / bar / src / BarItem.js View on Github external
onMouseLeave: PropTypes.func,
    tooltip: PropTypes.element.isRequired,

    theme: PropTypes.shape({
        tooltip: PropTypes.shape({}).isRequired,
        labels: PropTypes.shape({
            text: PropTypes.object.isRequired,
        }).isRequired,
    }).isRequired,
}

const enhance = compose(
    withPropsOnChange(['data', 'color', 'onClick'], ({ data, color, onClick }) => ({
        onClick: event => onClick({ color, ...data }, event),
    })),
    withPropsOnChange(
        ['data', 'color', 'theme', 'tooltip', 'getTooltipLabel', 'tooltipFormat'],
        ({ data, color, theme, tooltip, getTooltipLabel, tooltipFormat }) => ({
            tooltip: (