33var React = require ( "react" ) ;
44var Fragment = React . Fragment || "div" ;
55
6- exports . createComponent_ = function ( defaultUpdate ) {
7- var defaultInitialState = null ;
8- var defaultShouldUpdate = function ( ) {
9- return function ( ) {
10- return function ( ) {
11- return true ;
12- } ;
13- } ;
14- } ;
15- var defaultDidMount = function ( ) {
16- return function ( ) { } ;
17- } ;
18- var defaultDidUpdate = function ( ) {
19- return function ( ) { } ;
20- } ;
21- var defaultWillUnmount = function ( ) {
22- return function ( ) { } ;
23- } ;
24- var defaultRender = function ( ) {
25- return false ;
26- } ;
27-
6+ exports . createComponent = ( function ( ) {
287 // Begin component prototype functions
298 // (`this`-dependent, defined outside `createComponent`
309 // for a slight performance boost)
@@ -39,7 +18,7 @@ exports.createComponent_ = function(defaultUpdate) {
3918
4019 function shouldComponentUpdate ( nextProps , nextState ) {
4120 var shouldUpdate = this . $$spec . shouldUpdate ;
42- return shouldUpdate === defaultShouldUpdate
21+ return shouldUpdate === undefined
4322 ? true
4423 : shouldUpdate ( this . toSelf ( ) ) ( nextProps . $$props ) (
4524 nextState === null ? null : nextState . $$state
@@ -48,22 +27,22 @@ exports.createComponent_ = function(defaultUpdate) {
4827
4928 function componentDidMount ( ) {
5029 var didMount = this . $$spec . didMount ;
51- if ( didMount !== defaultDidMount ) {
52- this . $$spec . didMount ( this . toSelf ( ) ) ( ) ;
30+ if ( didMount !== undefined ) {
31+ didMount ( this . toSelf ( ) ) ( ) ;
5332 }
5433 }
5534
5635 function componentDidUpdate ( ) {
5736 var didUpdate = this . $$spec . didUpdate ;
58- if ( didUpdate !== defaultDidUpdate ) {
37+ if ( didUpdate !== undefined ) {
5938 didUpdate ( this . toSelf ( ) ) ( ) ;
6039 }
6140 }
6241
6342 function componentWillUnmount ( ) {
6443 this . $$mounted = false ;
6544 var willUnmount = this . $$spec . willUnmount ;
66- if ( willUnmount !== defaultWillUnmount ) {
45+ if ( willUnmount !== undefined ) {
6746 willUnmount ( this . toSelf ( ) ) ( ) ;
6847 }
6948 }
@@ -81,40 +60,36 @@ exports.createComponent_ = function(defaultUpdate) {
8160 // React may optimize components with no state,
8261 // so we leave state null if it was left as
8362 // the default value.
84- this . $$spec . initialState === defaultInitialState
63+ this . $$spec . initialState === undefined
8564 ? null
8665 : { $$state : this . $$spec . initialState } ;
8766 return this ;
8867 } ;
8968
9069 Component . displayName = displayName ;
9170 Component . prototype = Object . create ( React . Component . prototype ) ;
71+ Component . prototype . constructor = Component ;
9272 Component . prototype . toSelf = toSelf ;
9373 Component . prototype . shouldComponentUpdate = shouldComponentUpdate ;
9474 Component . prototype . componentDidMount = componentDidMount ;
9575 Component . prototype . componentDidUpdate = componentDidUpdate ;
9676 Component . prototype . componentWillUnmount = componentWillUnmount ;
9777 Component . prototype . render = render ;
9878
99- return {
100- $$type : Component ,
101- initialState : defaultInitialState ,
102- shouldUpdate : defaultShouldUpdate ,
103- didMount : defaultDidMount ,
104- didUpdate : defaultDidUpdate ,
105- willUnmount : defaultWillUnmount ,
106- update : defaultUpdate ,
107- render : defaultRender
108- } ;
79+ return Component ;
10980 } ;
110- } ;
81+ } ) ( ) ;
11182
11283exports . send_ = function ( buildStateUpdate ) {
11384 return function ( self , action ) {
11485 if ( ! self . instance_ . $$mounted ) {
11586 exports . warningUnmountedComponentAction ( self , action ) ;
11687 return ;
11788 }
89+ if ( self . instance_ . $$spec . update === undefined ) {
90+ exports . warningDefaultUpdate ( self , action ) ;
91+ return ;
92+ }
11893 var sideEffects = null ;
11994 self . instance_ . setState (
12095 function ( s ) {
@@ -150,13 +125,26 @@ exports.readState = function(self) {
150125 return state === null ? null : state . $$state ;
151126} ;
152127
153- exports . make = function ( $$spec ) {
154- return function ( $$props ) {
155- var props = {
156- $$props : $$props ,
157- $$spec : $$spec
128+ exports . make = function ( _unionDict ) {
129+ return function ( $$type ) {
130+ return function ( $$spec ) {
131+ var $$specPadded = {
132+ initialState : $$spec . initialState ,
133+ update : $$spec . update ,
134+ render : $$spec . render ,
135+ shouldUpdate : $$spec . shouldUpdate ,
136+ didMount : $$spec . didMount ,
137+ didUpdate : $$spec . didUpdate ,
138+ willUnmount : $$spec . willUnmount
139+ } ;
140+ return function ( $$props ) {
141+ var props = {
142+ $$props : $$props ,
143+ $$spec : $$specPadded
144+ } ;
145+ return React . createElement ( $$type , props ) ;
146+ } ;
158147 } ;
159- return React . createElement ( $$spec . $$type , props ) ;
160148 } ;
161149} ;
162150
@@ -179,32 +167,48 @@ exports.fragment = function(children) {
179167 return React . createElement . apply ( null , [ Fragment , { } ] . concat ( children ) ) ;
180168} ;
181169
182- exports . displayNameFromComponentSpec = function ( $$spec ) {
183- return $$spec . $$ type. displayName || "[unknown]" ;
170+ exports . displayNameFromComponent = function ( $$type ) {
171+ return $$type . displayName || "[unknown]" ;
184172} ;
185173
186174exports . displayNameFromSelf = function ( self ) {
187- return exports . displayNameFromComponentSpec ( self . instance_ . $$spec ) ;
175+ return exports . displayNameFromComponent ( self . instance_ . prototype . constructor ) ;
188176} ;
189177
190- exports . toReactComponent_ = function ( fromJSProps , $$spec ) {
191- var Component = function constructor ( ) {
192- return this ;
193- } ;
194-
195- Component . prototype = Object . create ( React . Component . prototype ) ;
196-
197- Component . displayName = $$spec . $$type . displayName + " (Wrapper)" ;
198-
199- Component . prototype . render = function ( ) {
200- var props = {
201- $$props : fromJSProps ( this . props ) ,
202- $$spec : $$spec
178+ exports . toReactComponent = function ( _unionDict ) {
179+ return function ( fromJSProps ) {
180+ return function ( $$type ) {
181+ return function ( $$spec ) {
182+ var $$specPadded = {
183+ initialState : $$spec . initialState ,
184+ update : $$spec . update ,
185+ render : $$spec . render ,
186+ shouldUpdate : $$spec . shouldUpdate ,
187+ didMount : $$spec . didMount ,
188+ didUpdate : $$spec . didUpdate ,
189+ willUnmount : $$spec . willUnmount
190+ } ;
191+
192+ var Component = function constructor ( ) {
193+ return this ;
194+ } ;
195+
196+ Component . prototype = Object . create ( React . Component . prototype ) ;
197+
198+ Component . displayName = $$type . displayName + " (Wrapper)" ;
199+
200+ Component . prototype . render = function ( ) {
201+ var props = {
202+ $$props : fromJSProps ( this . props ) ,
203+ $$spec : $$specPadded
204+ } ;
205+ return React . createElement ( $$type , props ) ;
206+ } ;
207+
208+ return Component ;
209+ } ;
203210 } ;
204- return React . createElement ( $$spec . $$type , props ) ;
205211 } ;
206-
207- return Component ;
208212} ;
209213
210214exports . warningDefaultUpdate = function ( self , action ) {
0 commit comments