@@ -6,27 +6,38 @@ var React = require("react");
6
6
function createClass ( baseClass ) {
7
7
function bindProperty ( instance , prop , value ) {
8
8
switch ( prop ) {
9
+ case 'state' :
10
+ case 'render' :
9
11
case 'componentDidMount' :
10
- case 'componentDidUpdate' :
11
- case 'componentWillMount' :
12
12
case 'componentWillUnmount' :
13
- case 'render' :
14
- case 'state' :
15
13
instance [ prop ] = value ;
16
14
break ;
17
15
18
- case 'componentWillReceiveProps' :
19
- instance [ prop ] = function ( a ) { return value ( a ) ( ) ; } ;
20
- break ;
21
-
22
16
case 'componentDidCatch' :
23
17
case 'componentWillUpdate' :
24
18
case 'shouldComponentUpdate' :
19
+ case 'getSnapshotBeforeUpdate' :
25
20
instance [ prop ] = function ( a , b ) { return value ( a ) ( b ) ( ) ; } ;
26
21
break ;
27
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
+
28
39
default :
29
- throw new Error ( 'Not a component property: ' + prop ) ;
40
+ throw new Error ( '[purescript-react] Not a component property: ' + prop ) ;
30
41
}
31
42
}
32
43
@@ -49,9 +60,25 @@ function createClass(baseClass) {
49
60
} ;
50
61
}
51
62
52
- exports . componentImpl = createClass ( React . Component ) ;
63
+ function createClassWithDerivedState ( classCtr ) {
64
+ return function ( displayName ) {
65
+ return function ( getDerivedStateFromProps ) {
66
+ return function ( ctrFn ) {
67
+ var Constructor = componentImpl ( displayName ) ( ctrFn ) ;
68
+ Constructor . getDerivedStateFromProps = function ( a , b ) { return getDerivedStateFromProps ( a ) ( b ) } ;
69
+ return Constructor ;
70
+ } ;
71
+ } ;
72
+ } ;
73
+ }
53
74
54
- exports . pureComponentImpl = createClass ( React . PureComponent ) ;
75
+ var componentImpl = createClass ( React . Component ) ;
76
+ exports . componentImpl = componentImpl ;
77
+ exports . componentWithDerivedStateImpl = createClassWithDerivedState ( componentImpl ) ;
78
+
79
+ var pureComponentImpl = createClass ( React . PureComponent ) ;
80
+ exports . pureComponentImpl = pureComponentImpl
81
+ exports . pureComponentWithDerivedStateImpl = createClassWithDerivedState ( pureComponentImpl ) ;
55
82
56
83
exports . statelessComponent = function ( x ) { return x ; } ;
57
84
@@ -68,60 +95,44 @@ exports.childrenToArray = React.Children.toArray
68
95
69
96
exports . childrenCount = React . Children . count ;
70
97
71
- function writeState ( this_ ) {
98
+ function setStateImpl ( this_ ) {
72
99
return function ( state ) {
73
100
return function ( ) {
74
101
this_ . setState ( state ) ;
75
- return state ;
76
102
} ;
77
103
} ;
78
104
}
79
- exports . writeState = writeState ;
105
+ exports . setStateImpl = setStateImpl ;
80
106
81
- function writeStateWithCallback ( this_ , cb ) {
107
+ function setStateWithCallbackImpl ( this_ ) {
82
108
return function ( state ) {
83
109
return function ( cb ) {
84
110
return function ( ) {
85
111
this_ . setState ( state , cb ) ;
86
- return state ;
87
112
} ;
88
113
} ;
89
114
} ;
90
115
}
91
- exports . writeStateWithCallback = writeStateWithCallback ;
116
+ exports . setStateWithCallbackImpl = setStateWithCallbackImpl ;
92
117
93
- function readState ( this_ ) {
118
+ function getState ( this_ ) {
94
119
return function ( ) {
120
+ if ( ! this_ . state ) {
121
+ throw new Error ( '[purescript-react] Cannot get state within constructor' ) ;
122
+ }
95
123
return this_ . state ;
96
124
} ;
97
125
}
98
- exports . readState = readState ;
126
+ exports . getState = getState ;
99
127
100
- function transformState ( this_ ) {
101
- return function ( update ) {
102
- return function ( ) {
103
- this_ . setState ( function ( old , props ) {
104
- return update ( old ) ;
105
- } ) ;
128
+ function forceUpdateWithCallback ( this_ ) {
129
+ return function ( cb ) {
130
+ return function ( ) {
131
+ this_ . forceUpdate ( cb ) ;
106
132
} ;
107
133
} ;
108
134
}
109
- exports . transformState = transformState ;
110
-
111
- function forceUpdateCbImpl ( this_ , cb ) {
112
- this_ . forceUpdate ( function ( ) {
113
- return cb ( ) ;
114
- } ) ;
115
- return { } ;
116
- } ;
117
- exports . forceUpdateCbImpl = forceUpdateCbImpl ;
118
-
119
- function handle ( f ) {
120
- return function ( e ) {
121
- return f ( e ) ( ) ;
122
- } ;
123
- } ;
124
- exports . handle = handle ;
135
+ exports . forceUpdateWithCallback = forceUpdateWithCallback ;
125
136
126
137
function createElement ( class_ ) {
127
138
return function ( props ) {
@@ -149,3 +160,12 @@ function createElementDynamic(class_) {
149
160
} ;
150
161
exports . createElementDynamicImpl = createElementDynamic ;
151
162
exports . createElementTagNameDynamic = createElementDynamic ;
163
+
164
+ function createContext ( defaultValue ) {
165
+ var context = React . createContext ( defaultValue ) ;
166
+ return {
167
+ consumer : context . Consumer ,
168
+ provider : context . Provider
169
+ } ;
170
+ }
171
+ exports . createContext = createContext ;
0 commit comments