-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (49 loc) · 1.48 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var React = require('react')
var semver = require('semver')
var _createReactClass
var _propTypes
var _refSet
var _refGet
// Hack for future support of react without React.createClass
if (semver.satisfies(React.version, '>=15.5.0')) {
_createReactClass = require('create' + '-react-class')
_propTypes = require('prop' + '-types')
} else {
_createReactClass = React.createClass
_propTypes = React.PropTypes
}
// Refs are handled different ways in different versions of react
if (semver.satisfies(React.version, '>=0.14.0')) {
_refSet = function (_this, refName) {
_this['__setRef' + refName] = _this['__setRef' + refName] || function (ref) {
_this['__ref' + refName] = ref
}
return _this['__setRef' + refName]
}
_refGet = function (_this, refName) {
return _this['__ref' + refName]
}
} else if (semver.satisfies(React.version, '>=0.13.0')) {
_refSet = function (_this, refName) {
_this['__setRef' + refName] = _this['__setRef' + refName] || function (ref) {
_this['__ref' + refName] = ref
}
return _this['__setRef' + refName]
}
_refGet = function (_this, refName) {
return _this['__ref' + refName] && _this['__ref' + refName].getDOMNode()
}
} else {
_refSet = function (_this, refName) {
return refName
}
_refGet = function (_this, refName) {
return _this.refs[refName] && _this.refs[refName].getDOMNode()
}
}
module.exports = {
createClass: _createReactClass,
PropTypes: _propTypes,
refSet: _refSet,
refGet: _refGet
}