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 invoke1 ( f ) {
5
+ return f === undefined ? f : function ( a ) {
6
+ return f ( a ) ( )
7
+ }
8
+ }
9
+ function invoke2 ( f ) {
10
+ return f === undefined ? f : function ( a , b ) {
11
+ return f ( a ) ( b ) ( )
12
+ }
13
+ }
14
+ function invoke3 ( f ) {
15
+ return f === undefined ? f : function ( a , b , c ) {
16
+ return f ( a ) ( b ) ( c ) ( )
38
17
}
39
18
}
40
19
@@ -43,10 +22,19 @@ function createClass(baseClass) {
43
22
var Constructor = function ( props ) {
44
23
baseClass . call ( this , props ) ;
45
24
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
- }
25
+
26
+ this . state = spec . state ;
27
+ this . render = spec . render ;
28
+ this . componentDidMount = spec . componentDidMount ;
29
+ this . componentWillUnmount = spec . componentWillUnmount ;
30
+ this . componentDidCatch = invoke2 ( spec . componentDidCatch ) ;
31
+ this . componentWillUpdate = invoke2 ( spec . componentWillUpdate ) ;
32
+ this . shouldComponentUpdate = invoke2 ( spec . shouldComponentUpdate ) ;
33
+ this . getSnapshotBeforeUpdate = invoke2 ( spec . getSnapshotBeforeUpdate ) ;
34
+ this . componentDidUpdate = invoke3 ( spec . componentDidUpdate ) ;
35
+ this . UNSAFE_componentWillMount = spec . unsafeComponentWillMount ;
36
+ this . UNSAFE_componentWillReceiveProps = invoke1 ( spec . unsafeComponentWillReceiveProps ) ;
37
+ this . UNSAFE_componentWillUpdate = invoke2 ( spec . unsafeComponentWillUpdate ) ;
50
38
} ;
51
39
52
40
Constructor . displayName = displayName ;
0 commit comments