Merge pull request #5859 from jimfb/clonewithprops

Removed cloneWithProps addon.
This commit is contained in:
Jim
2016-01-15 17:25:24 -08:00
4 changed files with 0 additions and 266 deletions
-5
View File
@@ -36,11 +36,6 @@ var addons = {
name: 'transition-group',
docs: 'animation',
},
cloneWithProps: {
module: 'cloneWithProps',
name: 'clone-with-props',
docs: 'clone-with-props',
},
createFragment: {
module: 'ReactFragment',
method: 'create',
-2
View File
@@ -27,7 +27,6 @@ var ReactFragment = require('ReactFragment');
var ReactTransitionGroup = require('ReactTransitionGroup');
var ReactUpdates = require('ReactUpdates');
var cloneWithProps = require('cloneWithProps');
var shallowCompare = require('shallowCompare');
var update = require('update');
var warning = require('warning');
@@ -51,7 +50,6 @@ React.addons = {
}
return ReactUpdates.batchedUpdates.apply(this, arguments);
},
cloneWithProps: cloneWithProps,
createFragment: ReactFragment.create,
shallowCompare: shallowCompare,
update: update,
@@ -1,196 +0,0 @@
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @emails react-core
*/
'use strict';
var React;
var ReactDOM;
var ReactTestUtils;
var onlyChild;
var cloneWithProps;
var emptyObject;
describe('cloneWithProps', function() {
beforeEach(function() {
jest.resetModuleRegistry();
React = require('React');
ReactDOM = require('ReactDOM');
ReactTestUtils = require('ReactTestUtils');
onlyChild = require('onlyChild');
cloneWithProps = require('cloneWithProps');
emptyObject = require('emptyObject');
spyOn(console, 'error');
});
it('should warn once because it is deprecated', function() {
var Parent = React.createClass({
render: function() {
return (
<div>
{cloneWithProps(onlyChild(this.props.children), {})}
</div>
);
},
});
ReactTestUtils.renderIntoDocument(<Parent><div /></Parent>);
ReactTestUtils.renderIntoDocument(<Parent><div /></Parent>);
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain(
'cloneWithProps(...) is deprecated. ' +
'Please use React.cloneElement instead.'
);
});
it('should clone a DOM component with new props', function() {
var Grandparent = React.createClass({
render: function() {
return <Parent><div className="child" /></Parent>;
},
});
var Parent = React.createClass({
render: function() {
return (
<div className="parent">
{cloneWithProps(onlyChild(this.props.children), {className: 'xyz'})}
</div>
);
},
});
var component = ReactTestUtils.renderIntoDocument(<Grandparent />);
expect(ReactDOM.findDOMNode(component).childNodes[0].className)
.toBe('xyz child');
});
it('should clone a composite component with new props', function() {
var Child = React.createClass({
render: function() {
return <div className={this.props.className} />;
},
});
var Grandparent = React.createClass({
render: function() {
return <Parent><Child className="child" /></Parent>;
},
});
var Parent = React.createClass({
render: function() {
return (
<div className="parent">
{cloneWithProps(onlyChild(this.props.children), {className: 'xyz'})}
</div>
);
},
});
var component = ReactTestUtils.renderIntoDocument(<Grandparent />);
expect(ReactDOM.findDOMNode(component).childNodes[0].className)
.toBe('xyz child');
});
it('should warn when cloning with refs', function() {
var Grandparent = React.createClass({
render: function() {
return <Parent><div ref="yolo" /></Parent>;
},
});
var Parent = React.createClass({
render: function() {
return (
<div>
{cloneWithProps(onlyChild(this.props.children), {className: 'xyz'})}
</div>
);
},
});
var component = ReactTestUtils.renderIntoDocument(<Grandparent />);
expect(component.refs).toBe(emptyObject);
expect(console.error.argsForCall.length).toBe(2);
});
it('should transfer the key property', function() {
var Component = React.createClass({
render: function() {
return null;
},
});
var clone = cloneWithProps(<Component />, {key: 'xyz'});
expect(clone.key).toBe('xyz');
});
it('should transfer children', function() {
var Component = React.createClass({
render: function() {
expect(this.props.children).toBe('xyz');
return <div />;
},
});
ReactTestUtils.renderIntoDocument(
cloneWithProps(<Component />, {children: 'xyz'})
);
});
it('should shallow clone children', function() {
var Component = React.createClass({
render: function() {
expect(this.props.children).toBe('xyz');
return <div />;
},
});
ReactTestUtils.renderIntoDocument(
cloneWithProps(<Component>xyz</Component>, {})
);
});
it('should support keys and refs', function() {
var Component = React.createClass({
render: function() {
return <div />;
},
});
var Parent = React.createClass({
render: function() {
var clone =
cloneWithProps(this.props.children, {key: 'xyz', ref: 'xyz'});
expect(clone.key).toBe('xyz');
expect(clone.ref).toBe('xyz');
return <div>{clone}</div>;
},
});
var Grandparent = React.createClass({
render: function() {
return <Parent><Component key="abc" /></Parent>;
},
});
ReactTestUtils.renderIntoDocument(<Grandparent />);
});
it('should overwrite props', function() {
var Component = React.createClass({
render: function() {
expect(this.props.myprop).toBe('xyz');
return <div />;
},
});
ReactTestUtils.renderIntoDocument(
cloneWithProps(<Component myprop="abc" />, {myprop: 'xyz'})
);
});
});
@@ -1,63 +0,0 @@
/**
* Copyright 2013-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @providesModule cloneWithProps
*/
'use strict';
var ReactElement = require('ReactElement');
var ReactPropTransferer = require('ReactPropTransferer');
var keyOf = require('keyOf');
var warning = require('warning');
var CHILDREN_PROP = keyOf({children: null});
var didDeprecatedWarn = false;
/**
* Sometimes you want to change the props of a child passed to you. Usually
* this is to add a CSS class.
*
* @param {ReactElement} child child element you'd like to clone
* @param {object} props props you'd like to modify. className and style will be
* merged automatically.
* @return {ReactElement} a clone of child with props merged in.
* @deprecated
*/
function cloneWithProps(child, props) {
if (__DEV__) {
warning(
didDeprecatedWarn,
'cloneWithProps(...) is deprecated. ' +
'Please use React.cloneElement instead.'
);
didDeprecatedWarn = true;
warning(
!child.ref,
'You are calling cloneWithProps() on a child with a ref. This is ' +
'dangerous because you\'re creating a new child which will not be ' +
'added as a ref to its parent.'
);
}
var newProps = ReactPropTransferer.mergeProps(props, child.props);
// Use `child.props.children` if it is provided.
if (!newProps.hasOwnProperty(CHILDREN_PROP) &&
child.props.hasOwnProperty(CHILDREN_PROP)) {
newProps.children = child.props.children;
}
// The current API doesn't retain _owner, which is why this
// doesn't use ReactElement.cloneAndReplaceProps.
return ReactElement.createElement(child.type, newProps);
}
module.exports = cloneWithProps;