diff --git a/grunt/tasks/npm-react-addons.js b/grunt/tasks/npm-react-addons.js index 67bbf783b8a52..238fefc60bdac 100644 --- a/grunt/tasks/npm-react-addons.js +++ b/grunt/tasks/npm-react-addons.js @@ -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', diff --git a/src/addons/ReactWithAddons.js b/src/addons/ReactWithAddons.js index b9a8004dd8c30..d3cf053a25fee 100644 --- a/src/addons/ReactWithAddons.js +++ b/src/addons/ReactWithAddons.js @@ -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, diff --git a/src/isomorphic/deprecated/__tests__/cloneWithProps-test.js b/src/isomorphic/deprecated/__tests__/cloneWithProps-test.js deleted file mode 100644 index 1b9602689587e..0000000000000 --- a/src/isomorphic/deprecated/__tests__/cloneWithProps-test.js +++ /dev/null @@ -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 ( -
- {cloneWithProps(onlyChild(this.props.children), {})} -
- ); - }, - }); - ReactTestUtils.renderIntoDocument(
); - ReactTestUtils.renderIntoDocument(
); - 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
; - }, - }); - var Parent = React.createClass({ - render: function() { - return ( -
- {cloneWithProps(onlyChild(this.props.children), {className: 'xyz'})} -
- ); - }, - }); - var component = ReactTestUtils.renderIntoDocument(); - 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
; - }, - }); - - var Grandparent = React.createClass({ - render: function() { - return ; - }, - }); - var Parent = React.createClass({ - render: function() { - return ( -
- {cloneWithProps(onlyChild(this.props.children), {className: 'xyz'})} -
- ); - }, - }); - var component = ReactTestUtils.renderIntoDocument(); - 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
; - }, - }); - var Parent = React.createClass({ - render: function() { - return ( -
- {cloneWithProps(onlyChild(this.props.children), {className: 'xyz'})} -
- ); - }, - }); - - var component = ReactTestUtils.renderIntoDocument(); - 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(, {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
; - }, - }); - - ReactTestUtils.renderIntoDocument( - cloneWithProps(, {children: 'xyz'}) - ); - }); - - it('should shallow clone children', function() { - var Component = React.createClass({ - render: function() { - expect(this.props.children).toBe('xyz'); - return
; - }, - }); - - ReactTestUtils.renderIntoDocument( - cloneWithProps(xyz, {}) - ); - }); - - it('should support keys and refs', function() { - var Component = React.createClass({ - render: function() { - return
; - }, - }); - - 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
{clone}
; - }, - }); - - var Grandparent = React.createClass({ - render: function() { - return ; - }, - }); - - ReactTestUtils.renderIntoDocument(); - }); - - it('should overwrite props', function() { - var Component = React.createClass({ - render: function() { - expect(this.props.myprop).toBe('xyz'); - return
; - }, - }); - - ReactTestUtils.renderIntoDocument( - cloneWithProps(, {myprop: 'xyz'}) - ); - }); -}); diff --git a/src/isomorphic/deprecated/cloneWithProps.js b/src/isomorphic/deprecated/cloneWithProps.js deleted file mode 100644 index 5504d829272de..0000000000000 --- a/src/isomorphic/deprecated/cloneWithProps.js +++ /dev/null @@ -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;