Skip to content

Commit

Permalink
Added warning for use of ReactLink.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimfb committed Oct 2, 2015
1 parent 3606702 commit efc24b5
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 3 deletions.
11 changes: 11 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,12 @@ var ReactUpdates = require('ReactUpdates');

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

var instancesByReactID = {};

var didWarnValueLink = false;

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

if (props.valueLink !== undefined && !didWarnValueLink) {
warning(
false,
'`.valueLink` on `input` is deprecated; set `.value` and `.onChange` instead.'
);
didWarnValueLink = 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` 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` on `textarea` is deprecated; set `.value` and `.onChange` instead.'
);
didWarnValueLink = true;
}
}

var defaultValue = props.defaultValue;
Expand Down
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` 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
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` 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` on `textarea` is deprecated; set `.value` and `.onChange` instead.'
);


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

0 comments on commit efc24b5

Please sign in to comment.