@@ -7,39 +7,47 @@ exports.createComponent_ = function(noUpdate, buildStateUpdate, displayName) {
77 function contextToSelf ( instance ) {
88 var self = {
99 props : instance . props . $$props ,
10- state : instance . state === undefined ? undefined : instance . state . $$state ,
10+ state : instance . state === null ? null : instance . state . $$state ,
1111 readProps : function ( ) {
1212 return self . instance_ . props . $$props ;
1313 } ,
1414 readState : function ( ) {
1515 var state = self . instance_ . state ;
16- return state === undefined ? undefined : state . $$state ;
16+ return state === null ? null : state . $$state ;
1717 } ,
1818 send : function ( action ) {
1919 return function ( ) {
20- var updates = buildStateUpdate (
21- self . instance_ . $$spec . update ( self ) ( action )
20+ var sideEffects = null ;
21+ self . instance_ . setState (
22+ function ( s ) {
23+ var setStateContext = contextToSelf ( self . instance_ ) ;
24+ setStateContext . state = s . $$state ;
25+ var updates = buildStateUpdate (
26+ self . instance_ . $$spec . update ( setStateContext ) ( action )
27+ ) ;
28+ if ( updates . effects !== null ) {
29+ sideEffects = updates . effects ;
30+ }
31+ if ( updates . state !== null && updates . state !== s . $$state ) {
32+ return { $$state : updates . state } ;
33+ } else {
34+ return null ;
35+ }
36+ } ,
37+ function ( ) {
38+ if ( sideEffects !== null ) {
39+ sideEffects ( contextToSelf ( this ) ) ( ) ;
40+ }
41+ }
2242 ) ;
23- if ( updates . state !== null ) {
24- self . instance_ . setState (
25- { $$state : updates . state } ,
26- updates . effects !== null
27- ? function ( ) {
28- updates . effects ( contextToSelf ( this ) ) ( ) ;
29- }
30- : undefined
31- ) ;
32- } else if ( updates . effects !== null ) {
33- updates . effects ( self ) ( ) ;
34- }
3543 } ;
3644 } ,
3745 instance_ : instance
3846 } ;
3947 return self ;
4048 }
4149
42- var defaultInitialState = { } ;
50+ var defaultInitialState = null ;
4351 var defaultShouldUpdate = function ( ) {
4452 return function ( ) {
4553 return function ( ) {
@@ -69,10 +77,10 @@ exports.createComponent_ = function(noUpdate, buildStateUpdate, displayName) {
6977 this . $$spec = props . $$spec ;
7078 this . state =
7179 // React may optimize components with no state,
72- // so we leave state undefined if it was left as
80+ // so we leave state null if it was left as
7381 // the default value.
7482 this . $$spec . initialState === defaultInitialState
75- ? undefined
83+ ? null
7684 : { $$state : this . $$spec . initialState } ;
7785 return this ;
7886 } ;
@@ -117,12 +125,12 @@ exports.createStatelessComponent = function(displayName) {
117125 function contextToSelf ( instance ) {
118126 var self = {
119127 props : instance . props . $$props ,
120- state : undefined ,
128+ state : null ,
121129 readProps : function ( ) {
122130 return self . instance_ . props . $$props ;
123131 } ,
124132 readState : function ( ) {
125- return undefined ;
133+ return null ;
126134 } ,
127135 send : function ( ) {
128136 return function ( ) { } ;
@@ -132,7 +140,7 @@ exports.createStatelessComponent = function(displayName) {
132140 return self ;
133141 }
134142
135- var defaultInitialState = { } ;
143+ var defaultInitialState = null ;
136144 var defaultShouldUpdate = function ( ) {
137145 return function ( ) {
138146 return function ( ) {
@@ -183,16 +191,36 @@ exports.createStatelessComponent = function(displayName) {
183191 } ;
184192} ;
185193
186- exports . make = function ( component ) {
194+ exports . make = function ( $$spec ) {
187195 return function ( $$props ) {
188196 var props = {
189197 $$props : $$props ,
190- $$spec : component
198+ $$spec : $$spec
191199 } ;
192- return React . createElement ( component . $$type , props ) ;
200+ return React . createElement ( $$spec . $$type , props ) ;
193201 } ;
194202} ;
195203
204+ exports . toReactComponent = function ( $$spec ) {
205+ var Component = function constructor ( ) {
206+ return this ;
207+ } ;
208+
209+ Component . prototype = Object . create ( React . Component . prototype ) ;
210+
211+ Component . displayName = $$spec . $$type . displayName + " (Wrapper)" ;
212+
213+ Component . prototype . render = function ( ) {
214+ var props = {
215+ $$props : this . props ,
216+ $$spec : $$spec
217+ } ;
218+ return React . createElement ( $$spec . $$type , props ) ;
219+ } ;
220+
221+ return Component ;
222+ } ;
223+
196224exports . keyed_ = function ( key , child ) {
197225 return React . createElement ( Fragment , { key : key } , child ) ;
198226} ;
@@ -204,9 +232,7 @@ exports.element_ = function(component, props) {
204232 ) ;
205233} ;
206234
207- exports . elementKeyed_ = function ( key , child ) {
208- return React . createElement . call ( null , Fragment , { key : key } , child ) ;
209- } ;
235+ exports . elementKeyed_ = exports . element_ ;
210236
211237exports . fragment = function ( children ) {
212238 return React . createElement . apply ( null , [ Fragment , { } ] . concat ( children ) ) ;
0 commit comments