Skip to content

Commit 3e69c14

Browse files
committed
React 0.12 & 0.13 support added
1 parent 40646d5 commit 3e69c14

File tree

4 files changed

+14
-25
lines changed

4 files changed

+14
-25
lines changed

bower.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-if-comp",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"homepage": "https://github.com/gfdev/javascript-react-if-component",
55
"authors": [
66
"Gordon Freeman <eax@gmx.us> (https://github.com/gfdev)"
@@ -18,6 +18,6 @@
1818
"license": "MIT",
1919
"devDependencies": {},
2020
"dependencies": {
21-
"react": "~0.14.0"
21+
"react": ">=0.12.0"
2222
}
2323
}

package.json

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-if-comp",
3-
"version": "0.0.3",
3+
"version": "0.0.4",
44
"description": "React component for conditional rendering of embedded elements or props",
55
"main": "index.js",
66
"keywords": [
@@ -29,30 +29,15 @@
2929
},
3030
"license": "MIT",
3131
"devDependencies": {
32-
"autoprefixer-loader": "^3.1.0",
3332
"babel-core": "^6.3.26",
34-
"babel-eslint": "^5.0.0-beta6",
35-
"babel-loader": "^6.2.0",
3633
"babel-plugin-transform-strict-mode": "^6.3.13",
3734
"babel-preset-react": "^6.3.13",
3835
"babel-preset-stage-0": "^6.3.13",
3936
"chai": "^3.4.1",
40-
"css-loader": "^0.23.1",
41-
"eslint": "^1.10.3",
42-
"eslint-loader": "^1.2.0",
43-
"eslint-plugin-react": "^3.12.0",
44-
"html-webpack-plugin": "^1.7.0",
4537
"mocha": "^2.3.4",
46-
"node-sass": "^3.4.2",
47-
"react-bootstrap": "^0.28.1",
48-
"react-dom": "^0.14.0",
49-
"react-hot-loader": "^1.3.0",
50-
"sass-loader": "^3.1.2",
51-
"style-loader": "^0.13.0",
52-
"webpack": "^1.12.9",
53-
"webpack-dev-server": "^1.14.0"
38+
"react-dom": "^0.14.0"
5439
},
5540
"dependencies": {
56-
"react": "^0.14.0"
41+
"react": ">=0.12.0"
5742
}
5843
}

src/if.jsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var React = require('react')
4+
, version = +React.version.substring(0, React.version.lastIndexOf('.'))
45
, types = ['bool', 'func', 'node'].map(name => React.PropTypes[name])
56
;
67

@@ -12,7 +13,7 @@ function _getResult(result) {
1213
return result;
1314

1415
if (typeof result === 'function') {
15-
if (typeof result.prototype.render === 'function')
16+
if (result.displayName)
1617
return React.createElement(result);
1718

1819
return _getResult(result());
@@ -36,8 +37,8 @@ var IF = React.createClass({
3637

3738
if (total) {
3839
React.Children.forEach(props.children, child => {
39-
if (child.type === IF) {
40-
if (!('if' in child.props)) {
40+
if (version <= 0.12 ? child.type === IF.type : child.type === IF) {
41+
if (child.props && !('if' in child.props)) {
4142
if (props.if && child.props.then) result.push(child.props.children);
4243
if (!props.if && child.props.else) result.push(child.props.children);
4344
} else {

test/tests.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
var expect = require('chai').expect
44
, React = require('react')
5-
, ReactDOMServer = require('react-dom/server')
5+
, version = +React.version.substring(0, React.version.lastIndexOf('.'))
6+
, ReactStaticMarkup = version <= 0.13 ? React : require('react-dom/server')
67
, Node = require('../src/if.jsx')
78
, nullElement = '<noscript></noscript>'
89
;
@@ -24,7 +25,9 @@ var Foo = React.createClass({
2425
});
2526

2627
function test(el, eq) {
27-
return expect(ReactDOMServer.renderToStaticMarkup(el)).equal(eq);
28+
return expect(
29+
ReactStaticMarkup[version <= 0.11 ? 'renderComponentToStaticMarkup' : 'renderToStaticMarkup'](el)
30+
).equal(eq);
2831
}
2932

3033
describe('React IF component testing:', function() {

0 commit comments

Comments
 (0)