Last active
April 20, 2017 11:35
-
-
Save marc-rutkowski/12c16f77f8b135cc42092be6bbdeb970 to your computer and use it in GitHub Desktop.
Revisions
-
marc-rutkowski revised this gist
Apr 20, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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(); PropTypes.checkPropTypes({ [propName]: typeSpecs }, { [propName]: value }, propName, componentName); }; export default ImmutableType; -
marc-rutkowski created this gist
Apr 20, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal 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;