How to use the recompose.getContext 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 Soluto / tweek / services / editor-new / src / components / common / Input / TypedInput.js View on Github external
import React from 'react';
import PropTypes from 'prop-types';
import { withContext, getContext } from 'recompose';
import changeCase from 'change-case';
import ComboBox from '../ComboBox/ComboBox';
import Input from './Input';

export const typesServiceContextType = {
  types: PropTypes.object.isRequired,
  safeConvertValue: PropTypes.func.isRequired,
};

export const withTypesService = ({ safeConvertValue, types }) =>
  withContext(typesServiceContextType, () => ({ safeConvertValue, types }));

const getTypesService = getContext(typesServiceContextType);

const valueToItem = value => (
  value === undefined || value === '' ?
    undefined :
    { label: changeCase.pascalCase(value), value }
);

const TypedInput = ({ safeConvertValue, types, valueType, value, onChange, ...props }) => {
  const typeDefinition = types[valueType];
  const allowedValues = typeDefinition && typeDefinition.allowedValues;
  const onChangeConvert = newValue => onChange && onChange(safeConvertValue(newValue, valueType));
  if (allowedValues && allowedValues.length > 0) {
    return (
github formio / react-formio / src / formioConnect.js View on Github external
export default function formioConnect(...args) {
  return compose(
    getContext({formio: PropTypes.object}),
    getContext({router: PropTypes.object}),
    connect(...args)
  );
}
github Soluto / tweek / services / editor / src / components / common / Input / ListTypedValue.js View on Github external
import React from 'react';
import PropTypes from 'prop-types';
import { compose, mapProps, getContext, withHandlers, withProps } from 'recompose';
import { WithContext as ReactTags } from 'react-tag-input';
import * as R from 'ramda';
import classes from 'classnames';

export const typesServiceContextType = {
  types: PropTypes.object.isRequired,
  safeConvertValue: PropTypes.func.isRequired,
  isAllowedValue: PropTypes.func.isRequired,
};

export const getTypesService = getContext(typesServiceContextType);

const convertToArray = (value) => (value && (Array.isArray(value) ? value : [value])) || [];

const toTags = (arr) => arr.map((x) => x.toString()).map((x) => ({ id: x, text: x }));

const enhance = compose(
  getTypesService,
  withProps(({ value }) => ({ value: convertToArray(value) })),
  withHandlers({
    handleAddition: ({ onChange, value, safeConvertValue, isAllowedValue, valueType }) => (
      newValue,
    ) => {
      const convertedVal = safeConvertValue(newValue.text, valueType);
      if (
        convertedVal !== undefined &&
        !value.includes(convertedVal) &&
github i-novus-llc / n2o-framework / frontend / n2o-framework / src / components / core / RootPage.jsx View on Github external
PropTypes.func,
    PropTypes.element,
    PropTypes.node,
  ]),
  rootPageId: PropTypes.string,
};

const mapStateToProps = createStructuredSelector({
  rootPageId: rootPageSelector,
});

export default compose(
  defaultProps({
    defaultTemplate: SimpleTemplate,
  }),
  getContext({
    defaultTemplate: PropTypes.oneOfType([
      PropTypes.func,
      PropTypes.element,
      PropTypes.node,
    ]),
  }),
  connect(mapStateToProps)
)(RootPage);
github olymp / olymp / external / fela / panorama.es6 View on Github external
}

  const query = Object.keys(newOptions)
    .map(key => `${key}_${newOptions[key]}`)
    .join(',');

  if (newUrl.indexOf('/upload/') !== -1) {
    return newUrl.replace('/upload/', `/upload/${crop}${query}/`);
  } else if (newUrl.indexOf('/fetch/') !== -1) {
    return newUrl.replace('/fetch/', `/fetch/${crop}${query}/`);
  }
};


const enhance = compose(
  getContext({
    amp: PropTypes.bool,
  }),
  withState('cWidth', 'setCWidth', undefined),
  withState('isLoaded', 'setIsLoaded', false),
  withState('responsiveSize', 'setResponsiveSize', {}),
  withPropsOnChange(['value', 'options', 'responsiveSize'], ({ value, options, responsiveSize }) => ({
    url: cloudinaryUrl(value, options, responsiveSize),
  })),
);

@enhance
class Image extends Component {
  componentDidMount() {
    this.node = ReactDOM.findDOMNode(this);
    if (this.node) {
      this.onResize(this.node.getBoundingClientRect());
github formio / react-formio / src / formioConnect.js View on Github external
export default function formioConnect(...args) {
  return compose(
    getContext({formio: PropTypes.object}),
    getContext({router: PropTypes.object}),
    connect(...args)
  );
}
github elastic / kibana / x-pack / plugins / canvas / public / components / workpad / index.js View on Github external
height,
    workpadCss,
    workpadId,
    isFullscreen: getFullscreen(state),
  };
};

const mapDispatchToProps = {
  undoHistory,
  redoHistory,
  fetchAllRenderables,
};

export const Workpad = compose(
  pure,
  getContext({
    router: PropTypes.object,
  }),
  withState('grid', 'setGrid', false),
  connect(
    mapStateToProps,
    mapDispatchToProps
  ),
  withState('transition', 'setTransition', null),
  withState('prevSelectedPageNumber', 'setPrevSelectedPageNumber', 0),
  withProps(({ selectedPageNumber, prevSelectedPageNumber, transition }) => {
    function getAnimation(pageNumber) {
      if (!transition || !transition.name) {
        return null;
      }
      if (![selectedPageNumber, prevSelectedPageNumber].includes(pageNumber)) {
        return null;
github psychobolt / react-pie-menu / src / PieMenu.component.js View on Github external
...getSlices(child, index + i),
      ];
      index = Math.max(0, slices.length - 1);
    });
    return { slices };
  }),
  withContext(propTypes, ({
    slices,
    radius = '150px',
    centerRadius = '50px',
  }: Context) => {
    const centralAngle = 360 / slices.length || 360;
    const polar = centralAngle % 180 === 0;
    return { radius, centerRadius, centralAngle, polar };
  }),
  getContext(propTypes),
);

const PieMenu = ({
  className,
  radius,
  centerRadius,
  centralAngle,
  startOffsetAngle = 0,
  polar,
  Center = PieCenter,
  slices,
  attrs = {},
}: Props) => {
  const deltaAngle = 90 - centralAngle;
  const startAngle = polar ? 45 : startOffsetAngle + deltaAngle + (centralAngle / 2);
  return (
github nmaro / ooth / packages / ooth-client-react / src / index.tsx View on Github external
user,
    };
  }

  private onUser = async (user: User) => {
    this.setState({
      user,
    });
  };
}

export const withOoth = getContext({
  oothClient: PropTypes.object.isRequired,
});

export const withUser = getContext({
  user: PropTypes.object,
});