Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added warning for use of ReactLink. #5032

Merged
merged 1 commit into from
Oct 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/renderers/dom/client/wrappers/ReactDOMInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ var ReactUpdates = require('ReactUpdates');

var assign = require('Object.assign');
var invariant = require('invariant');
var warning = require('warning');

var instancesByReactID = {};

var didWarnValueLink = false;
var didWarnCheckedLink = false;

function forceUpdateIfMounted() {
if (this._rootNodeID) {
// DOM component is still mounted; update
Expand Down Expand Up @@ -67,6 +71,21 @@ var ReactDOMInput = {
props,
inst._currentElement._owner
);

if (props.valueLink !== undefined && !didWarnValueLink) {
warning(
false,
'`valueLink` prop on `input` is deprecated; set `value` and `onChange` instead.'
);
didWarnValueLink = true;
}
if (props.checkedLink !== undefined && !didWarnCheckedLink) {
warning(
false,
'`checkedLink` prop on `input` is deprecated; set `value` and `onChange` instead.'
);
didWarnCheckedLink = true;
}
}

var defaultValue = props.defaultValue;
Expand Down
10 changes: 10 additions & 0 deletions src/renderers/dom/client/wrappers/ReactDOMSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ var ReactUpdates = require('ReactUpdates');
var assign = require('Object.assign');
var warning = require('warning');

var didWarnValueLink = false;

var valueContextKey =
'__ReactDOMSelect_value$' + Math.random().toString(36).slice(2);

Expand Down Expand Up @@ -58,6 +60,14 @@ function checkSelectPropTypes(inst, props) {
owner
);

if (props.valueLink !== undefined && !didWarnValueLink) {
warning(
false,
'`valueLink` prop on `select` is deprecated; set `value` and `onChange` instead.'
);
didWarnValueLink = true;
}

for (var i = 0; i < valuePropNames.length; i++) {
var propName = valuePropNames[i];
if (props[propName] == null) {
Expand Down
9 changes: 9 additions & 0 deletions src/renderers/dom/client/wrappers/ReactDOMTextarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ var assign = require('Object.assign');
var invariant = require('invariant');
var warning = require('warning');

var didWarnValueLink = false;

function forceUpdateIfMounted() {
if (this._rootNodeID) {
// DOM component is still mounted; update
Expand Down Expand Up @@ -67,6 +69,13 @@ var ReactDOMTextarea = {
props,
inst._currentElement._owner
);
if (props.valueLink !== undefined && !didWarnValueLink) {
warning(
false,
'`valueLink` prop on `textarea` is deprecated; set `value` and `onChange` instead.'
);
didWarnValueLink = true;
}
}

var defaultValue = props.defaultValue;
Expand Down
20 changes: 13 additions & 7 deletions src/renderers/dom/client/wrappers/__tests__/ReactDOMInput-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,17 @@ describe('ReactDOMInput', function() {
it('should warn with value and no onChange handler', function() {
var link = new ReactLink('yolo', mocks.getMockFunction());
ReactTestUtils.renderIntoDocument(<input type="text" valueLink={link} />);
expect(console.error.argsForCall.length).toBe(0);
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain(
'`valueLink` prop on `input` is deprecated; set `value` and `onChange` instead.'
);

ReactTestUtils.renderIntoDocument(
<input type="text" value="zoink" onChange={mocks.getMockFunction()} />
);
expect(console.error.argsForCall.length).toBe(0);
ReactTestUtils.renderIntoDocument(<input type="text" value="zoink" />);
expect(console.error.argsForCall.length).toBe(1);
ReactTestUtils.renderIntoDocument(<input type="text" value="zoink" />);
expect(console.error.argsForCall.length).toBe(2);
});

it('should warn with value and no onChange handler and readOnly specified', function() {
Expand Down Expand Up @@ -318,7 +321,10 @@ describe('ReactDOMInput', function() {
var node = document.createElement('div');
var link = new ReactLink(true, mocks.getMockFunction());
ReactDOM.render(<input type="checkbox" checkedLink={link} />, node);
expect(console.error.argsForCall.length).toBe(0);
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain(
'`checkedLink` prop on `input` is deprecated; set `value` and `onChange` instead.'
);

ReactTestUtils.renderIntoDocument(
<input
Expand All @@ -327,15 +333,15 @@ describe('ReactDOMInput', function() {
onChange={mocks.getMockFunction()}
/>
);
expect(console.error.argsForCall.length).toBe(0);
expect(console.error.argsForCall.length).toBe(1);

ReactTestUtils.renderIntoDocument(
<input type="checkbox" checked="false" readOnly={true} />
);
expect(console.error.argsForCall.length).toBe(0);
expect(console.error.argsForCall.length).toBe(1);

ReactTestUtils.renderIntoDocument(<input type="checkbox" checked="false" />);
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.argsForCall.length).toBe(2);
});

it('should warn with checked and no onChange handler with readOnly specified', function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,16 @@ describe('ReactDOMSelect', function() {
<option value="giraffe">A giraffe!</option>
<option value="gorilla">A gorilla!</option>
</select>;

spyOn(console, 'error');

stub = ReactTestUtils.renderIntoDocument(stub);

expect(console.error.argsForCall.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain(
'`valueLink` prop on `select` is deprecated; set `value` and `onChange` instead.'
);

var node = ReactDOM.findDOMNode(stub);

expect(node.options[0].selected).toBe(false); // monkey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,13 @@ describe('ReactDOMTextarea', function() {
var link = new ReactLink('yolo', mocks.getMockFunction());
var instance = <textarea valueLink={link} />;

spyOn(console, 'error');
instance = renderTextarea(instance);
expect(console.error.argsForCall.length).toBe(1);
expect(console.error.argsForCall[0][0]).toContain(
'`valueLink` prop on `textarea` is deprecated; set `value` and `onChange` instead.'
);


expect(ReactDOM.findDOMNode(instance).value).toBe('yolo');
expect(link.value).toBe('yolo');
Expand Down