From 7bbe9d134a0d09fd33c4cf0f8d316b34550fdca4 Mon Sep 17 00:00:00 2001 From: Brandon Dail Date: Mon, 23 Jan 2017 18:05:59 -0600 Subject: [PATCH 1/4] Deprecate React.createMixin This API was never fully implemented. Since mixins are no longer considered part of the future React API, it will be removed. --- src/isomorphic/React.js | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/isomorphic/React.js b/src/isomorphic/React.js index c791b30e08cf0..5b6fb2d4674a2 100644 --- a/src/isomorphic/React.js +++ b/src/isomorphic/React.js @@ -35,20 +35,35 @@ if (__DEV__) { } var __spread = Object.assign; +var createMixin = function(mixin) { + return mixin; +}; if (__DEV__) { - var warned = false; + var warnedForSpread = false; + var warnedForCreateMixin = false; __spread = function() { warning( - warned, + warnedForSpread, 'React.__spread is deprecated and should not be used. Use ' + 'Object.assign directly or another helper function with similar ' + 'semantics. You may be seeing this warning due to your compiler. ' + 'See https://fb.me/react-spread-deprecation for more details.' ); - warned = true; + warnedForSpread = true; return Object.assign.apply(null, arguments); }; + + createMixin = function(mixin) { + warning( + warnedForCreateMixin, + 'React.createMixin is deprecated and should not be used. You ' + + 'can use your mixin directly instead.' + ); + warnedForCreateMixin = true; + return mixin; + }; + } var React = { @@ -75,10 +90,7 @@ var React = { PropTypes: ReactPropTypes, createClass: ReactClass.createClass, createFactory: createFactory, - createMixin: function(mixin) { - // Currently a noop. Will be used to validate and trace mixins. - return mixin; - }, + createMixin: createMixin, // This looks DOM specific but these are actually isomorphic helpers // since they are just generating DOM strings. From a4bc6a4860c79b93e7d0045366710670831ebf3d Mon Sep 17 00:00:00 2001 From: Brandon Dail Date: Mon, 23 Jan 2017 18:07:00 -0600 Subject: [PATCH 2/4] Add test for deprecation warnings --- src/isomorphic/__tests__/React-test.js | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 src/isomorphic/__tests__/React-test.js diff --git a/src/isomorphic/__tests__/React-test.js b/src/isomorphic/__tests__/React-test.js new file mode 100644 index 0000000000000..a101a1aecfa58 --- /dev/null +++ b/src/isomorphic/__tests__/React-test.js @@ -0,0 +1,42 @@ +/** + * 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'; + +describe('React', () => { + + var React; + + beforeEach(() => { + React = require('React'); + }); + + it('should log a deprecation warning once when using React.__spread', () => { + spyOn(console, 'error'); + React.__spread({}); + React.__spread({}); + expectDev(console.error.calls.count()).toBe(1); + expectDev(console.error.calls.argsFor(0)[0]).toContain( + 'React.__spread is deprecated and should not be used' + ); + }); + + it('should log a deprecation warning once when using React.createMixin', () => { + spyOn(console, 'error'); + React.createMixin(); + React.createMixin(); + expectDev(console.error.calls.count()).toBe(1); + expectDev(console.error.calls.argsFor(0)[0]).toContain( + 'React.createMixin is deprecated and should not be used' + ); + }); + +}); From 9193120c67827175d8b992e47669da41c9c248a9 Mon Sep 17 00:00:00 2001 From: Brandon Dail Date: Mon, 23 Jan 2017 18:21:59 -0600 Subject: [PATCH 3/4] Add deprecation tests to fiber test tracker --- scripts/fiber/tests-passing.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/scripts/fiber/tests-passing.txt b/scripts/fiber/tests-passing.txt index 27e9536aa43ac..050dd41e1b504 100644 --- a/scripts/fiber/tests-passing.txt +++ b/scripts/fiber/tests-passing.txt @@ -108,6 +108,10 @@ src/addons/transitions/__tests__/ReactTransitionGroup-test.js * should handle entering/leaving several elements at once * should warn for duplicated keys +src/isomorphic/__tests__/React-test.js +* should log a deprecation warning once when using React.__spread +* should log a deprecation warning once when using React.createMixin + src/isomorphic/children/__tests__/ReactChildren-test.js * should support identity for simple * should treat single arrayless child as being in array From 2d6c2827e8133383f98a9387d29d94cbcccdc7ac Mon Sep 17 00:00:00 2001 From: Brandon Dail Date: Mon, 23 Jan 2017 19:42:28 -0600 Subject: [PATCH 4/4] Update deprecation wording to be less aggressive --- src/isomorphic/React.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/isomorphic/React.js b/src/isomorphic/React.js index 5b6fb2d4674a2..bdeb08e864372 100644 --- a/src/isomorphic/React.js +++ b/src/isomorphic/React.js @@ -58,7 +58,7 @@ if (__DEV__) { warning( warnedForCreateMixin, 'React.createMixin is deprecated and should not be used. You ' + - 'can use your mixin directly instead.' + 'can use this mixin directly instead.' ); warnedForCreateMixin = true; return mixin;