@@ -6,27 +6,38 @@ var React = require("react");
66function createClass ( baseClass ) {
77 function bindProperty ( instance , prop , value ) {
88 switch ( prop ) {
9+ case 'state' :
10+ case 'render' :
911 case 'componentDidMount' :
10- case 'componentDidUpdate' :
11- case 'componentWillMount' :
1212 case 'componentWillUnmount' :
13- case 'render' :
14- case 'state' :
1513 instance [ prop ] = value ;
1614 break ;
1715
18- case 'componentWillReceiveProps' :
19- instance [ prop ] = function ( a ) { return value ( a ) ( ) ; } ;
20- break ;
21-
2216 case 'componentDidCatch' :
2317 case 'componentWillUpdate' :
2418 case 'shouldComponentUpdate' :
19+ case 'getSnapshotBeforeUpdate' :
2520 instance [ prop ] = function ( a , b ) { return value ( a ) ( b ) ( ) ; } ;
2621 break ;
2722
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+
2839 default :
29- throw new Error ( 'Not a component property: ' + prop ) ;
40+ throw new Error ( '[purescript-react] Not a component property: ' + prop ) ;
3041 }
3142 }
3243
@@ -49,9 +60,25 @@ function createClass(baseClass) {
4960 } ;
5061}
5162
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+ }
5374
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 ) ;
5582
5683exports . statelessComponent = function ( x ) { return x ; } ;
5784
@@ -68,60 +95,44 @@ exports.childrenToArray = React.Children.toArray
6895
6996exports . childrenCount = React . Children . count ;
7097
71- function writeState ( this_ ) {
98+ function setStateImpl ( this_ ) {
7299 return function ( state ) {
73100 return function ( ) {
74101 this_ . setState ( state ) ;
75- return state ;
76102 } ;
77103 } ;
78104}
79- exports . writeState = writeState ;
105+ exports . setStateImpl = setStateImpl ;
80106
81- function writeStateWithCallback ( this_ , cb ) {
107+ function setStateWithCallbackImpl ( this_ ) {
82108 return function ( state ) {
83109 return function ( cb ) {
84110 return function ( ) {
85111 this_ . setState ( state , cb ) ;
86- return state ;
87112 } ;
88113 } ;
89114 } ;
90115}
91- exports . writeStateWithCallback = writeStateWithCallback ;
116+ exports . setStateWithCallbackImpl = setStateWithCallbackImpl ;
92117
93- function readState ( this_ ) {
118+ function getState ( this_ ) {
94119 return function ( ) {
120+ if ( ! this_ . state ) {
121+ throw new Error ( '[purescript-react] Cannot get state within constructor' ) ;
122+ }
95123 return this_ . state ;
96124 } ;
97125}
98- exports . readState = readState ;
126+ exports . getState = getState ;
99127
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 ) ;
106132 } ;
107133 } ;
108134}
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 ;
125136
126137function createElement ( class_ ) {
127138 return function ( props ) {
@@ -149,3 +160,12 @@ function createElementDynamic(class_) {
149160} ;
150161exports . createElementDynamicImpl = createElementDynamic ;
151162exports . 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