Skip to content

Commit 2a34e21

Browse files
committed
Update to latest internal build
Included changes: * Display name for debugging purposes * Experimental Clipping Rectangle hooks for experimental art build * Defer markup generation to centralized point * Unit test updated to support latest JSDOM quirks.
1 parent 55659a7 commit 2a34e21

File tree

2 files changed

+84
-25
lines changed

2 files changed

+84
-25
lines changed

src/ReactART.js

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ require('art/modes/fast'); // Flip this to DOM mode for debugging
2323
var Transform = require('art/core/transform');
2424
var Mode = require('art/modes/current');
2525

26+
var DOMPropertyOperations = require('DOMPropertyOperations');
2627
var ReactComponent = require('ReactComponent');
2728
var ReactMount = require('ReactMount');
2829
var ReactMultiChild = require('ReactMultiChild');
2930
var ReactDOMComponent = require('ReactDOMComponent');
3031

3132
var ReactComponentMixin = ReactComponent.Mixin;
3233

33-
var flattenChildren = require('flattenChildren'); // Should I use this?
3434
var mixInto = require('mixInto');
3535
var 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

173174
var 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

414456
var 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

535581
var 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
};
540586
LinearGradient.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
};
547593
RadialGradient.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
};
554600
Pattern.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

src/__tests__/ReactART-test.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,19 @@ var Shape;
3232
var Surface;
3333
var TestComponent;
3434

35+
var Missing = {};
36+
3537
function testDOMNodeStructure(domNode, expectedStructure) {
3638
expect(domNode).toBeDefined();
3739
expect(domNode.nodeName).toBe(expectedStructure.nodeName);
3840
for (var prop in expectedStructure) {
3941
if (!expectedStructure.hasOwnProperty(prop)) continue;
4042
if (prop != 'nodeName' && prop != 'children') {
41-
expect(domNode.getAttribute(prop)).toBe(expectedStructure[prop]);
43+
if (expectedStructure[prop] === Missing) {
44+
expect(domNode.hasAttribute(prop)).toBe(false);
45+
} else {
46+
expect(domNode.getAttribute(prop)).toBe(expectedStructure[prop]);
47+
}
4248
}
4349
}
4450
if (expectedStructure.children) {
@@ -95,17 +101,23 @@ describe('ReactART', function() {
95101

96102
return (
97103
<Surface width={150} height={200}>
98-
<Group>
104+
<Group ref="group">
99105
{this.props.flipped ? [b, a, c] : [a, b, c]}
100106
</Group>
101107
</Surface>
102108
);
103109
}
104-
105110
});
106111

107112
});
108113

114+
it('should have the correct lifecycle state', function() {
115+
var instance = <TestComponent />;
116+
ReactTestUtils.renderIntoDocument(instance);
117+
var group = instance.refs.group;
118+
expect(group._lifeCycleState).toBe('MOUNTED');
119+
});
120+
109121
it('should render a reasonable SVG structure in SVG mode', function() {
110122
var instance = <TestComponent />;
111123
ReactTestUtils.renderIntoDocument(instance);
@@ -150,7 +162,7 @@ describe('ReactART', function() {
150162
children: [
151163
{ nodeName: 'DEFS' },
152164
{ nodeName: 'PATH', opacity: '0.1' },
153-
{ nodeName: 'PATH', opacity: '' },
165+
{ nodeName: 'PATH', opacity: Missing },
154166
{ nodeName: 'G' }
155167
]
156168
}
@@ -170,7 +182,7 @@ describe('ReactART', function() {
170182
nodeName: 'G',
171183
children: [
172184
{ nodeName: 'DEFS' },
173-
{ nodeName: 'PATH', opacity: '' },
185+
{ nodeName: 'PATH', opacity: Missing },
174186
{ nodeName: 'PATH', opacity: '0.1' },
175187
{ nodeName: 'G' }
176188
]

0 commit comments

Comments
 (0)