How to use the recompose.defaultProps 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 flow-typed / flow-typed / definitions / npm / recompose_v0.26.x / flow_v0.47.x-v0.52.x / test_defaultProps.js View on Github external
const Comp = ({ hello, eA }) =>
  <div>
    {(hello: string)}
    {(eA: number)}
    {
      // $ExpectError eA nor any nor string
      (eA: string)
    }
    {
      // $ExpectError hello nor any nor number
      (hello: number)
    }
  </div>;

const enhacer: HOC&lt;*, EnhancedCompProps&gt; = compose(
  defaultProps({
    hello: "world"
  }),
  withProps(props =&gt; ({
    hello: (props.hello: string),
    eA: (props.eA: number),
    // $ExpectError hello nor any nor number
    helloErr: (props.hello: number),
    // $ExpectError eA nor any nor string
    eAErr: (props.eA: string)
  })),
  withProps(props =&gt; ({
    // $ExpectError property not found
    err: props.iMNotExists
  }))
);
github geosolutions-it / MapStore2 / web / client / plugins / manager / EditorEnhancer.js View on Github external
return getStylesAndAttributes(layer, workspace).do(opts => optionsLoaded(opts))
                .catch(() => {
                    setLoading(false);
                    return Rx.Observable.of(onError({
                        title: "rulesmanager.errorTitle",
                        message: "rulesmanager.errorLoading"
                    }));
                }).do(() => setLoading(false));
        }).let(emitStop);
};

