1
- /* global exports */
2
1
"use strict" ;
3
2
4
3
var React = require ( "react" ) ;
5
4
6
5
function createClass ( baseClass ) {
7
6
function bindProperty ( instance , prop , value ) {
8
7
switch ( prop ) {
9
- case ' state' :
10
- case ' render' :
11
- case ' componentDidMount' :
12
- case ' componentWillUnmount' :
8
+ case " state" :
9
+ case " render" :
10
+ case " componentDidMount" :
11
+ case " componentWillUnmount" :
13
12
instance [ prop ] = value ;
14
13
break ;
15
14
16
- case ' componentDidCatch' :
17
- case ' componentWillUpdate' :
18
- case ' shouldComponentUpdate' :
19
- case ' getSnapshotBeforeUpdate' :
15
+ case " componentDidCatch" :
16
+ case " componentWillUpdate" :
17
+ case " shouldComponentUpdate" :
18
+ case " getSnapshotBeforeUpdate" :
20
19
instance [ prop ] = function ( a , b ) { return value ( a ) ( b ) ( ) ; } ;
21
20
break ;
22
21
23
- case ' componentDidUpdate' :
22
+ case " componentDidUpdate" :
24
23
instance [ prop ] = function ( a , b , c ) { return value ( a ) ( b ) ( c ) ( ) ; } ;
25
24
break ;
26
25
27
- case ' unsafeComponentWillMount' :
28
- instance [ ' UNSAFE_componentWillMount' ] = value ;
26
+ case " unsafeComponentWillMount" :
27
+ instance [ " UNSAFE_componentWillMount" ] = value ;
29
28
break ;
30
29
31
- case ' unsafeComponentWillReceiveProps' :
32
- instance [ ' UNSAFE_componentWillReceiveProps' ] = function ( a ) { return value ( a ) ( ) ; } ;
30
+ case " unsafeComponentWillReceiveProps" :
31
+ instance [ " UNSAFE_componentWillReceiveProps" ] = function ( a ) { return value ( a ) ( ) ; } ;
33
32
break ;
34
33
35
- case ' unsafeComponentWillUpdate' :
36
- instance [ ' UNSAFE_componentWillUpdate' ] = function ( a , b ) { return value ( a ) ( b ) ( ) ; } ;
34
+ case " unsafeComponentWillUpdate" :
35
+ instance [ " UNSAFE_componentWillUpdate" ] = function ( a , b ) { return value ( a ) ( b ) ( ) ; } ;
37
36
break ;
38
37
39
38
default :
40
- throw new Error ( ' [purescript-react] Not a component property: ' + prop ) ;
39
+ throw new Error ( " [purescript-react] Not a component property: " + prop ) ;
41
40
}
42
41
}
43
42
@@ -47,7 +46,9 @@ function createClass(baseClass) {
47
46
baseClass . call ( this , props ) ;
48
47
var spec = ctrFn ( this ) ( ) ;
49
48
for ( var k in spec ) {
50
- bindProperty ( this , k , spec [ k ] ) ;
49
+ if ( Object . prototype . hasOwnProperty . call ( spec , k ) ) {
50
+ bindProperty ( this , k , spec [ k ] ) ;
51
+ }
51
52
}
52
53
} ;
53
54
@@ -60,7 +61,13 @@ function createClass(baseClass) {
60
61
} ;
61
62
}
62
63
63
- function createClassWithDerivedState ( classCtr ) {
64
+ var componentImpl = createClass ( React . Component ) ;
65
+ exports . componentImpl = componentImpl ;
66
+
67
+ var pureComponentImpl = createClass ( React . PureComponent ) ;
68
+ exports . pureComponentImpl = pureComponentImpl ;
69
+
70
+ function createClassWithDerivedState ( ) {
64
71
return function ( displayName ) {
65
72
return function ( getDerivedStateFromProps ) {
66
73
return function ( ctrFn ) {
@@ -72,12 +79,7 @@ function createClassWithDerivedState(classCtr) {
72
79
} ;
73
80
}
74
81
75
- var componentImpl = createClass ( React . Component ) ;
76
- exports . componentImpl = componentImpl ;
77
82
exports . componentWithDerivedStateImpl = createClassWithDerivedState ( componentImpl ) ;
78
-
79
- var pureComponentImpl = createClass ( React . PureComponent ) ;
80
- exports . pureComponentImpl = pureComponentImpl ;
81
83
exports . pureComponentWithDerivedStateImpl = createClassWithDerivedState ( pureComponentImpl ) ;
82
84
83
85
exports . statelessComponent = function ( x ) { return x ; } ;
@@ -118,7 +120,7 @@ exports.setStateWithCallbackImpl = setStateWithCallbackImpl;
118
120
function getState ( this_ ) {
119
121
return function ( ) {
120
122
if ( ! this_ . state ) {
121
- throw new Error ( ' [purescript-react] Cannot get state within constructor' ) ;
123
+ throw new Error ( " [purescript-react] Cannot get state within constructor" ) ;
122
124
}
123
125
return this_ . state ;
124
126
} ;
@@ -157,7 +159,7 @@ function createElementDynamic(class_) {
157
159
return React . createElement ( class_ , props , children ) ;
158
160
} ;
159
161
} ;
160
- } ;
162
+ }
161
163
exports . createElementDynamicImpl = createElementDynamic ;
162
164
exports . createElementTagNameDynamic = createElementDynamic ;
163
165
0 commit comments