├── .babelrc ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── dist └── index.js ├── docs ├── README.md ├── SUMMARY.md └── book.json ├── package.json ├── src └── index.js └── test └── index.js /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["es2015-loose", "stage-0", "react"], 3 | "plugins": [ 4 | "transform-runtime", 5 | "add-module-exports" 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | build 3 | lib-cov 4 | *.seed 5 | *.log 6 | *.csv 7 | *.dat 8 | *.out 9 | *.pid 10 | *.gz 11 | _book 12 | 13 | pids 14 | logs 15 | results 16 | 17 | npm-debug.log 18 | node_modules 19 | *.sublime* 20 | *.node 21 | coverage 22 | *.orig 23 | .idea 24 | sandbox 25 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - "4" 4 | env: 5 | - CXX=g++-4.8 6 | addons: 7 | apt: 8 | sources: 9 | - ubuntu-toolchain-r-test 10 | packages: 11 | - g++-4.8 12 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Change Log 2 | 3 | ### upcoming (2016/01/25 00:39 +00:00) 4 | - [#8](https://github.com/contra/immutable-props/pull/8) Add Cursor (@axelhzf) 5 | - [dbbab68](https://github.com/contra/immutable-props/commit/dbbab68ce06bfcd222f3b11e3a6674e864287468) add cursor (@axelhzf) 6 | - [#3](https://github.com/contra/immutable-props/pull/3) fix emoji (@stevemao) 7 | - [#2](https://github.com/contra/immutable-props/pull/2) any version means any version (@stevemao) 8 | - [b7bf7b3](https://github.com/contra/immutable-props/commit/b7bf7b38851c12fff4982b10bd85302626341ca6) fix emoji (@stevemao) 9 | - [739073f](https://github.com/contra/immutable-props/commit/739073f0fbb1243dc87849c0076d855e47b07688) any version means any version (@stevemao) 10 | - [#1](https://github.com/contra/immutable-props/pull/1) Fix code style in README (@cht8687) 11 | - [7c96dc2](https://github.com/contra/immutable-props/commit/7c96dc215490b19090b7d53a72a099050403cb3b) Fix code style in README (@cht8687) 12 | - [46a497c](https://github.com/contra/immutable-props/commit/46a497c8cbb3ec242ce72693f9d29fcdf83e6e90) fix travis (@contra) 13 | - [ba9d72a](https://github.com/contra/immutable-props/commit/ba9d72ade312852bae3ebb88aadae1d491b05abe) sync docs (@contra) 14 | - [00d8e12](https://github.com/contra/immutable-props/commit/00d8e12eb22230d8789bc2fc006a56493146f36f) init (@contra) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 Contra 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # immutable-props [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] 2 | 3 | ## Information 4 | 5 | - This provides [React PropTypes](https://facebook.github.io/react/docs/reusable-components.html) for Immutable.js data. 6 | - This is the equivalent of `React.PropTypes.instanceOf(Immutable.Type)` so you can do all the normal stuff 7 | - `.isRequired`, nest in `.oneOfType`, etc. 8 | - React and Immutable are peer dependencies, so this will not install those for you. 9 | - This module works with any version of React and Immutable you have installed! :beer: 10 | 11 | ## Install 12 | 13 | ``` 14 | npm install immutable-props --save 15 | ``` 16 | 17 | ## Available Types 18 | 19 | - Iterable 20 | - Seq 21 | - Collection 22 | - Map 23 | - OrderedMap 24 | - List 25 | - Stack 26 | - Set 27 | - OrderedSet 28 | - Record 29 | - Range 30 | - Repeat 31 | - Cursor 32 | 33 | ## Example 34 | 35 | ### ES5 36 | 37 | ```js 38 | var IPropTypes = require('immutable-props'); 39 | 40 | var UserPage = React.createClass({ 41 | propTypes: { 42 | user: IPropTypes.Map, 43 | friends: IPropTypes.List 44 | }, 45 | render: function() { 46 | // ... 47 | } 48 | }); 49 | ``` 50 | 51 | ### ES6 52 | 53 | ```js 54 | import IPropTypes from 'immutable-props' 55 | 56 | class UserPage extends React.Component { 57 | static propTypes = { 58 | user: IPropTypes.Map, 59 | friends: IPropTypes.List 60 | }; 61 | 62 | render () { 63 | // ... 64 | } 65 | } 66 | ``` 67 | 68 | ### ES6 (with destructuring) 69 | 70 | ```js 71 | import { Map, List } from 'immutable-props' 72 | 73 | class UserPage extends React.Component { 74 | static propTypes = { 75 | user: Map, 76 | friends: List 77 | }; 78 | 79 | render () { 80 | // ... 81 | } 82 | } 83 | ``` 84 | 85 | [downloads-image]: http://img.shields.io/npm/dm/immutable-props.svg 86 | [npm-url]: https://npmjs.org/package/immutable-props 87 | [npm-image]: http://img.shields.io/npm/v/immutable-props.svg 88 | 89 | [travis-url]: https://travis-ci.org/contra/immutable-props 90 | [travis-image]: https://travis-ci.org/contra/immutable-props.png?branch=master 91 | -------------------------------------------------------------------------------- /dist/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | exports.__esModule = true; 4 | 5 | var _react = require('react'); 6 | 7 | var _immutable = require('immutable'); 8 | 9 | var _immutable2 = _interopRequireDefault(_immutable); 10 | 11 | var _cursor = require('immutable/contrib/cursor'); 12 | 13 | var _cursor2 = _interopRequireDefault(_cursor); 14 | 15 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 16 | 17 | var types = ['Iterable', 'Seq', 'Collection', 'Map', 'OrderedMap', 'List', 'Stack', 'Set', 'OrderedSet', 'Record', 'Range', 'Repeat']; 18 | 19 | var props = types.reduce(function (p, i) { 20 | p[i] = _react.PropTypes.instanceOf(_immutable2.default[i]); 21 | return p; 22 | }, {}); 23 | 24 | props.Cursor = _react.PropTypes.instanceOf(_cursor2.default); 25 | 26 | exports.default = props; 27 | module.exports = exports['default']; -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # immutable-props [![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] 2 | 3 | ## Information 4 | 5 | - This provides [React PropTypes](https://facebook.github.io/react/docs/reusable-components.html) for Immutable.js data. 6 | - This is the equivalent of `React.PropTypes.instanceOf(Immutable.Type)` so you can do all the normal stuff 7 | - `.isRequired`, nest in `.oneOfType`, etc. 8 | - React and Immutable are peer dependencies, so this will not install those for you. 9 | - This module works with any version of React and Immutable you have installed! 🍾 10 | 11 | ## Install 12 | 13 | ``` 14 | npm install immutable-props --save 15 | ``` 16 | 17 | ## Available Types 18 | 19 | - Iterable 20 | - Seq 21 | - Collection 22 | - Map 23 | - OrderedMap 24 | - List 25 | - Stack 26 | - Set 27 | - OrderedSet 28 | - Record 29 | - Range 30 | - Repeat 31 | 32 | ## Example 33 | 34 | ### ES5 35 | 36 | ```js 37 | var IPropTypes = require('immutable-props'); 38 | 39 | var UserPage = React.createClass({ 40 | propTypes: { 41 | user: IPropTypes.Map, 42 | friends: IPropTypes.List 43 | }, 44 | render: function() { 45 | // ... 46 | } 47 | }); 48 | ``` 49 | 50 | ### ES6 51 | 52 | ```js 53 | import IPropTypes from 'immutable-props' 54 | 55 | class UserPage extends React.Component { 56 | static propTypes = { 57 | user: IPropTypes.Map, 58 | friends: IPropTypes.List 59 | }; 60 | 61 | render () { 62 | // ... 63 | } 64 | } 65 | ``` 66 | 67 | ### ES6 (with destructuring) 68 | 69 | ```js 70 | import {Map, List} from 'immutable-props' 71 | 72 | class UserPage extends React.Component { 73 | static propTypes = { 74 | user: Map, 75 | friends: List 76 | }; 77 | 78 | render () { 79 | // ... 80 | } 81 | } 82 | ``` 83 | 84 | [downloads-image]: http://img.shields.io/npm/dm/immutable-props.svg 85 | [npm-url]: https://npmjs.org/package/immutable-props 86 | [npm-image]: http://img.shields.io/npm/v/immutable-props.svg 87 | 88 | [travis-url]: https://travis-ci.org/contra/immutable-props 89 | [travis-image]: https://travis-ci.org/contra/immutable-props.png?branch=master 90 | -------------------------------------------------------------------------------- /docs/SUMMARY.md: -------------------------------------------------------------------------------- 1 | * [README.md](README.md) 2 | -------------------------------------------------------------------------------- /docs/book.json: -------------------------------------------------------------------------------- 1 | { 2 | "gitbook": "2.x.x", 3 | "title": "immutable-props", 4 | "description": "React PropTypes for Immutable.js", 5 | "plugins": [ 6 | "edit-link", 7 | "prism", 8 | "-highlight", 9 | "github", 10 | "anchors", 11 | "collapsible-menu" 12 | ], 13 | "pluginsConfig": { 14 | "edit-link": { 15 | "base": "https://github.com/contra/immutable-props/tree/master", 16 | "label": "Edit This Page" 17 | }, 18 | "github": { 19 | "url": "https://github.com/contra/immutable-props/" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "immutable-props", 3 | "version": "1.1.0", 4 | "description": "React PropTypes for Immutable.js", 5 | "main": "dist/index.js", 6 | "keywords": [ 7 | "immutable", 8 | "proptypes", 9 | "proptype", 10 | "prop type", 11 | "react", 12 | "props", 13 | "immutablejs", 14 | "immutable.js", 15 | "validation" 16 | ], 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/contra/immutable-props.git" 20 | }, 21 | "author": "Contra (http://contra.io)", 22 | "license": "MIT", 23 | "bugs": { 24 | "url": "https://github.com/contra/immutable-props/issues" 25 | }, 26 | "homepage": "https://github.com/contra/immutable-props#readme", 27 | "files": [ 28 | "dist" 29 | ], 30 | "scripts": { 31 | "preversion": "npm run clean && npm run build && npm docs", 32 | "postpublish": "npm run changelog", 33 | "build": "babel src --out-dir dist", 34 | "clean": "rimraf dist", 35 | "lint": "eslint src", 36 | "changelog": "github-changes -o contra -r immutable-props -b master -f ./CHANGELOG.md --order-semver --use-commit-body", 37 | "test": "npm run-script lint && npm run test:node && npm run test:browser", 38 | "test:node": "mocha --compilers js:babel-register --recursive --reporter spec", 39 | "test:browser": "mochify --transform babelify --recursive --reporter spec", 40 | "docs": "npm run docs:pre && npm run docs:build && npm run docs:publish", 41 | "docs:pre": "gitbook install && rimraf _book", 42 | "docs:build": "gitbook build -g contra/immutable-props", 43 | "docs:publish": "cd _book && git init && git commit --allow-empty -m 'update book' && git checkout -b gh-pages && touch .nojekyll && git add . && git commit -am 'update book' && git push git@github.com:contra/immutable-props gh-pages --force" 44 | }, 45 | "peerDependencies": { 46 | "immutable": "*", 47 | "react": "*" 48 | }, 49 | "devDependencies": { 50 | "babel": "^6.3.26", 51 | "babel-cli": "^6.4.0", 52 | "babel-core": "^6.4.0", 53 | "babel-eslint": "^4.1.6", 54 | "babel-loader": "^6.2.1", 55 | "babel-plugin-add-module-exports": "^0.1.2", 56 | "babel-plugin-transform-runtime": "^6.4.3", 57 | "babel-preset-es2015": "^6.3.13", 58 | "babel-preset-es2015-loose": "^7.0.0", 59 | "babel-preset-react": "^6.3.13", 60 | "babel-preset-stage-0": "^6.3.13", 61 | "babel-register": "^6.4.3", 62 | "babelify": "^7.2.0", 63 | "eslint": "^1.10.3", 64 | "eslint-config-rackt": "^1.1.1", 65 | "eslint-plugin-react": "^3.15.0", 66 | "gitbook-cli": "^1.0.1", 67 | "github-changes": "^1.0.1", 68 | "immutable": "^3.7.6", 69 | "mocha": "^2.3.4", 70 | "mochify": "dylanfm/mochify.js", 71 | "react": "^0.14.0", 72 | "rimraf": "^2.5.0", 73 | "should": "^8.0.0" 74 | }, 75 | "eslintConfig": { 76 | "parser": "babel-eslint", 77 | "env": { 78 | "browser": true, 79 | "node": true, 80 | "es6": true 81 | }, 82 | "ecmaFeatures": { 83 | "modules": true 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import {PropTypes} from 'react' 2 | import Immutable from 'immutable' 3 | import Cursor from 'immutable/contrib/cursor' 4 | 5 | const types = [ 6 | 'Iterable', 7 | 'Seq', 8 | 'Collection', 9 | 'Map', 10 | 'OrderedMap', 11 | 'List', 12 | 'Stack', 13 | 'Set', 14 | 'OrderedSet', 15 | 'Record', 16 | 'Range', 17 | 'Repeat' 18 | ] 19 | 20 | var props = types.reduce((p, i) => { 21 | p[i] = PropTypes.instanceOf(Immutable[i]) 22 | return p 23 | }, {}) 24 | 25 | props.Cursor = PropTypes.instanceOf(Cursor) 26 | 27 | export default props -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | import should from 'should' 4 | import lib from '../src' 5 | 6 | var types = [ 7 | 'Iterable', 8 | 'Seq', 9 | 'Collection', 10 | 'Map', 11 | 'OrderedMap', 12 | 'List', 13 | 'Stack', 14 | 'Set', 15 | 'OrderedSet', 16 | 'Record', 17 | 'Range', 18 | 'Repeat', 19 | 'Cursor' 20 | ] 21 | 22 | describe('immutable-props', () => { 23 | types.forEach((k) => { 24 | it(`should export ${k} as a valid PropType`, () => { 25 | should.exist(lib[k]) 26 | }) 27 | }) 28 | }) 29 | --------------------------------------------------------------------------------