Socket
Socket
Sign inDemoInstall

react-immutable-proptypes

Package Overview
Dependencies
1
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.5.0 to 1.5.1

8

CHANGELOG.md
## 1.5.0 improved warnings
- try to specify which Immutable data structure was provided instead of saying `object`.
## 1.4.0 added support for orderedSetOf and orderedMapOf
## 1.3.0 added support for record and recordOf type checkers.
## 1.4.0
- added support for orderedSetOf and orderedMapOf
## 1.3.0
- added support for record and recordOf type checkers.
## 1.2.x

@@ -7,0 +11,0 @@ - 1.2.3 [Nik Butenko](http://butenko.me/) provided a better .npmignore file

@@ -94,7 +94,9 @@ /**

}
if (typeof typeChecker !== "function") {
return new Error("Invalid typeChecker supplied to `" + componentName + "` " + ("for propType `" + propName + "`, expected a function."));
}
var propValues = propValue.toArray();
for (var i = 0, len = propValues.length; i < len; i++) {
if (typeof typeChecker !== "function") {
return new Error("Invalid typeChecker supplied to `" + componentName + "` " + ("for propType `" + propName + "`, expected a function."));
}
var error = typeChecker(propValues, i, componentName, location);

@@ -101,0 +103,0 @@ if (error instanceof Error) {

{
"name": "react-immutable-proptypes",
"version": "1.5.0",
"version": "1.5.1",
"description": "PropType validators that work with Immutable.js.",

@@ -5,0 +5,0 @@ "main": "dist/ImmutablePropTypes.js",

@@ -13,24 +13,28 @@ # react-immutable-proptypes

var ImmutablePropTypes = require('react-immutable-proptypes');
var MyReactComponent = React.createClass({
// ...
propTypes: {
```js
var ImmutablePropTypes = require('react-immutable-proptypes');
var MyReactComponent = React.createClass({
// ...
propTypes: {
myRequiredImmutableList: ImmutablePropTypes.listOf(
ImmutablePropTypes.contains({
someNumberProp: React.PropTypes.number.isRequired
})
ImmutablePropTypes.contains({
someNumberProp: React.PropTypes.number.isRequired
})
).isRequired
}
// ...
});
}
// ...
});
```
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
}
```js
propTypes: {
oldListTypeChecker: React.PropTypes.instanceOf(Immutable.List),
anotherWay: ImmutablePropTypes.list,
requiredList: ImmutablePropTypes.list.isRequired,
mapsToo: ImmutablePropTypes.map,
evenIterable: ImmutablePropTypes.iterable
}
```

@@ -41,6 +45,7 @@

Installing via [npmjs](https://www.npmjs.com/package/react-immutable-proptypes)
```bash
npm install --save react-immutable-proptypes
```
npm install --save react-immutable-proptypes
## API

@@ -50,13 +55,14 @@

* Primitive Types
```js
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.record // instanceof Record
```
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.record // instanceof Record
* `ImmutablePropTypes.listOf` is based on `React.PropTypes.array` and is specific to `Immutable.List`.

@@ -74,21 +80,25 @@

// ...
aRecord: ImmutablePropTypes.recordOf({
keyA: React.PropTypes.string,
keyB: ImmutablePropTypes.list.isRequired
})
// ...
```js
// ...
aRecord: ImmutablePropTypes.recordOf({
keyA: React.PropTypes.string,
keyB: ImmutablePropTypes.list.isRequired
})
// ...
```
* `ImmutablePropTypes.contains` (formerly `shape`) is based on `React.PropTypes.shape` and will try to work with any `Immutable.Iterable`. In practice, I would recommend limiting this to `Immutable.Map` or `Immutable.OrderedMap`. However, it is possible to abuse `contains` to validate an array via `Immutable.List`.
// ...
aList: ImmutablePropTypes.contains({
0: React.PropTypes.number.isRequired,
1: React.PropTypes.string.isRequired,
2: React.PropTypes.string
})
// ...
<SomeComponent aList={Immutable.List([1, '2'])} />
```es6
// ...
aList: ImmutablePropTypes.contains({
0: React.PropTypes.number.isRequired,
1: React.PropTypes.string.isRequired,
2: React.PropTypes.string
})
// ...
<SomeComponent aList={Immutable.List([1, '2'])} />
```
That said, don't do this. Please, just... don't.
That said, don't do this. Please, just... don't.

@@ -95,0 +105,0 @@ These two validators cover the output of `Immutable.fromJS` on standard JSON data sources.

@@ -99,10 +99,12 @@ /**

}
if (typeof typeChecker !== 'function') {
return new Error(
`Invalid typeChecker supplied to \`${componentName}\` ` +
`for propType \`${propName}\`, expected a function.`
);
}
var propValues = propValue.toArray();
for (var i = 0, len = propValues.length; i < len; i++) {
if (typeof typeChecker !== 'function') {
return new Error(
`Invalid typeChecker supplied to \`${componentName}\` ` +
`for propType \`${propName}\`, expected a function.`
);
}
var error = typeChecker(propValues, i, componentName, location);

@@ -109,0 +111,0 @@ if (error instanceof Error) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc