Skip to content

Instantly share code, notes, and snippets.

@marc-rutkowski
Last active April 20, 2017 11:35
Show Gist options
  • Save marc-rutkowski/12c16f77f8b135cc42092be6bbdeb970 to your computer and use it in GitHub Desktop.
Save marc-rutkowski/12c16f77f8b135cc42092be6bbdeb970 to your computer and use it in GitHub Desktop.

Revisions

  1. marc-rutkowski revised this gist Apr 20, 2017. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion ImmutableType.js
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ const ImmutableType = (typeSpecs) => (props, propName, componentName) => { // es
    return new Error(`Prop ${propName} supplied to ${componentName} is not immutable.`);
    }
    const value = propValue.toJS();
    return PropTypes.checkPropTypes({ [propName]: typeSpecs }, { [propName]: value }, propName, componentName);
    PropTypes.checkPropTypes({ [propName]: typeSpecs }, { [propName]: value }, propName, componentName);
    };

    export default ImmutableType;
  2. marc-rutkowski created this gist Apr 20, 2017.
    20 changes: 20 additions & 0 deletions ImmutableType.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    /**
    * 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;