Skip to content
This repository was archived by the owner on Sep 28, 2023. It is now read-only.

Commit 2309dd3

Browse files
committed
Fix React PropTypes warning
1 parent f4f3105 commit 2309dd3

File tree

3 files changed

+53
-50
lines changed

3 files changed

+53
-50
lines changed

package.json

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"scripts": {
1212
"start": "webpack-dev-server --content-base examples/ --port 3000 --hot",
1313
"test": "./node_modules/karma/bin/karma start",
14-
"dist": "babel src --out-dir dist",
14+
"dist": "rm -rf dist && mkdir dist && babel src --out-dir dist",
1515
"dist/example": "webpack --dist",
1616
"prepublish": "npm run dist",
1717
"lint": "standard"
@@ -22,31 +22,31 @@
2222
},
2323
"author": "Adam Putinski",
2424
"dependencies": {
25-
"classnames": "^2.2.3",
25+
"classnames": "2.2.5",
2626
"rebound": "0.0.13"
2727
},
2828
"devDependencies": {
29-
"babel-cli": "^6.4.0",
30-
"babel-core": "^6.4.0",
31-
"babel-loader": "^6.2.1",
32-
"babel-preset-es2015": "^6.3.13",
33-
"babel-preset-react": "^6.3.13",
34-
"chai": "^3.4.1",
35-
"karma": "^0.13.19",
36-
"karma-chai": "^0.1.0",
37-
"karma-chrome-launcher": "^0.2.2",
38-
"karma-mocha": "^0.2.1",
39-
"karma-spec-reporter": "0.0.23",
40-
"karma-webpack": "^1.7.0",
41-
"minimist": "^1.2.0",
42-
"mocha": "^2.3.4",
43-
"react": "^0.14.6",
44-
"react-addons-test-utils": "^0.14.6",
45-
"react-dom": "^0.14.6",
46-
"sinon": "^1.17.2",
47-
"standard": "^8.0.0-beta.5",
48-
"webpack": "^1.12.11",
49-
"webpack-dev-server": "^1.14.1"
29+
"babel-cli": "6.11.4",
30+
"babel-core": "6.13.2",
31+
"babel-loader": "6.2.5",
32+
"babel-preset-es2015": "6.13.2",
33+
"babel-preset-react": "6.11.1",
34+
"chai": "3.5.0",
35+
"karma": "1.2.0",
36+
"karma-chai": "0.1.0",
37+
"karma-chrome-launcher": "2.0.0",
38+
"karma-mocha": "1.1.1",
39+
"karma-spec-reporter": "0.0.26",
40+
"karma-webpack": "1.8.0",
41+
"minimist": "1.2.0",
42+
"mocha": "3.0.2",
43+
"react": "15.3.1",
44+
"react": "15.3.1",
45+
"react": "15.3.1",
46+
"sinon": "1.17.5",
47+
"standard": "8.0.0-beta.5",
48+
"webpack": "1.13.2",
49+
"webpack-dev-server": "1.14.1"
5050
},
5151
"standard": {
5252
"ignore": [

spec/navigation-controller.spec.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* global describe, it, beforeEach, expect, requestAnimationFrame, sinon */
22

3-
import React from 'react/addons'
3+
import React from 'react'
44

55
import {
66
isCompositeComponent,

src/navigation-controller.jsx

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,39 +19,42 @@ const {
1919
mapValueInRange
2020
} = rebound.MathUtil
2121

22+
const isNumber = (value) =>
23+
typeof value === 'number'
24+
const isFunction = (value) =>
25+
typeof value === 'function'
26+
const isBool = (value) =>
27+
value === true || value === false
28+
const isArray = (value) =>
29+
Array.isArray(value)
30+
31+
const validate = (validator) => (options, key, method) => {
32+
if (!validator(options[key])) {
33+
throw new Error(`Option "${key}" of method "${method}" was invalid`)
34+
}
35+
}
36+
2237
const optionTypes = {
2338
pushView: {
24-
view: React.PropTypes.element.isRequired,
25-
transition: React.PropTypes.oneOfType([
26-
React.PropTypes.func,
27-
React.PropTypes.number
28-
]),
29-
onComplete: React.PropTypes.func
39+
view: validate(React.isValidElement),
40+
transition: validate(x => isFunction(x) || isNumber(x)),
41+
onComplete: validate(isFunction)
3042
},
3143
popView: {
32-
transition: React.PropTypes.oneOfType([
33-
React.PropTypes.func,
34-
React.PropTypes.number
35-
]),
36-
onComplete: React.PropTypes.func
44+
transition: validate(x => isFunction(x) || isNumber(x)),
45+
onComplete: validate(isFunction)
3746
},
3847
popToRootView: {
39-
transition: React.PropTypes.oneOfType([
40-
React.PropTypes.func,
41-
React.PropTypes.number
42-
]),
43-
onComplete: React.PropTypes.func
48+
transition: validate(x => isFunction(x) || isNumber(x)),
49+
onComplete: validate(isFunction)
4450
},
4551
setViews: {
46-
views: React.PropTypes.arrayOf(
47-
React.PropTypes.element
48-
).isRequired,
49-
preserveState: React.PropTypes.bool,
50-
transition: React.PropTypes.oneOfType([
51-
React.PropTypes.func,
52-
React.PropTypes.number
53-
]),
54-
onComplete: React.PropTypes.func
52+
views: validate(x => isArray(x) && x.reduce((valid, e) => {
53+
return valid === false ? false : React.isValidElement(e)
54+
}, true) === true),
55+
preserveState: validate(isBool),
56+
transition: validate(x => isFunction(x) || isNumber(x)),
57+
onComplete: validate(isFunction)
5558
}
5659
}
5760

@@ -65,7 +68,7 @@ function checkOptions (method, options) {
6568
const optionType = optionTypes[method]
6669
Object.keys(options).forEach(key => {
6770
if (optionType[key]) {
68-
const e = optionType[key](options, key, method, 'prop')
71+
const e = optionType[key](options, key, method)
6972
if (e) throw e
7073
}
7174
})

0 commit comments

Comments
 (0)