Skip to content

Commit ef97101

Browse files
committed
Deprecate isValidClass
Fixes facebook#2374
1 parent daf4182 commit ef97101

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

src/browser/__tests__/ReactDOM-test.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@ describe('ReactDOM', function() {
108108
expect(dog.className).toBe('bigdog');
109109
});
110110

111-
it('should be a valid class', function() {
112-
expect(React.isValidClass(ReactDOM.div)).toBe(false);
113-
});
114-
115111
it('allow React.DOM factories to be called without warnings', function() {
116112
spyOn(console, 'warn');
117113
var element = React.DOM.div();

src/browser/ui/React.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var React = {
7777
renderToString: ReactServerRendering.renderToString,
7878
renderToStaticMarkup: ReactServerRendering.renderToStaticMarkup,
7979
unmountComponentAtNode: ReactMount.unmountComponentAtNode,
80-
isValidClass: ReactLegacyElement.isValidFactory,
80+
isValidClass: ReactLegacyElement.isValidClass,
8181
isValidElement: ReactElement.isValidElement,
8282
withContext: ReactContext.withContext,
8383

src/core/ReactLegacyElement.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,17 @@ ReactLegacyElementFactory.isValidFactory = function(factory) {
227227
factory.isReactLegacyFactory === LEGACY_MARKER;
228228
};
229229

230+
ReactLegacyElementFactory.isValidClass = function(factory) {
231+
if (__DEV__) {
232+
warning(
233+
false,
234+
'isValidClass is deprecated and will be removed in a future release. ' +
235+
'Use a more specific validator instead.'
236+
);
237+
}
238+
return ReactLegacyElementFactory.isValidFactory(factory);
239+
};
240+
230241
ReactLegacyElementFactory._isLegacyCallWarningEnabled = true;
231242

232243
module.exports = ReactLegacyElementFactory;

src/core/__tests__/ReactCompositeComponent-test.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -878,17 +878,28 @@ describe('ReactCompositeComponent', function() {
878878
expect(ReactMount.purgeID.callCount).toBe(4);
879879
});
880880

881-
it('should detect valid CompositeComponent classes', function() {
881+
it('should warn but detect valid CompositeComponent classes', function() {
882+
var warn = console.warn;
883+
console.warn = mocks.getMockFunction();
884+
882885
var Component = React.createClass({
883886
render: function() {
884887
return <div/>;
885888
}
886889
});
887890

888891
expect(React.isValidClass(Component)).toBe(true);
892+
893+
expect(console.warn.mock.calls.length).toBe(1);
894+
expect(console.warn.mock.calls[0][0]).toContain(
895+
'isValidClass is deprecated and will be removed in a future release'
896+
);
889897
});
890898

891-
it('should detect invalid CompositeComponent classes', function() {
899+
it('should warn but detect invalid CompositeComponent classes', function() {
900+
var warn = console.warn;
901+
console.warn = mocks.getMockFunction();
902+
892903
var FnComponent = function() {
893904
return false;
894905
};
@@ -903,6 +914,13 @@ describe('ReactCompositeComponent', function() {
903914
expect(React.isValidClass(FnComponent)).toBe(false);
904915
expect(React.isValidClass(NullComponent)).toBe(false);
905916
expect(React.isValidClass(TrickFnComponent)).toBe(false);
917+
918+
expect(console.warn.mock.calls.length).toBe(3);
919+
console.warn.mock.calls.forEach(function(call) {
920+
expect(call[0]).toContain(
921+
'isValidClass is deprecated and will be removed in a future release'
922+
);
923+
});
906924
});
907925

908926
it('should warn when shouldComponentUpdate() returns undefined', function() {

0 commit comments

Comments
 (0)