react-immutable-proptypes
Advanced tools
Comparing version 0.1.6 to 0.1.7
@@ -10,5 +10,2 @@ "use strict"; | ||
var Immutable; | ||
var ReactFragment; | ||
var ReactPropTypeLocations; | ||
var ReactTestUtils; | ||
@@ -27,3 +24,3 @@ var requiredMessage = "Required prop `testProp` was not specified in `testComponent`."; | ||
var error = declaration(props, "testProp", "testComponent", "prop"); | ||
expect(error).to.be(undefined); | ||
expect(error).not.to.be.ok(); | ||
} | ||
@@ -38,2 +35,50 @@ | ||
describe("Primitive Types", function () { | ||
it("should not warn for valid values", function () { | ||
typeCheckPass(PropTypes.list, new Immutable.List()); | ||
typeCheckPass(PropTypes.map, new Immutable.Map()); | ||
typeCheckPass(PropTypes.map, new Immutable.OrderedMap()); | ||
typeCheckPass(PropTypes.orderedMap, new Immutable.OrderedMap()); | ||
typeCheckPass(PropTypes.set, new Immutable.Set()); | ||
typeCheckPass(PropTypes.set, new Immutable.OrderedSet()); | ||
typeCheckPass(PropTypes.orderedSet, new Immutable.OrderedSet()); | ||
typeCheckPass(PropTypes.stack, new Immutable.Stack()); | ||
typeCheckPass(PropTypes.seq, new Immutable.Seq()); | ||
typeCheckPass(PropTypes.iterable, new Immutable.Iterable()); | ||
typeCheckPass(PropTypes.iterable, new Immutable.List()); | ||
typeCheckPass(PropTypes.iterable, new Immutable.Map()); | ||
typeCheckPass(PropTypes.iterable, new Immutable.OrderedMap()); | ||
typeCheckPass(PropTypes.iterable, new Immutable.Set()); | ||
typeCheckPass(PropTypes.iterable, new Immutable.OrderedSet()); | ||
typeCheckPass(PropTypes.iterable, new Immutable.Stack()); | ||
typeCheckPass(PropTypes.iterable, new Immutable.Seq()); | ||
}); | ||
it("should warn for invalid lists", function () { | ||
typeCheckFail(PropTypes.list, [], "Invalid prop `testProp` of type `array` supplied to " + "`testComponent`, expected `List`."); | ||
typeCheckFail(PropTypes.list, {}, "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected `List`."); | ||
typeCheckFail(PropTypes.list, "", "Invalid prop `testProp` of type `string` supplied to " + "`testComponent`, expected `List`."); | ||
typeCheckFail(PropTypes.list, false, "Invalid prop `testProp` of type `boolean` supplied to " + "`testComponent`, expected `List`."); | ||
typeCheckFail(PropTypes.list, 0, "Invalid prop `testProp` of type `number` supplied to " + "`testComponent`, expected `List`."); | ||
typeCheckFail(PropTypes.list, new Immutable.Map(), "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected `List`."); | ||
typeCheckFail(PropTypes.list, new Immutable.Iterable(), "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected `List`."); | ||
}); | ||
it("should warn for invalid maps", function () { | ||
typeCheckFail(PropTypes.map, [], "Invalid prop `testProp` of type `array` supplied to " + "`testComponent`, expected `Map`."); | ||
typeCheckFail(PropTypes.map, {}, "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected `Map`."); | ||
typeCheckFail(PropTypes.map, "", "Invalid prop `testProp` of type `string` supplied to " + "`testComponent`, expected `Map`."); | ||
typeCheckFail(PropTypes.map, false, "Invalid prop `testProp` of type `boolean` supplied to " + "`testComponent`, expected `Map`."); | ||
typeCheckFail(PropTypes.map, 0, "Invalid prop `testProp` of type `number` supplied to " + "`testComponent`, expected `Map`."); | ||
typeCheckFail(PropTypes.map, new Immutable.List(), "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected `Map`."); | ||
typeCheckFail(PropTypes.map, new Immutable.Iterable(), "Invalid prop `testProp` of type `object` supplied to " + "`testComponent`, expected `Map`."); | ||
}); | ||
it("should be implicitly optional and not warn without values", function () { | ||
typeCheckPass(PropTypes.list, null); | ||
typeCheckPass(PropTypes.list, undefined); | ||
}); | ||
it("should warn for missing required values", function () { | ||
typeCheckFail(PropTypes.list.isRequired, null, requiredMessage); | ||
typeCheckFail(PropTypes.list.isRequired, undefined, requiredMessage); | ||
}); | ||
}); | ||
describe("ListOf Type", function () { | ||
@@ -40,0 +85,0 @@ it("should support the listOf propTypes", function () { |
@@ -17,3 +17,12 @@ /** | ||
iterableOf: createIterableOfTypeChecker, | ||
shape: createShapeTypeChecker | ||
shape: createShapeTypeChecker, | ||
// Primitive Types | ||
list: createImmutableTypeChecker("List", Immutable.List.isList), | ||
map: createImmutableTypeChecker("Map", Immutable.Map.isMap), | ||
orderedMap: createImmutableTypeChecker("OrderedMap", Immutable.OrderedMap.isOrderedMap), | ||
set: createImmutableTypeChecker("Set", Immutable.Set.isSet), | ||
orderedSet: createImmutableTypeChecker("OrderedSet", Immutable.OrderedSet.isOrderedSet), | ||
stack: createImmutableTypeChecker("Stack", Immutable.Stack.isStack), | ||
seq: createImmutableTypeChecker("Seq", Immutable.Seq.isSeq), | ||
iterable: createImmutableTypeChecker("Iterable", Immutable.Iterable.isIterable) | ||
}; | ||
@@ -54,2 +63,14 @@ | ||
function createImmutableTypeChecker(immutableClassName, immutableClassTypeValidator) { | ||
function validate(props, propName, componentName, location) { | ||
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 null; | ||
} | ||
return createChainableTypeChecker(validate); | ||
} | ||
function createIterableTypeChecker(typeChecker, immutableClassName, immutableClassTypeValidator) { | ||
@@ -56,0 +77,0 @@ function validate(props, propName, componentName, location) { |
{ | ||
"name": "react-immutable-proptypes", | ||
"version": "0.1.6", | ||
"version": "0.1.7", | ||
"description": "PropType validators that work with Immutable.js.", | ||
@@ -10,3 +10,4 @@ "main": "dist/ImmutablePropTypes.js", | ||
"test-cov": "./scripts/test-cov", | ||
"prepublish": "npm run build" | ||
"prepublish": "npm run build", | ||
"lint": "./node_modules/.bin/eslint ./src" | ||
}, | ||
@@ -36,2 +37,5 @@ "repository": { | ||
"babel": "^4.6.6", | ||
"babel-eslint": "^3.1.1", | ||
"eslint": "^0.21.0", | ||
"eslint-plugin-react": "^2.2.0", | ||
"expect.js": "^0.3.1", | ||
@@ -38,0 +42,0 @@ "istanbul": "~0.3.7", |
@@ -8,5 +8,10 @@ # react-immutable-proptypes | ||
## Version Updates | ||
0.1.3 updated package.json to support React v0.11.0+ (including 0.13.1). Thanks [Andrey Okonetchnikov](https://github.com/okonet)! | ||
- 0.1.7 added convencience checkers for "primitive" immutable types (map, list, etc...) | ||
- 0.1.6 added `iterableOf` | ||
- 0.1.4 added `mapOf` | ||
- 0.1.3 updated package.json to support React v0.11.0+ (including 0.13.1). Thanks [Andrey Okonetchnikov](https://github.com/okonet)! | ||
Since v 0.1.6 the library seems like it covers just about everything that is needed. If this package continues to be as stable on our projects as it has been, there will probably be a bump to v 1.0 soon. | ||
## About | ||
@@ -31,3 +36,13 @@ | ||
Since version 0.1.7 there are convenience helpers for "primitive" Immutable.js objects. | ||
propTypes: { | ||
oldListTypeChecker: React.PropTypes.instanceOf(Immutable.List), | ||
anotherWay: ImmutablePropTypes.list, | ||
requiredList: ImmutablePropTypes.list.isRequired, | ||
mapsToo: ImmutablePropTypes.map, | ||
evenIterable: ImmutablePropTypes.iterable | ||
} | ||
## Installation | ||
@@ -42,4 +57,14 @@ | ||
React-Immutable-PropTypes has just two validators that cover 100% of my use cases, and probably 99% of everybody's use cases. | ||
React-Immutable-PropTypes has: | ||
* Primitive Types | ||
ImmutablePropTypes.list // Immutable.List.isList | ||
ImmutablePropTypes.map // Immutable.Map.isMap | ||
ImmutablePropTypes.orderedMap // Immutable.OrderedMap.isOrderedMap | ||
ImmutablePropTypes.set // Immutable.Set.isSet | ||
ImmutablePropTypes.orderedSet // Immutable.OrderedSet.isOrderedSet | ||
ImmutablePropTypes.stack // Immutable.Stack.isStack | ||
ImmutablePropTypes.seq // Immutable.Seq.isSeq | ||
ImmutablePropTypes.iterable // Immutable.Iterable.isIterable | ||
* `ImmutablePropTypes.listOf` is based on `React.PropTypes.array` and is specific to `Immutable.List`. | ||
@@ -46,0 +71,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
77649
24
748
92
7