Skip to content

Commit

Permalink
Run prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
flarnie committed Jun 7, 2017
1 parent f82d323 commit d8a2381
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 94 deletions.
55 changes: 24 additions & 31 deletions src/renderers/dom/client/__tests__/inputValueTracking-test.js
Expand Up @@ -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() {
Expand All @@ -49,7 +47,7 @@ describe('inputValueTracking', function() {
});

it('should initialize with the current value', function() {
input.value ='foo';
input.value = 'foo';

inputValueTracking.track(mockComponent);

Expand All @@ -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');
});

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -112,53 +110,48 @@ 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');
});

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);
});
Expand Down
55 changes: 18 additions & 37 deletions src/renderers/dom/client/eventPlugins/ChangeEventPlugin.js
Expand Up @@ -23,7 +23,6 @@ var getEventTarget = require('getEventTarget');
var isEventSupported = require('isEventSupported');
var isTextInputElement = require('isTextInputElement');


var eventTypes = {
change: {
phasedRegistrationNames: {
Expand All @@ -48,7 +47,7 @@ function createAndAccumulateChangeEvent(inst, nativeEvent, target) {
eventTypes.change,
inst,
nativeEvent,
target
target,
);
event.type = 'change';
EventPropagators.accumulateTwoPhaseDispatches(event);
Expand All @@ -60,8 +59,6 @@ function createAndAccumulateChangeEvent(inst, nativeEvent, target) {
var activeElement = null;
var activeElementInst = null;



/**
* SECTION: handle `change` event
*/
Expand Down Expand Up @@ -121,21 +118,18 @@ 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;
}
}

function getTargetInstForChangeEvent(topLevelType, targetInst) {

if (topLevelType === 'topChange') {
return targetInst;
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
//
Expand All @@ -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);
}
Expand All @@ -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);
}
}
Expand Down
Expand Up @@ -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);
Expand All @@ -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';
Expand All @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit d8a2381

Please sign in to comment.