4
4
var React = require ( "react" ) ;
5
5
6
6
function createClass ( baseClass ) {
7
- function bindProperty ( instance , prop , value ) {
8
- switch ( prop ) {
9
- case 'state' :
10
- case 'render' :
11
- case 'componentDidMount' :
12
- case 'componentWillUnmount' :
13
- instance [ prop ] = value ;
14
- break ;
15
-
16
- case 'componentDidCatch' :
17
- case 'componentWillUpdate' :
18
- case 'shouldComponentUpdate' :
19
- case 'getSnapshotBeforeUpdate' :
20
- instance [ prop ] = function ( a , b ) { return value ( a ) ( b ) ( ) ; } ;
21
- break ;
22
-
23
- case 'componentDidUpdate' :
24
- instance [ prop ] = function ( a , b , c ) { return value ( a ) ( b ) ( c ) ( ) ; } ;
25
- break ;
26
-
27
- case 'unsafeComponentWillMount' :
28
- instance [ 'UNSAFE_componentWillMount' ] = value ;
29
- break ;
30
-
31
- case 'unsafeComponentWillReceiveProps' :
32
- instance [ 'UNSAFE_componentWillReceiveProps' ] = function ( a ) { return value ( a ) ( ) ; } ;
33
- break ;
34
-
35
- case 'unsafeComponentWillUpdate' :
36
- instance [ 'UNSAFE_componentWillUpdate' ] = function ( a , b ) { return value ( a ) ( b ) ( ) ; } ;
37
- break ;
38
-
39
- default :
40
- throw new Error ( '[purescript-react] Not a component property: ' + prop ) ;
7
+ function curry2 ( f ) {
8
+ return f === undefined ? f : function ( a , b ) {
9
+ return f ( a ) ( b )
10
+ }
11
+ }
12
+ function curry3 ( f ) {
13
+ return f === undefined ? f : function ( a , b , c ) {
14
+ return f ( a ) ( b ) ( c )
41
15
}
42
16
}
43
17
@@ -46,9 +20,19 @@ function createClass(baseClass) {
46
20
var Constructor = function ( props ) {
47
21
baseClass . call ( this , props ) ;
48
22
var spec = ctrFn ( this ) ( ) ;
49
- for ( var k in spec ) {
50
- bindProperty ( this , k , spec [ k ] ) ;
51
- }
23
+
24
+ this . state = spec . state ;
25
+ this . render = spec . render ;
26
+ this . componentDidMount = spec . componentDidMount ;
27
+ this . componentWillUnmount = spec . componentWillUnmount ;
28
+ this . componentDidCatch = curry2 ( spec . componentDidCatch ) ;
29
+ this . componentWillUpdate = curry2 ( spec . componentWillUpdate ) ;
30
+ this . shouldComponentUpdate = curry2 ( spec . shouldComponentUpdate ) ;
31
+ this . getSnapshotBeforeUpdate = curry2 ( spec . getSnapshotBeforeUpdate ) ;
32
+ this . componentDidUpdate = curry3 ( spec . componentDidUpdate ) ;
33
+ this . UNSAFE_componentWillMount = spec . unsafeComponentWillMount ;
34
+ this . UNSAFE_componentWillReceiveProps = curry2 ( spec . unsafeComponentWillReceiveProps ) ;
35
+ this . UNSAFE_componentWillUpdate = curry3 ( spec . unsafeComponentWillUpdate ) ;
52
36
} ;
53
37
54
38
Constructor . displayName = displayName ;
0 commit comments