@samitouri / QOS-React-2 / commits / 140d9b4192

Warn only once for each class when accessing .type

Currently it is a bit too spammy.

Sebastian Markbage committed Feb 5, 2015 at 12:32 UTC 140d9b4192d5399f032e26d17c3d78acf110f07d
2 files changed +18
src/classic/class/ReactClass.js
+3
@@ -714,6 +714,9 @@ var typeDeprecationDescriptor = {
714 displayName,
715 displayName
716 );
717 + Object.defineProperty(this, 'type', {
718 + value: this
719 + });
720 return this;
721 }
722 };
src/classic/class/__tests__/ReactClass-test.js
+15
@@ -50,12 +50,27 @@ describe('ReactClass-spec', function() {
50 return <div />;
51 }
52 });
53 + var SecondTestComponent = React.createClass({
54 + render: function() {
55 + return <div />;
56 + }
57 + });
58 expect(TestComponent.type).toBe(TestComponent);
59 expect(console.warn.argsForCall.length).toBe(1);
60 expect(console.warn.argsForCall[0][0]).toBe(
61 'Warning: TestComponent.type is deprecated. Use TestComponent ' +
62 'directly to access the class.'
63 );
64 + // Warn once per class
65 + expect(SecondTestComponent.type).toBe(SecondTestComponent);
66 + expect(console.warn.argsForCall.length).toBe(2);
67 + expect(console.warn.argsForCall[1][0]).toBe(
68 + 'Warning: SecondTestComponent.type is deprecated. Use ' +
69 + 'SecondTestComponent directly to access the class.'
70 + );
71 + // Not again
72 + expect(TestComponent.type).toBe(TestComponent);
73 + expect(console.warn.argsForCall.length).toBe(2);
74 });
75
76 it('should copy prop types onto the Constructor', function() {