Deprecate isValidClass

Fixes #2374
This commit is contained in:
Sebastian Markbage
2014-10-19 23:55:57 -07:00
parent daf4182707
commit ef971014bc
4 changed files with 32 additions and 7 deletions

View File

@@ -108,10 +108,6 @@ describe('ReactDOM', function() {
expect(dog.className).toBe('bigdog');
});
it('should be a valid class', function() {
expect(React.isValidClass(ReactDOM.div)).toBe(false);
});
it('allow React.DOM factories to be called without warnings', function() {
spyOn(console, 'warn');
var element = React.DOM.div();

View File

@@ -77,7 +77,7 @@ var React = {
renderToString: ReactServerRendering.renderToString,
renderToStaticMarkup: ReactServerRendering.renderToStaticMarkup,
unmountComponentAtNode: ReactMount.unmountComponentAtNode,
isValidClass: ReactLegacyElement.isValidFactory,
isValidClass: ReactLegacyElement.isValidClass,
isValidElement: ReactElement.isValidElement,
withContext: ReactContext.withContext,

View File

@@ -227,6 +227,17 @@ ReactLegacyElementFactory.isValidFactory = function(factory) {
factory.isReactLegacyFactory === LEGACY_MARKER;
};
ReactLegacyElementFactory.isValidClass = function(factory) {
if (__DEV__) {
warning(
false,
'isValidClass is deprecated and will be removed in a future release. ' +
'Use a more specific validator instead.'
);
}
return ReactLegacyElementFactory.isValidFactory(factory);
};
ReactLegacyElementFactory._isLegacyCallWarningEnabled = true;
module.exports = ReactLegacyElementFactory;

View File

@@ -878,7 +878,10 @@ describe('ReactCompositeComponent', function() {
expect(ReactMount.purgeID.callCount).toBe(4);
});
it('should detect valid CompositeComponent classes', function() {
it('should warn but detect valid CompositeComponent classes', function() {
var warn = console.warn;
console.warn = mocks.getMockFunction();
var Component = React.createClass({
render: function() {
return <div/>;
@@ -886,9 +889,17 @@ describe('ReactCompositeComponent', function() {
});
expect(React.isValidClass(Component)).toBe(true);
expect(console.warn.mock.calls.length).toBe(1);
expect(console.warn.mock.calls[0][0]).toContain(
'isValidClass is deprecated and will be removed in a future release'
);
});
it('should detect invalid CompositeComponent classes', function() {
it('should warn but detect invalid CompositeComponent classes', function() {
var warn = console.warn;
console.warn = mocks.getMockFunction();
var FnComponent = function() {
return false;
};
@@ -903,6 +914,13 @@ describe('ReactCompositeComponent', function() {
expect(React.isValidClass(FnComponent)).toBe(false);
expect(React.isValidClass(NullComponent)).toBe(false);
expect(React.isValidClass(TrickFnComponent)).toBe(false);
expect(console.warn.mock.calls.length).toBe(3);
console.warn.mock.calls.forEach(function(call) {
expect(call[0]).toContain(
'isValidClass is deprecated and will be removed in a future release'
);
});
});
it('should warn when shouldComponentUpdate() returns undefined', function() {