module.exports = compose(connect(() => ({}), {
    onChangeDrawingStatus: changeDrawingStatus,
    onError: error
}),
defaultProps({dataStreamFactory}),
withStateHandlers(({activeRule: initRule}) => ({
    activeRule: initRule,
    initRule,
    activeEditor: "1",
    styles: [],
    properties: []
}), {
    setOption: ({activeRule}) => ({key, value}) => {
        // Add some reference logic here
        if (key === "workspace") {
            const {layer, workspace, constraints, ...newActive} = activeRule;
            const l = !value ? {layer} : {};
            return {
                activeRule: { ...newActive, workspace: value, ...l},
                styles: [],
                properties: [],
github Uscreen-video / atomic-builder / app / Editor / creators / createEditor.js View on Github external
export default () =>
compose(
  editorState,
  // Create initial cursor,
  // Cursor must will be expanded in each level
  defaultProps({ Cursor }),

  // We allow to drag&drop organisms inside editor
  // Also we dont  fire commit of changes, because its own state
  dndState('organisms', 'data', false),

  withHandlers({
    updateEditorState: props => (key, state) => {
      const mutation = props.organisms.setIn(key, state);
      const templateShapeId = UUID.create().toString();
      window.templatesShape = JSON.stringify({
        ...mutation.toJS()[0],
        id: templateShapeId
      });
      props.update(mutation);
    }
  }),
github go-faast / faast-web / src / app / components / i18n / T.jsx View on Github external
import React from 'react'
import PropTypes from 'prop-types'
import { compose, setDisplayName, setPropTypes, defaultProps, getContext, mapProps } from 'recompose'
import { Trans } from 'react-i18next'

export default compose(
  setDisplayName('T'),
  setPropTypes({
    block: PropTypes.bool,
    tag: PropTypes.string || PropTypes.func,
    ...Trans.propTypes,
    i18nKey: PropTypes.string.isRequired,
    translate: PropTypes.bool,
  }),
  defaultProps({
    block: false,
    tag: 'span',
    translate: true,
  }),
  mapProps(({ block, parent, tag, ...rest }) => ({
    parent: block ? 'div' : (parent || tag),
    ...rest,
  })),
  getContext(Trans.contextTypes)
)((props) => {
  const { i18nKey, children, translate, } = props
  if (!translate) {
    return children
  }
  if (!(/^[\w.:]+$/).test(i18nKey)) {
    console.error(`Invalid i18nKey '${i18nKey}' provided to T for: ${children}`)
github go-faast / faast-web / src / app / components / WalletSelectField.jsx View on Github external
export default compose(
    setDisplayName('WalletSelectField'),
    connect(createStructuredSelector({
      connectedWallets: getAllWalletsArray,
    }), {
      push: pushAction
    }),
    setPropTypes({
      dropDownText: PropTypes.string,
      dropDownStyle: PropTypes.object,
      handleSelect: PropTypes.func,
      ERC20: PropTypes.bool,
      valid: PropTypes.bool,
    }),
    defaultProps({
      dropDownText: 'Select Wallet',
      dropDownStyle: {},
      handleSelect: () => {},
      ERC20: false,
      valid: true
    }),
    withStateHandlers(
      { dropdownOpen: false },
      { toggleDropDown: ({ dropdownOpen }) => () => ({ dropdownOpen: !dropdownOpen }) },
    ),
    withHandlers({
      handleConnect: ({ push }) => () => {
        push('/connect')
      }
    })
  )(WalletSelectField)
github go-faast / faast-web / src / app / components / ConfirmTransactionModal / index.jsx View on Github external
return TrezorBtcInstructions
  }
  if (walletType.includes('ethereum')) {
    if (wallet.typeLabel.toLowerCase().includes('metamask')) {
      return MetaMaskInstructions
    }
    return EthereumInstructions
  }
}

export default compose(
  setDisplayName('ConfirmTransactionModal'),
  setPropTypes({
    swap: PropTypes.object,
  }),
  defaultProps({
    swap: null,
  }),
  withProps(({ swap }) =&gt; {
    const InstructionComponent = swap &amp;&amp; getInstructionComponent(swap.tx, swap.sendWallet)
    return {
      InstructionComponent,
      isOpen: Boolean(swap &amp;&amp; InstructionComponent),
    }
  })
)(({ swap, InstructionComponent, handleCancel, isOpen }) =&gt; (
  
    
      Confirm Transaction
    
    
      {InstructionComponent &amp;&amp; (
github plouc / nivo / packages / geo / src / enhance.js View on Github external
export const enhanceGeoMap = Component => {
    if (Component.displayName === 'GeoMap') {
        return setDisplayName(Component.displayName)(
            compose(
                defaultProps(GeoMapDefaultProps),
                ...commonEnhancers,
                pure
            )(Component)
        )
    }

    if (Component.displayName === 'GeoMapCanvas') {
        return setDisplayName(Component.displayName)(
            compose(
                defaultProps(GeoMapCanvasDefaultProps),
                ...commonEnhancers,
                pure
            )(Component)
        )
    }
}
github go-faast / faast-web / src / site / components / Footer.jsx View on Github external
import classNames from 'class-names'
import PropTypes from 'prop-types'

import { betaTag } from './Header/style.scss'
import EmailSubscriptionForm from './EmailSubscriptionForm'
import LazyLoad from 'react-lazyload'

import LangLink from 'Components/LangLink'

export default compose(
  setDisplayName('Footer'),
  setPropTypes({
    footerClass: PropTypes.string,
    showEmail: PropTypes.bool
  }),
  defaultProps({
    footerClass: '',
    showEmail: true
  }),
)(({ showEmail, footerClass, translations: { static: { footer: t = {} } = {} } }) =&gt; (
  
    {showEmail &amp;&amp; (
      <div>
        
          
        
      </div>
    )}
    <div style="{{">
      <footer>
        <div style="{{">
          <div></div></div></footer></div>
github plouc / nivo / packages / geo / src / enhance.js View on Github external
export const enhanceChoropleth = Component => {
    const defaultComponentProps =
        Component.displayName === 'Choropleth'
            ? ChoroplethDefaultProps
            : ChoroplethCanvasDefaultProps

    return setDisplayName(Component.displayName)(
        compose(
            defaultProps(defaultComponentProps),
            withPropsOnChange(['colors', 'unknownColor'], ({ colors, unknownColor }) => {
                const colorScale = guessQuantizeColorScale(colors).domain([0, 1000000])

                return {
                    fillColor: feature => {
                        if (feature.value === undefined) return unknownColor
                        return colorScale(feature.value)
                    },
                }
            }),
            withPropsOnChange(
                ['features', 'data', 'matchOn', 'valueFrom', 'fillColor'],
                ({ features, data, matchOn, valueFrom, fillColor }) => {
                    let predicate
                    if (isFunction(matchOn)) {
                        predicate = matchOn
github geosolutions-it / MapStore2 / web / client / components / manager / rulesmanager / ruleseditor / attributeselectors / IpAddress.jsx View on Github external
value={selected}
                            placeholder={placeholder}
                            onChange={this.handleChange}
                        /&gt;
                    
                
            
        );
    }
    handleChange = (e) =&gt; {
        this.props.setOption({key: "ipaddress", value: e.target.value});
    }
}

module.exports = compose(
    defaultProps({
        placeholder: "rulesmanager.placeholders.ip"
    }),
    withLocalized(["placeholder"]))(IpAddress);