Skip to content

Commit

Permalink
Reduce calls to onChange of the parent form.
Browse files Browse the repository at this point in the history
  • Loading branch information
amannn committed May 5, 2017
1 parent 8a1d9ec commit 6b1f7c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/FormsyText.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const FormsyText = React.createClass({

if (isValueChanging || this.props.defaultValue === this.getValue()) {
this.setState({ value, isValid });
this.setValue(value);
if (this.getValue() !== value) this.setValue(value);
}
}
},
Expand Down
14 changes: 14 additions & 0 deletions test/test.FormsyText.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,20 @@ describe('FormsyText', () => {
formValues = formsyForm.getCurrentValues();
expect(formValues.text).to.eq('some text');
});

it('calls onChange once per text update', () => {
const calls = [];
const { parent, formsyTextWrapper } = makeTestParent({
onChange: (...args) => calls.push(args),
value: 'initial',
});

const inputDOM = formsyTextWrapper.find('input').node;
inputDOM.value = 'updated';
parent.setState({ value: 'updated' });

expect(calls.length).to.eq(1);
});
});

describe('resetting to', () => {
Expand Down

0 comments on commit 6b1f7c9

Please sign in to comment.