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