react-immutable-proptypes
Advanced tools
Comparing version 1.7.0 to 1.7.1
@@ -0,1 +1,4 @@ | ||
## 1.7.1 added better warnings | ||
- thanks to [Monday Chen](https://github.com/mondaychen) for adding this new feature. | ||
## 1.7.0 added mapContains type checker | ||
@@ -2,0 +5,0 @@ - thanks to [Brian Emil Hartz](https://github.com/hartzis) for adding this long requested feature. |
@@ -57,3 +57,4 @@ /** | ||
function createChainableTypeChecker(validate) { | ||
function checkType(isRequired, props, propName, componentName, location) { | ||
function checkType(isRequired, props, propName, componentName, location, propFullName) { | ||
propFullName = propFullName || propName; | ||
componentName = componentName || ANONYMOUS; | ||
@@ -63,6 +64,6 @@ if (props[propName] == null) { | ||
if (isRequired) { | ||
return new Error("Required " + locationName + " `" + propName + "` was not specified in " + ("`" + componentName + "`.")); | ||
return new Error("Required " + locationName + " `" + propFullName + "` was not specified in " + ("`" + componentName + "`.")); | ||
} | ||
} else { | ||
return validate(props, propName, componentName, location); | ||
return validate(props, propName, componentName, location, propFullName); | ||
} | ||
@@ -78,7 +79,7 @@ } | ||
function createImmutableTypeChecker(immutableClassName, immutableClassTypeValidator) { | ||
function validate(props, propName, componentName, location) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
if (!immutableClassTypeValidator(propValue)) { | ||
var propType = getPropType(propValue); | ||
return new Error("Invalid " + location + " `" + propName + "` of type `" + propType + "` " + ("supplied to `" + componentName + "`, expected `" + immutableClassName + "`.")); | ||
return new Error("Invalid " + location + " `" + propFullName + "` of type `" + propType + "` " + ("supplied to `" + componentName + "`, expected `" + immutableClassName + "`.")); | ||
} | ||
@@ -92,3 +93,3 @@ return null; | ||
function validate(props, propName, componentName, location) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
@@ -98,7 +99,7 @@ if (!immutableClassTypeValidator(propValue)) { | ||
var propType = getPropType(propValue); | ||
return new Error("Invalid " + locationName + " `" + propName + "` of type " + ("`" + propType + "` supplied to `" + componentName + "`, expected an Immutable.js " + immutableClassName + ".")); | ||
return new Error("Invalid " + locationName + " `" + propFullName + "` of type " + ("`" + propType + "` supplied to `" + componentName + "`, expected an Immutable.js " + immutableClassName + ".")); | ||
} | ||
if (typeof typeChecker !== "function") { | ||
return new Error("Invalid typeChecker supplied to `" + componentName + "` " + ("for propType `" + propName + "`, expected a function.")); | ||
return new Error("Invalid typeChecker supplied to `" + componentName + "` " + ("for propType `" + propFullName + "`, expected a function.")); | ||
} | ||
@@ -108,3 +109,3 @@ | ||
for (var i = 0, len = propValues.length; i < len; i++) { | ||
var error = typeChecker(propValues, i, componentName, location); | ||
var error = typeChecker(propValues, i, componentName, location, "" + propFullName + "[" + i + "]"); | ||
if (error instanceof Error) { | ||
@@ -147,3 +148,3 @@ return error; | ||
function createRecordOfTypeChecker(recordKeys) { | ||
function validate(props, propName, componentName, location) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
@@ -153,3 +154,3 @@ var propType = getPropType(propValue); | ||
var locationName = location; | ||
return new Error("Invalid " + locationName + " `" + propName + "` of type `" + propType + "` " + ("supplied to `" + componentName + "`, expected an Immutable.js Record.")); | ||
return new Error("Invalid " + locationName + " `" + propFullName + "` of type `" + propType + "` " + ("supplied to `" + componentName + "`, expected an Immutable.js Record.")); | ||
} | ||
@@ -162,3 +163,3 @@ for (var key in recordKeys) { | ||
var mutablePropValue = propValue.toObject(); | ||
var error = checker(mutablePropValue, key, componentName, location); | ||
var error = checker(mutablePropValue, key, componentName, location, "" + propFullName + "." + key); | ||
if (error) { | ||
@@ -177,3 +178,3 @@ return error; | ||
function validate(props, propName, componentName, location) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
@@ -183,3 +184,3 @@ var propType = getPropType(propValue); | ||
var locationName = location; | ||
return new Error("Invalid " + locationName + " `" + propName + "` of type `" + propType + "` " + ("supplied to `" + componentName + "`, expected an Immutable.js " + immutableClassName + ".")); | ||
return new Error("Invalid " + locationName + " `" + propFullName + "` of type `" + propType + "` " + ("supplied to `" + componentName + "`, expected an Immutable.js " + immutableClassName + ".")); | ||
} | ||
@@ -192,3 +193,3 @@ var mutablePropValue = propValue.toObject(); | ||
} | ||
var error = checker(mutablePropValue, key, componentName, location); | ||
var error = checker(mutablePropValue, key, componentName, location, "" + propFullName + "." + key); | ||
if (error) { | ||
@@ -195,0 +196,0 @@ return error; |
{ | ||
"name": "react-immutable-proptypes", | ||
"version": "1.7.0", | ||
"version": "1.7.1", | ||
"description": "PropType validators that work with Immutable.js.", | ||
@@ -5,0 +5,0 @@ "main": "dist/ImmutablePropTypes.js", |
@@ -53,3 +53,4 @@ /** | ||
function createChainableTypeChecker(validate) { | ||
function checkType(isRequired, props, propName, componentName, location) { | ||
function checkType(isRequired, props, propName, componentName, location, propFullName) { | ||
propFullName = propFullName || propName; | ||
componentName = componentName || ANONYMOUS; | ||
@@ -60,3 +61,3 @@ if (props[propName] == null) { | ||
return new Error( | ||
`Required ${locationName} \`${propName}\` was not specified in ` + | ||
`Required ${locationName} \`${propFullName}\` was not specified in ` + | ||
`\`${componentName}\`.` | ||
@@ -66,3 +67,3 @@ ); | ||
} else { | ||
return validate(props, propName, componentName, location); | ||
return validate(props, propName, componentName, location, propFullName); | ||
} | ||
@@ -78,3 +79,3 @@ } | ||
function createImmutableTypeChecker(immutableClassName, immutableClassTypeValidator) { | ||
function validate(props, propName, componentName, location) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
@@ -84,3 +85,3 @@ if(!immutableClassTypeValidator(propValue)) { | ||
return new Error( | ||
`Invalid ${location} \`${propName}\` of type \`${propType}\` ` + | ||
`Invalid ${location} \`${propFullName}\` of type \`${propType}\` ` + | ||
`supplied to \`${componentName}\`, expected \`${immutableClassName}\`.` | ||
@@ -96,3 +97,3 @@ ); | ||
function validate(props, propName, componentName, location) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
@@ -103,3 +104,3 @@ if (!immutableClassTypeValidator(propValue)) { | ||
return new Error( | ||
`Invalid ${locationName} \`${propName}\` of type ` + | ||
`Invalid ${locationName} \`${propFullName}\` of type ` + | ||
`\`${propType}\` supplied to \`${componentName}\`, expected an Immutable.js ${immutableClassName}.` | ||
@@ -112,3 +113,3 @@ ); | ||
`Invalid typeChecker supplied to \`${componentName}\` ` + | ||
`for propType \`${propName}\`, expected a function.` | ||
`for propType \`${propFullName}\`, expected a function.` | ||
); | ||
@@ -119,3 +120,3 @@ } | ||
for (var i = 0, len = propValues.length; i < len; i++) { | ||
var error = typeChecker(propValues, i, componentName, location); | ||
var error = typeChecker(propValues, i, componentName, location, `${propFullName}[${i}]`); | ||
if (error instanceof Error) { | ||
@@ -158,3 +159,3 @@ return error; | ||
function createRecordOfTypeChecker(recordKeys) { | ||
function validate(props, propName, componentName, location) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
@@ -165,3 +166,3 @@ var propType = getPropType(propValue); | ||
return new Error( | ||
`Invalid ${locationName} \`${propName}\` of type \`${propType}\` ` + | ||
`Invalid ${locationName} \`${propFullName}\` of type \`${propType}\` ` + | ||
`supplied to \`${componentName}\`, expected an Immutable.js Record.` | ||
@@ -176,3 +177,3 @@ ); | ||
var mutablePropValue = propValue.toObject(); | ||
var error = checker(mutablePropValue, key, componentName, location); | ||
var error = checker(mutablePropValue, key, componentName, location, `${propFullName}.${key}`); | ||
if (error) { | ||
@@ -188,3 +189,3 @@ return error; | ||
function createShapeTypeChecker(shapeTypes, immutableClassName = 'Iterable', immutableClassTypeValidator = Immutable.Iterable.isIterable) { | ||
function validate(props, propName, componentName, location) { | ||
function validate(props, propName, componentName, location, propFullName) { | ||
var propValue = props[propName]; | ||
@@ -195,3 +196,3 @@ var propType = getPropType(propValue); | ||
return new Error( | ||
`Invalid ${locationName} \`${propName}\` of type \`${propType}\` ` + | ||
`Invalid ${locationName} \`${propFullName}\` of type \`${propType}\` ` + | ||
`supplied to \`${componentName}\`, expected an Immutable.js ${immutableClassName}.` | ||
@@ -206,3 +207,3 @@ ); | ||
} | ||
var error = checker(mutablePropValue, key, componentName, location); | ||
var error = checker(mutablePropValue, key, componentName, location, `${propFullName}.${key}`); | ||
if (error) { | ||
@@ -209,0 +210,0 @@ return error; |
25213
360