@@ -23,14 +23,14 @@ require('art/modes/fast'); // Flip this to DOM mode for debugging
2323var Transform = require ( 'art/core/transform' ) ;
2424var Mode = require ( 'art/modes/current' ) ;
2525
26+ var DOMPropertyOperations = require ( 'DOMPropertyOperations' ) ;
2627var ReactComponent = require ( 'ReactComponent' ) ;
2728var ReactMount = require ( 'ReactMount' ) ;
2829var ReactMultiChild = require ( 'ReactMultiChild' ) ;
2930var ReactDOMComponent = require ( 'ReactDOMComponent' ) ;
3031
3132var ReactComponentMixin = ReactComponent . Mixin ;
3233
33- var flattenChildren = require ( 'flattenChildren' ) ; // Should I use this?
3434var mixInto = require ( 'mixInto' ) ;
3535var merge = require ( 'merge' ) ;
3636
@@ -54,9 +54,10 @@ function childrenAsString(children) {
5454 return '' ;
5555}
5656
57- function createComponent ( ) {
57+ function createComponent ( name ) {
5858 var ReactARTComponent = function ( ) { } ;
59- for ( var i = 0 , l = arguments . length ; i < l ; i ++ ) {
59+ ReactARTComponent . displayName = name ;
60+ for ( var i = 1 , l = arguments . length ; i < l ; i ++ ) {
6061 mixInto ( ReactARTComponent , arguments [ i ] ) ;
6162 }
6263 var ConvenienceConstructor = function ( props , children ) {
@@ -144,7 +145,7 @@ var ContainerMixin = merge(ReactMultiChild.Mixin, {
144145 /**
145146 * Override to bypass batch updating because it is not necessary.
146147 *
147- * @param {?object } nextChildren As returned by `flattenChildren` .
148+ * @param {?object } nextChildren.
148149 * @param {ReactReconcileTransaction } transaction
149150 * @internal
150151 * @override {ReactMultiChild.Mixin.updateChildren}
@@ -158,7 +159,7 @@ var ContainerMixin = merge(ReactMultiChild.Mixin, {
158159
159160 mountAndInjectChildren : function ( children , transaction ) {
160161 var mountedImages = this . mountChildren (
161- flattenChildren ( children ) ,
162+ children ,
162163 transaction
163164 ) ;
164165 for ( var i = 0 ; i < mountedImages . length ; i ++ ) {
@@ -171,6 +172,7 @@ var ContainerMixin = merge(ReactMultiChild.Mixin, {
171172// Surface - Root node of all ART
172173
173174var Surface = createComponent (
175+ 'Surface' ,
174176 ReactDOMComponent . Mixin ,
175177 ReactComponentMixin ,
176178 ContainerMixin , {
@@ -182,9 +184,10 @@ var Surface = createComponent(
182184 transaction ,
183185 mountDepth
184186 ) ;
185- transaction . getReactOnDOMReady ( ) . enqueue ( this , this . componentDidMount ) ;
187+ transaction . getReactMountReady ( ) . enqueue ( this , this . componentDidMount ) ;
186188 // Temporary placeholder
187- return '<div ' + ReactMount . ATTR_NAME + '="' + rootID + '"></div>' ;
189+ var idMarkup = DOMPropertyOperations . createMarkupForID ( rootID ) ;
190+ return '<div ' + idMarkup + '></div>' ;
188191 } ,
189192
190193 setApprovedDOMProperties : function ( nextProps ) {
@@ -221,13 +224,14 @@ var Surface = createComponent(
221224 this . props = prevProps ;
222225 } ,
223226
224- componentDidMount : function ( node ) {
227+ componentDidMount : function ( ) {
225228 var props = this . props ;
226229
227230 this . node = Mode . Surface ( + props . width , + props . height ) ;
228231 var surfaceElement = this . node . toElement ( ) ;
229232
230233 // Replace placeholder hoping that nothing important happened to it
234+ var node = this . getDOMNode ( ) ;
231235 if ( node . parentNode ) {
232236 node . parentNode . replaceChild ( surfaceElement , node ) ;
233237 }
@@ -248,7 +252,8 @@ var Surface = createComponent(
248252 this . props = props ;
249253 } ,
250254
251- receiveProps : function ( props , transaction ) {
255+ receiveComponent : function ( nextComponent , transaction ) {
256+ var props = nextComponent . props ;
252257 var node = this . node ;
253258
254259 if ( this . props . width != props . width || this . props . width != props . height ) {
@@ -257,7 +262,7 @@ var Surface = createComponent(
257262
258263 this . setApprovedDOMProperties ( props ) ;
259264
260- this . updateChildren ( flattenChildren ( props . children ) , transaction ) ;
265+ this . updateChildren ( props . children , transaction ) ;
261266
262267 if ( node . render ) {
263268 node . render ( ) ;
@@ -381,18 +386,20 @@ var NodeMixin = merge(ReactComponentMixin, {
381386
382387// Group
383388
384- var Group = createComponent ( NodeMixin , ContainerMixin , {
389+ var Group = createComponent ( 'Group' , NodeMixin , ContainerMixin , {
385390
386391 mountComponent : function ( transaction ) {
392+ ReactComponentMixin . mountComponent . apply ( this , arguments ) ;
387393 this . node = Mode . Group ( ) ;
388394 this . applyGroupProps ( BLANK_PROPS , this . props ) ;
389395 this . mountAndInjectChildren ( this . props . children , transaction ) ;
390396 return this . node ;
391397 } ,
392398
393- receiveProps : function ( props , transaction ) {
399+ receiveComponent : function ( nextComponent , transaction ) {
400+ var props = nextComponent . props ;
394401 this . applyGroupProps ( this . props , props ) ;
395- this . updateChildren ( flattenChildren ( props . children ) , transaction ) ;
402+ this . updateChildren ( props . children , transaction ) ;
396403 this . props = props ;
397404 } ,
398405
@@ -409,6 +416,41 @@ var Group = createComponent(NodeMixin, ContainerMixin, {
409416
410417} ) ;
411418
419+ // ClippingRectangle
420+ var ClippingRectangle = createComponent (
421+ 'ClippingRectangle' , NodeMixin , ContainerMixin , {
422+
423+ mountComponent : function ( transaction ) {
424+ ReactComponentMixin . mountComponent . apply ( this , arguments ) ;
425+ this . node = Mode . ClippingRectangle ( ) ;
426+ this . applyClippingProps ( BLANK_PROPS , this . props ) ;
427+ this . mountAndInjectChildren ( this . props . children , transaction ) ;
428+ return this . node ;
429+ } ,
430+
431+ receiveComponent : function ( nextComponent , transaction ) {
432+ var props = nextComponent . props ;
433+ this . applyClippingProps ( this . props , props ) ;
434+ this . updateChildren ( props . children , transaction ) ;
435+ this . props = props ;
436+ } ,
437+
438+ applyClippingProps : function ( oldProps , props ) {
439+ this . node . width = props . width ;
440+ this . node . height = props . height ;
441+ this . node . x = props . x ;
442+ this . node . y = props . y ;
443+ this . applyNodeProps ( oldProps , props ) ;
444+ } ,
445+
446+ unmountComponent : function ( ) {
447+ this . destroyEventListeners ( ) ;
448+ this . unmountChildren ( ) ;
449+ }
450+
451+ } ) ;
452+
453+
412454// Renderables
413455
414456var RenderableMixin = merge ( NodeMixin , {
@@ -445,15 +487,17 @@ var RenderableMixin = merge(NodeMixin, {
445487
446488// Shape
447489
448- var Shape = createComponent ( RenderableMixin , {
490+ var Shape = createComponent ( 'Shape' , RenderableMixin , {
449491
450492 mountComponent : function ( ) {
493+ ReactComponentMixin . mountComponent . apply ( this , arguments ) ;
451494 this . node = Mode . Shape ( ) ;
452495 this . applyShapeProps ( BLANK_PROPS , this . props ) ;
453496 return this . node ;
454497 } ,
455498
456- receiveProps : function ( props ) {
499+ receiveComponent : function ( nextComponent , transaction ) {
500+ var props = nextComponent . props ;
457501 this . applyShapeProps ( this . props , props ) ;
458502 this . props = props ;
459503 } ,
@@ -478,9 +522,10 @@ var Shape = createComponent(RenderableMixin, {
478522
479523// Text
480524
481- var Text = createComponent ( RenderableMixin , {
525+ var Text = createComponent ( 'Text' , RenderableMixin , {
482526
483527 mountComponent : function ( ) {
528+ ReactComponentMixin . mountComponent . apply ( this , arguments ) ;
484529 var props = this . props ;
485530 var newString = childrenAsString ( props . children ) ;
486531 this . node = Mode . Text ( newString , props . font , props . alignment , props . path ) ;
@@ -505,7 +550,8 @@ var Text = createComponent(RenderableMixin, {
505550 ) ;
506551 } ,
507552
508- receiveProps : function ( props ) {
553+ receiveComponent : function ( nextComponent , transaction ) {
554+ var props = nextComponent . props ;
509555 var oldProps = this . props ;
510556
511557 var oldString = this . _oldString ;
@@ -534,21 +580,21 @@ var Text = createComponent(RenderableMixin, {
534580
535581var slice = Array . prototype . slice ;
536582
537- var LinearGradient = function ( stops , x1 , y1 , x2 , y2 ) {
583+ function LinearGradient ( stops , x1 , y1 , x2 , y2 ) {
538584 this . args = slice . call ( arguments ) ;
539585} ;
540586LinearGradient . prototype . applyFill = function ( node ) {
541587 node . fillLinear . apply ( node , this . args ) ;
542588} ;
543589
544- var RadialGradient = function ( stops , fx , fy , rx , ry , cx , cy ) {
590+ function RadialGradient ( stops , fx , fy , rx , ry , cx , cy ) {
545591 this . args = slice . call ( arguments ) ;
546592} ;
547593RadialGradient . prototype . applyFill = function ( node ) {
548594 node . fillRadial . apply ( node , this . args ) ;
549595} ;
550596
551- var Pattern = function ( url , width , height , left , top ) {
597+ function Pattern ( url , width , height , left , top ) {
552598 this . args = slice . call ( arguments ) ;
553599} ;
554600Pattern . prototype . applyFill = function ( node ) {
@@ -564,6 +610,7 @@ var ReactART = {
564610 Path : Mode . Path ,
565611 Surface : Surface ,
566612 Group : Group ,
613+ ClippingRectangle : ClippingRectangle ,
567614 Shape : Shape ,
568615 Text : Text
569616
0 commit comments