mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Run prettier
This commit is contained in:
@@ -22,23 +22,21 @@ describe('inputValueTracking', function() {
|
||||
input.type = 'text';
|
||||
checkbox = document.createElement('input');
|
||||
checkbox.type = 'checkbox';
|
||||
mockComponent = { _hostNode: input, _wrapperState: {} };
|
||||
mockComponent = {_hostNode: input, _wrapperState: {}};
|
||||
});
|
||||
|
||||
it('should attach tracker to wrapper state', function() {
|
||||
inputValueTracking.track(mockComponent);
|
||||
|
||||
expect(
|
||||
mockComponent._wrapperState.hasOwnProperty('valueTracker')
|
||||
).toBe(true);
|
||||
expect(mockComponent._wrapperState.hasOwnProperty('valueTracker')).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
|
||||
it('should define `value` on the instance node', function() {
|
||||
inputValueTracking.track(mockComponent);
|
||||
|
||||
expect(
|
||||
input.hasOwnProperty('value')
|
||||
).toBe(true);
|
||||
expect(input.hasOwnProperty('value')).toBe(true);
|
||||
});
|
||||
|
||||
it('should define `checked` on the instance node', function() {
|
||||
@@ -49,7 +47,7 @@ describe('inputValueTracking', function() {
|
||||
});
|
||||
|
||||
it('should initialize with the current value', function() {
|
||||
input.value ='foo';
|
||||
input.value = 'foo';
|
||||
|
||||
inputValueTracking.track(mockComponent);
|
||||
|
||||
@@ -69,13 +67,13 @@ describe('inputValueTracking', function() {
|
||||
});
|
||||
|
||||
it('should track value changes', function() {
|
||||
input.value ='foo';
|
||||
input.value = 'foo';
|
||||
|
||||
inputValueTracking.track(mockComponent);
|
||||
|
||||
var tracker = mockComponent._wrapperState.valueTracker;
|
||||
|
||||
input.value ='bar';
|
||||
input.value = 'bar';
|
||||
expect(tracker.getValue()).toEqual('bar');
|
||||
});
|
||||
|
||||
@@ -91,7 +89,7 @@ describe('inputValueTracking', function() {
|
||||
});
|
||||
|
||||
it('should update value manually', function() {
|
||||
input.value ='foo';
|
||||
input.value = 'foo';
|
||||
inputValueTracking.track(mockComponent);
|
||||
|
||||
var tracker = mockComponent._wrapperState.valueTracker;
|
||||
@@ -101,7 +99,7 @@ describe('inputValueTracking', function() {
|
||||
});
|
||||
|
||||
it('should coerce value to a string', function() {
|
||||
input.value ='foo';
|
||||
input.value = 'foo';
|
||||
inputValueTracking.track(mockComponent);
|
||||
|
||||
var tracker = mockComponent._wrapperState.valueTracker;
|
||||
@@ -112,37 +110,32 @@ describe('inputValueTracking', function() {
|
||||
|
||||
it('should update value if it changed and return result', function() {
|
||||
inputValueTracking.track(mockComponent);
|
||||
input.value ='foo';
|
||||
input.value = 'foo';
|
||||
|
||||
var tracker = mockComponent._wrapperState.valueTracker;
|
||||
|
||||
expect(
|
||||
inputValueTracking.updateValueIfChanged(mockComponent)
|
||||
).toBe(false);
|
||||
expect(inputValueTracking.updateValueIfChanged(mockComponent)).toBe(false);
|
||||
|
||||
tracker.setValue('bar');
|
||||
|
||||
expect(
|
||||
inputValueTracking.updateValueIfChanged(mockComponent)
|
||||
).toBe(true);
|
||||
expect(inputValueTracking.updateValueIfChanged(mockComponent)).toBe(true);
|
||||
|
||||
expect(tracker.getValue()).toEqual('foo');
|
||||
});
|
||||
|
||||
it('should track value and return true when updating untracked instance', function() {
|
||||
input.value ='foo';
|
||||
input.value = 'foo';
|
||||
|
||||
expect(
|
||||
inputValueTracking.updateValueIfChanged(mockComponent)
|
||||
)
|
||||
.toBe(true);
|
||||
expect(inputValueTracking.updateValueIfChanged(mockComponent)).toBe(true);
|
||||
|
||||
var tracker = mockComponent._wrapperState.valueTracker;
|
||||
expect(tracker.getValue()).toEqual('foo');
|
||||
});
|
||||
|
||||
it('should return tracker from node', function() {
|
||||
var node = ReactTestUtils.renderIntoDocument(<input type="text" defaultValue="foo" />);
|
||||
var node = ReactTestUtils.renderIntoDocument(
|
||||
<input type="text" defaultValue="foo" />,
|
||||
);
|
||||
var tracker = inputValueTracking._getTrackerFromNode(node);
|
||||
expect(tracker.getValue()).toEqual('foo');
|
||||
});
|
||||
@@ -150,15 +143,15 @@ describe('inputValueTracking', function() {
|
||||
it('should stop tracking', function() {
|
||||
inputValueTracking.track(mockComponent);
|
||||
|
||||
expect(
|
||||
mockComponent._wrapperState.hasOwnProperty('valueTracker')
|
||||
).toBe(true);
|
||||
expect(mockComponent._wrapperState.hasOwnProperty('valueTracker')).toBe(
|
||||
true,
|
||||
);
|
||||
|
||||
inputValueTracking.stopTracking(mockComponent);
|
||||
|
||||
expect(
|
||||
mockComponent._wrapperState.hasOwnProperty('valueTracker')
|
||||
).toBe(false);
|
||||
expect(mockComponent._wrapperState.hasOwnProperty('valueTracker')).toBe(
|
||||
false,
|
||||
);
|
||||
|
||||
expect(input.hasOwnProperty('value')).toBe(false);
|
||||
});
|
||||
|
||||
@@ -23,7 +23,6 @@ var getEventTarget = require('getEventTarget');
|
||||
var isEventSupported = require('isEventSupported');
|
||||
var isTextInputElement = require('isTextInputElement');
|
||||
|
||||
|
||||
var eventTypes = {
|
||||
change: {
|
||||
phasedRegistrationNames: {
|
||||
@@ -48,7 +47,7 @@ function createAndAccumulateChangeEvent(inst, nativeEvent, target) {
|
||||
eventTypes.change,
|
||||
inst,
|
||||
nativeEvent,
|
||||
target
|
||||
target,
|
||||
);
|
||||
event.type = 'change';
|
||||
EventPropagators.accumulateTwoPhaseDispatches(event);
|
||||
@@ -60,8 +59,6 @@ function createAndAccumulateChangeEvent(inst, nativeEvent, target) {
|
||||
var activeElement = null;
|
||||
var activeElementInst = null;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* SECTION: handle `change` event
|
||||
*/
|
||||
@@ -121,13 +118,11 @@ function stopWatchingForChangeEventIE8() {
|
||||
activeElementInst = null;
|
||||
}
|
||||
|
||||
|
||||
function getInstIfValueChanged(targetInst, nativeEvent) {
|
||||
var updated = inputValueTracking.updateValueIfChanged(targetInst);
|
||||
var simulated = (
|
||||
var simulated =
|
||||
nativeEvent.simulated === true &&
|
||||
ChangeEventPlugin._allowSimulatedPassThrough
|
||||
);
|
||||
ChangeEventPlugin._allowSimulatedPassThrough;
|
||||
|
||||
if (updated || simulated) {
|
||||
return targetInst;
|
||||
@@ -135,7 +130,6 @@ function getInstIfValueChanged(targetInst, nativeEvent) {
|
||||
}
|
||||
|
||||
function getTargetInstForChangeEvent(topLevelType, targetInst) {
|
||||
|
||||
if (topLevelType === 'topChange') {
|
||||
return targetInst;
|
||||
}
|
||||
@@ -160,13 +154,11 @@ if (ExecutionEnvironment.canUseDOM) {
|
||||
// IE9 claims to support the input event but fails to trigger it when
|
||||
// deleting text, so we ignore its input events.
|
||||
|
||||
isInputEventSupported = isEventSupported('input') && (
|
||||
!('documentMode' in document) || document.documentMode > 9
|
||||
);
|
||||
|
||||
isInputEventSupported =
|
||||
isEventSupported('input') &&
|
||||
(!('documentMode' in document) || document.documentMode > 9);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* (For IE <=9) Starts tracking propertychange events on the passed-in element
|
||||
* and override the value property so that we can distinguish user events from
|
||||
@@ -205,13 +197,7 @@ function handlePropertyChange(nativeEvent) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function handleEventsForInputEventPolyfill(
|
||||
topLevelType,
|
||||
target,
|
||||
targetInst
|
||||
) {
|
||||
|
||||
function handleEventsForInputEventPolyfill(topLevelType, target, targetInst) {
|
||||
if (topLevelType === 'topFocus') {
|
||||
// In IE8, we can capture almost all .value changes by adding a
|
||||
// propertychange handler and looking for events with propertyName
|
||||
@@ -237,11 +223,13 @@ function handleEventsForInputEventPolyfill(
|
||||
function getTargetInstForInputEventPolyfill(
|
||||
topLevelType,
|
||||
targetInst,
|
||||
nativeEvent
|
||||
nativeEvent,
|
||||
) {
|
||||
if (topLevelType === 'topSelectionChange' ||
|
||||
topLevelType === 'topKeyUp' ||
|
||||
topLevelType === 'topKeyDown') {
|
||||
if (
|
||||
topLevelType === 'topSelectionChange' ||
|
||||
topLevelType === 'topKeyUp' ||
|
||||
topLevelType === 'topKeyDown'
|
||||
) {
|
||||
// On the selectionchange event, the target is just document which isn't
|
||||
// helpful for us so just check activeElement instead.
|
||||
//
|
||||
@@ -265,17 +253,13 @@ function shouldUseClickEvent(elem) {
|
||||
// until `blur` in IE8.
|
||||
var nodeName = elem.nodeName;
|
||||
return (
|
||||
(nodeName && nodeName.toLowerCase() === 'input') &&
|
||||
nodeName &&
|
||||
nodeName.toLowerCase() === 'input' &&
|
||||
(elem.type === 'checkbox' || elem.type === 'radio')
|
||||
);
|
||||
}
|
||||
|
||||
function getTargetInstForClickEvent(
|
||||
topLevelType,
|
||||
targetInst,
|
||||
nativeEvent
|
||||
) {
|
||||
|
||||
function getTargetInstForClickEvent(topLevelType, targetInst, nativeEvent) {
|
||||
if (topLevelType === 'topClick') {
|
||||
return getInstIfValueChanged(targetInst, nativeEvent);
|
||||
}
|
||||
@@ -284,12 +268,9 @@ function getTargetInstForClickEvent(
|
||||
function getTargetInstForInputOrChangeEvent(
|
||||
topLevelType,
|
||||
targetInst,
|
||||
nativeEvent
|
||||
nativeEvent,
|
||||
) {
|
||||
if (
|
||||
topLevelType === 'topInput' ||
|
||||
topLevelType === 'topChange'
|
||||
) {
|
||||
if (topLevelType === 'topInput' || topLevelType === 'topChange') {
|
||||
return getInstIfValueChanged(targetInst, nativeEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,9 @@ describe('ChangeEventPlugin', () => {
|
||||
expect(e.type).toBe('change');
|
||||
}
|
||||
|
||||
var input = ReactTestUtils.renderIntoDocument(<input type="checkbox" onChange={cb}/>);
|
||||
var input = ReactTestUtils.renderIntoDocument(
|
||||
<input type="checkbox" onChange={cb} />,
|
||||
);
|
||||
|
||||
setUntrackedValue(input, true);
|
||||
ReactTestUtils.SimulateNative.click(input);
|
||||
@@ -66,7 +68,7 @@ describe('ChangeEventPlugin', () => {
|
||||
|
||||
it('should catch setting the value programmatically', function() {
|
||||
var input = ReactTestUtils.renderIntoDocument(
|
||||
<input type="text" defaultValue="foo"/>
|
||||
<input type="text" defaultValue="foo" />,
|
||||
);
|
||||
|
||||
input.value = 'bar';
|
||||
@@ -82,7 +84,7 @@ describe('ChangeEventPlugin', () => {
|
||||
}
|
||||
|
||||
var input = ReactTestUtils.renderIntoDocument(
|
||||
<input type="text" onChange={cb} defaultValue="foo"/>
|
||||
<input type="text" onChange={cb} defaultValue="foo" />,
|
||||
);
|
||||
|
||||
input.value = 'bar';
|
||||
@@ -104,7 +106,7 @@ describe('ChangeEventPlugin', () => {
|
||||
}
|
||||
|
||||
var input = ReactTestUtils.renderIntoDocument(
|
||||
<input type="checkbox" onChange={cb} defaultChecked={true} />
|
||||
<input type="checkbox" onChange={cb} defaultChecked={true} />,
|
||||
);
|
||||
|
||||
input.checked = true;
|
||||
@@ -132,7 +134,9 @@ describe('ChangeEventPlugin', () => {
|
||||
called += 1;
|
||||
}
|
||||
|
||||
var input = ReactTestUtils.renderIntoDocument(<input type="radio" onChange={cb}/>);
|
||||
var input = ReactTestUtils.renderIntoDocument(
|
||||
<input type="radio" onChange={cb} />,
|
||||
);
|
||||
setUntrackedValue(input, true);
|
||||
ReactTestUtils.SimulateNative.click(input);
|
||||
ReactTestUtils.SimulateNative.click(input);
|
||||
@@ -149,9 +153,9 @@ describe('ChangeEventPlugin', () => {
|
||||
}
|
||||
|
||||
[
|
||||
<input type="text" onChange={cb}/>,
|
||||
<input type="number" onChange={cb}/>,
|
||||
<input type="range" onChange={cb}/>,
|
||||
<input type="text" onChange={cb} />,
|
||||
<input type="number" onChange={cb} />,
|
||||
<input type="range" onChange={cb} />,
|
||||
].forEach(function(element) {
|
||||
called = 0;
|
||||
input = ReactTestUtils.renderIntoDocument(element);
|
||||
@@ -189,7 +193,9 @@ describe('ChangeEventPlugin', () => {
|
||||
return;
|
||||
}
|
||||
|
||||
var input = ReactTestUtils.renderIntoDocument(<input type="range" onChange={cb}/>);
|
||||
var input = ReactTestUtils.renderIntoDocument(
|
||||
<input type="range" onChange={cb} />,
|
||||
);
|
||||
setUntrackedValue(input, 'bar');
|
||||
|
||||
ReactTestUtils.SimulateNative.input(input);
|
||||
@@ -209,7 +215,9 @@ describe('ChangeEventPlugin', () => {
|
||||
expect(e.type).toBe('change');
|
||||
}
|
||||
|
||||
var input = ReactTestUtils.renderIntoDocument(<input type="range" onChange={cb}/>);
|
||||
var input = ReactTestUtils.renderIntoDocument(
|
||||
<input type="range" onChange={cb} />,
|
||||
);
|
||||
setUntrackedValue(input, '40');
|
||||
ReactTestUtils.SimulateNative.input(input);
|
||||
ReactTestUtils.SimulateNative.change(input);
|
||||
|
||||
@@ -16,7 +16,8 @@ function isCheckable(elem) {
|
||||
var type = elem.type;
|
||||
var nodeName = elem.nodeName;
|
||||
return (
|
||||
(nodeName && nodeName.toLowerCase() === 'input') &&
|
||||
nodeName &&
|
||||
nodeName.toLowerCase() === 'input' &&
|
||||
(type === 'checkbox' || type === 'radio')
|
||||
);
|
||||
}
|
||||
@@ -36,9 +37,7 @@ function detachTracker(inst) {
|
||||
function getValueFromNode(node) {
|
||||
var value;
|
||||
if (node) {
|
||||
value = isCheckable(node)
|
||||
? '' + node.checked
|
||||
: node.value;
|
||||
value = isCheckable(node) ? '' + node.checked : node.value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
@@ -46,9 +45,7 @@ function getValueFromNode(node) {
|
||||
var inputValueTracking = {
|
||||
// exposed for testing
|
||||
_getTrackerFromNode(node) {
|
||||
return getTracker(
|
||||
ReactDOMComponentTree.getInstanceFromNode(node)
|
||||
);
|
||||
return getTracker(ReactDOMComponentTree.getInstanceFromNode(node));
|
||||
},
|
||||
|
||||
track: function(inst) {
|
||||
@@ -60,7 +57,7 @@ var inputValueTracking = {
|
||||
var valueField = isCheckable(node) ? 'checked' : 'value';
|
||||
var descriptor = Object.getOwnPropertyDescriptor(
|
||||
node.constructor.prototype,
|
||||
valueField
|
||||
valueField,
|
||||
);
|
||||
|
||||
var currentValue = '' + node[valueField];
|
||||
@@ -111,7 +108,7 @@ var inputValueTracking = {
|
||||
|
||||
var lastValue = tracker.getValue();
|
||||
var nextValue = getValueFromNode(
|
||||
ReactDOMComponentTree.getNodeFromInstance(inst)
|
||||
ReactDOMComponentTree.getNodeFromInstance(inst),
|
||||
);
|
||||
|
||||
if (nextValue !== lastValue) {
|
||||
|
||||
@@ -21,7 +21,6 @@ describe('ReactDOMInput', () => {
|
||||
var ReactLink;
|
||||
var ReactTestUtils;
|
||||
|
||||
|
||||
beforeEach(() => {
|
||||
jest.resetModuleRegistry();
|
||||
React = require('React');
|
||||
|
||||
@@ -916,10 +916,12 @@ describe('ReactDOMComponent', () => {
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
it('should track input values', function() {
|
||||
var container = document.createElement('div');
|
||||
var inst = ReactDOM.render(<input type="text" defaultValue="foo"/>, container);
|
||||
var inst = ReactDOM.render(
|
||||
<input type="text" defaultValue="foo" />,
|
||||
container,
|
||||
);
|
||||
|
||||
var tracker = inputValueTracking._getTrackerFromNode(inst);
|
||||
|
||||
@@ -928,7 +930,7 @@ describe('ReactDOMComponent', () => {
|
||||
|
||||
it('should track textarea values', function() {
|
||||
var container = document.createElement('div');
|
||||
var inst = ReactDOM.render(<textarea defaultValue="foo"/>, container);
|
||||
var inst = ReactDOM.render(<textarea defaultValue="foo" />, container);
|
||||
|
||||
var tracker = inputValueTracking._getTrackerFromNode(inst);
|
||||
|
||||
@@ -1144,10 +1146,12 @@ describe('ReactDOMComponent', () => {
|
||||
expect(EventPluginHub.getListener(inst, 'onClick')).toBe(undefined);
|
||||
});
|
||||
|
||||
|
||||
it('should clean up input value tracking', function() {
|
||||
var container = document.createElement('div');
|
||||
var node = ReactDOM.render(<input type="text" defaultValue="foo"/>, container);
|
||||
var node = ReactDOM.render(
|
||||
<input type="text" defaultValue="foo" />,
|
||||
container,
|
||||
);
|
||||
var tracker = inputValueTracking._getTrackerFromNode(node);
|
||||
|
||||
spyOn(tracker, 'stopTracking');
|
||||
@@ -1159,7 +1163,7 @@ describe('ReactDOMComponent', () => {
|
||||
|
||||
it('should clean up input textarea tracking', function() {
|
||||
var container = document.createElement('div');
|
||||
var node = ReactDOM.render(<textarea defaultValue="foo"/>, container);
|
||||
var node = ReactDOM.render(<textarea defaultValue="foo" />, container);
|
||||
var tracker = inputValueTracking._getTrackerFromNode(node);
|
||||
|
||||
spyOn(tracker, 'stopTracking');
|
||||
|
||||
Reference in New Issue
Block a user