mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Merge branch 'no-content' of git://github.com/spicyj/react into spicyj-no-content
Conflicts: src/core/ReactNativeComponent.js
This commit is contained in:
@@ -36,7 +36,6 @@ var invariant = require('invariant');
|
||||
* @private
|
||||
*/
|
||||
var INVALID_PROPERTY_ERRORS = {
|
||||
content: '`content` must be set using `updateTextContentByID()`.',
|
||||
dangerouslySetInnerHTML:
|
||||
'`dangerouslySetInnerHTML` must be set using `updateInnerHTMLByID()`.',
|
||||
style: '`style` must be set using `updateStylesByID()`.'
|
||||
|
||||
@@ -40,7 +40,6 @@ var registrationNames = ReactEventEmitter.registrationNames;
|
||||
// For quickly matching children type, to test if can be treated as content.
|
||||
var CONTENT_TYPES = {'string': true, 'number': true};
|
||||
|
||||
var CONTENT = keyOf({content: null});
|
||||
var DANGEROUSLY_SET_INNER_HTML = keyOf({dangerouslySetInnerHTML: null});
|
||||
var STYLE = keyOf({style: null});
|
||||
|
||||
@@ -51,14 +50,10 @@ function assertValidProps(props) {
|
||||
if (!props) {
|
||||
return;
|
||||
}
|
||||
// Note the use of `!=` which checks for null or undefined.
|
||||
var hasChildren = props.children != null ? 1 : 0;
|
||||
var hasContent = props.content != null ? 1 : 0;
|
||||
var hasInnerHTML = props.dangerouslySetInnerHTML != null ? 1 : 0;
|
||||
// Note the use of `==` which checks for null or undefined.
|
||||
invariant(
|
||||
hasChildren + hasContent + hasInnerHTML <= 1,
|
||||
'Can only set one of `children`, `props.content`, or ' +
|
||||
'`props.dangerouslySetInnerHTML`.'
|
||||
props.children == null || props.dangerouslySetInnerHTML == null,
|
||||
'Can only set one of `children` or `props.dangerouslySetInnerHTML`.'
|
||||
);
|
||||
invariant(
|
||||
props.style == null || typeof props.style === 'object',
|
||||
@@ -158,7 +153,7 @@ ReactNativeComponent.Mixin = {
|
||||
return innerHTML.__html;
|
||||
}
|
||||
} else {
|
||||
var contentToUse = this.props.content != null ? this.props.content :
|
||||
var contentToUse =
|
||||
CONTENT_TYPES[typeof this.props.children] ? this.props.children : null;
|
||||
var childrenToUse = contentToUse != null ? null : this.props.children;
|
||||
if (contentToUse != null) {
|
||||
@@ -222,12 +217,11 @@ ReactNativeComponent.Mixin = {
|
||||
}
|
||||
}
|
||||
} else if (propKey === DANGEROUSLY_SET_INNER_HTML) {
|
||||
// http://jsperf.com/emptying-speed
|
||||
ReactComponent.DOMIDOperations.updateTextContentByID(
|
||||
this._rootNodeID,
|
||||
''
|
||||
);
|
||||
} else if (propKey === CONTENT) {
|
||||
// (Removal happens in _updateDOMChildren)
|
||||
} else if (registrationNames[propKey]) {
|
||||
deleteListener(this._rootNodeID, propKey);
|
||||
} else {
|
||||
@@ -277,8 +271,6 @@ ReactNativeComponent.Mixin = {
|
||||
nextProp
|
||||
);
|
||||
}
|
||||
} else if (propKey === CONTENT) {
|
||||
// (Update happens in _updateDOMChildren)
|
||||
} else if (registrationNames[propKey]) {
|
||||
putListener(this._rootNodeID, propKey, nextProp);
|
||||
} else {
|
||||
@@ -305,17 +297,10 @@ ReactNativeComponent.Mixin = {
|
||||
* @param {ReactReconcileTransaction} transaction
|
||||
*/
|
||||
_updateDOMChildren: function(nextProps, transaction) {
|
||||
var thisPropsContentType = typeof this.props.content;
|
||||
var thisPropsContentEmpty =
|
||||
this.props.content == null || thisPropsContentType === 'boolean';
|
||||
var nextPropsContentType = typeof nextProps.content;
|
||||
var nextPropsContentEmpty =
|
||||
nextProps.content == null || nextPropsContentType === 'boolean';
|
||||
|
||||
var lastUsedContent = !thisPropsContentEmpty ? this.props.content :
|
||||
var lastUsedContent =
|
||||
CONTENT_TYPES[typeof this.props.children] ? this.props.children : null;
|
||||
|
||||
var contentToUse = !nextPropsContentEmpty ? nextProps.content :
|
||||
var contentToUse =
|
||||
CONTENT_TYPES[typeof nextProps.children] ? nextProps.children : null;
|
||||
|
||||
// Note the use of `!=` which checks for null or undefined.
|
||||
|
||||
@@ -33,8 +33,8 @@ describe('ReactDOMIDOperations', function() {
|
||||
expect(function() {
|
||||
ReactDOMIDOperations.updatePropertyByID(
|
||||
'testID',
|
||||
keyOf({content: null}),
|
||||
'testContent'
|
||||
keyOf({dangerouslySetInnerHTML: null}),
|
||||
{__html: 'testContent'}
|
||||
);
|
||||
}).toThrow();
|
||||
|
||||
|
||||
@@ -71,10 +71,6 @@ var assertSingleChild = function(instance, text) {
|
||||
};
|
||||
|
||||
// Helpers
|
||||
var renderSingleContentChild = function(text) {
|
||||
var d = ReactTestUtils.renderIntoDocument(<div content={text} />);
|
||||
return d;
|
||||
};
|
||||
var renderSingleTextChild = function(text) {
|
||||
var d = ReactTestUtils.renderIntoDocument(<div>{text}</div>);
|
||||
return d;
|
||||
@@ -158,11 +154,6 @@ describe('ReactMultiChildText', function() {
|
||||
assertMultiChild(d, 'hello', 'goodbye');
|
||||
});
|
||||
|
||||
it('should render content to single text node', function() {
|
||||
var d = renderSingleContentChild('hello');
|
||||
assertNodeText(d, 'hello');
|
||||
});
|
||||
|
||||
it('should render a single text child to a single text node', function() {
|
||||
var d = renderSingleTextChild('hello');
|
||||
assertNodeText(d, 'hello');
|
||||
@@ -234,12 +225,6 @@ describe('ReactMultiChildText', function() {
|
||||
assertNodeText(d, '0');
|
||||
});
|
||||
|
||||
it('should render content number zero as text node', function() {
|
||||
var d = renderSingleContentChild(0);
|
||||
// false should act exactly as a null child
|
||||
assertNodeText(d, '0');
|
||||
});
|
||||
|
||||
it('should render zero string as string child', function() {
|
||||
var d = renderMultipleTextChildren('0', 234.2);
|
||||
// false should act exactly as a null child
|
||||
@@ -250,7 +235,7 @@ describe('ReactMultiChildText', function() {
|
||||
var d = renderMultipleTextChildren('0', 234.2);
|
||||
// false should act exactly as a null child
|
||||
assertMultiChild(d, '0', '234.2');
|
||||
d.replaceProps({content: '0'});
|
||||
d.replaceProps({children: '0'});
|
||||
assertNodeText(d, '0');
|
||||
});
|
||||
|
||||
@@ -258,7 +243,7 @@ describe('ReactMultiChildText', function() {
|
||||
var d = renderMultipleTextChildren(0, 234.2);
|
||||
// false should act exactly as a null child
|
||||
assertMultiChild(d, '0', '234.2');
|
||||
d.replaceProps({content: 0});
|
||||
d.replaceProps({children: 0});
|
||||
// BELOW REVEALS A BUG IN JSDOM
|
||||
// assertNodeText(d, '0'); // This works in the browser.
|
||||
});
|
||||
@@ -266,7 +251,7 @@ describe('ReactMultiChildText', function() {
|
||||
it('should render multiple children then switch to inline', function() {
|
||||
var d = renderMultipleTextChildren('hello', 'goodbye');
|
||||
assertMultiChild(d, 'hello', 'goodbye');
|
||||
d.replaceProps({content: 'hello'});
|
||||
d.replaceProps({children: 'hello'});
|
||||
assertNodeText(d, 'hello');
|
||||
});
|
||||
|
||||
@@ -286,13 +271,6 @@ describe('ReactMultiChildText', function() {
|
||||
assertMultiChild(d, 'hello', 'goodbye');
|
||||
});
|
||||
|
||||
it('should render content, then switch to text components ', function() {
|
||||
var d = renderSingleContentChild('hello');
|
||||
assertNodeText(d, 'hello');
|
||||
d.replaceProps({children: ['hello', 'goodbye']});
|
||||
assertMultiChild(d, 'hello', 'goodbye');
|
||||
});
|
||||
|
||||
it('should render inline child, then switch to composite', function() {
|
||||
var d = renderSingleTextChild('hello');
|
||||
assertNodeText(d, 'hello');
|
||||
@@ -302,9 +280,11 @@ describe('ReactMultiChildText', function() {
|
||||
.toBeCompositeComponentWithType(TestCompositeComponent);
|
||||
});
|
||||
|
||||
it('should throw if rendering both content and children', function() {
|
||||
it('should throw if rendering both HTML and children', function() {
|
||||
expect(function() {
|
||||
ReactTestUtils.renderIntoDocument(<div content="asdf">ghjkl</div>);
|
||||
ReactTestUtils.renderIntoDocument(
|
||||
<div dangerouslySetInnerHTML={{_html: 'abcdef'}}>ghjkl</div>
|
||||
);
|
||||
}).toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -292,25 +292,11 @@ describe('ReactNativeComponent', function() {
|
||||
});
|
||||
|
||||
it("should validate against multiple children props", function() {
|
||||
expect(function() {
|
||||
mountComponent({ content: '', children: '' });
|
||||
}).toThrow(
|
||||
'Invariant Violation: Can only set one of `children`, ' +
|
||||
'`props.content`, or `props.dangerouslySetInnerHTML`.'
|
||||
);
|
||||
|
||||
expect(function() {
|
||||
mountComponent({ content: '', dangerouslySetInnerHTML: '' });
|
||||
}).toThrow(
|
||||
'Invariant Violation: Can only set one of `children`, ' +
|
||||
'`props.content`, or `props.dangerouslySetInnerHTML`.'
|
||||
);
|
||||
|
||||
expect(function() {
|
||||
mountComponent({ children: '', dangerouslySetInnerHTML: '' });
|
||||
}).toThrow(
|
||||
'Invariant Violation: Can only set one of `children`, ' +
|
||||
'`props.content`, or `props.dangerouslySetInnerHTML`.'
|
||||
'Invariant Violation: Can only set one of `children` or ' +
|
||||
'`props.dangerouslySetInnerHTML`.'
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user