/** * Custom PropTypes validator for Immutable JS data * * This helper performs the following operations * 1. Check that prop is immutable * 2. Convert value toJS() then check it against the prop type specs. */ import PropTypes from 'prop-types'; import { isImmutable } from 'immutable'; const ImmutableType = (typeSpecs) => (props, propName, componentName) => { // eslint-disable-line consistent-return const propValue = props[propName]; if (!isImmutable(propValue)) { return new Error(`Prop ${propName} supplied to ${componentName} is not immutable.`); } const value = propValue.toJS(); return PropTypes.checkPropTypes({ [propName]: typeSpecs }, { [propName]: value }, propName, componentName); }; export default ImmutableType;