Skip to content

Commit

Permalink
1.3.1: improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-hur Santos Ott committed Feb 17, 2017
1 parent 6e5dda4 commit 4d5a36f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ var money = MaskService.toMask('money', '123', {


# Changelog
## 1.3.1
* Performance: adding check if the next value to be applied to the mask is equal as actual and prevent state change.

## 1.3.0
* Feat: now you can check and prevent input text on `TextInputMask` using `checkText` prop.

Expand Down
26 changes: 18 additions & 8 deletions lib/base-text-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,17 @@ export default class BaseTextComponent extends Component {

return new Promise((resolve, reject) => {
let maskedText = self._getMaskedValue(text);
self.setState({
value: maskedText
}, () => {
resolve(maskedText);
});

if(self._mustUpdateValue(maskedText)) {
self.setState({
value: maskedText
}, () => {
resolve(maskedText);
});
}
else {
resolve(this.state.value);
}
});
}

Expand All @@ -48,6 +54,10 @@ export default class BaseTextComponent extends Component {
);
}

_mustUpdateValue(newValue) {
return this.state.value !== newValue;
}

_resolveMaskHandler() {
this._maskHandler = MaskResolver.resolve(this.state.type);
}
Expand All @@ -63,7 +73,7 @@ export default class BaseTextComponent extends Component {
if(changeMaskHandler) {
self._resolveMaskHandler();
}

self.setState({
value: self._getMaskedValue(props.value)
});
Expand All @@ -72,7 +82,7 @@ export default class BaseTextComponent extends Component {

_getMaskedValue(value) {
return this._maskHandler.getValue(
this._getDefaultValue(value),
this._getDefaultValue(value),
this.state.options);
}

Expand All @@ -83,4 +93,4 @@ export default class BaseTextComponent extends Component {

return value;
}
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-masked-text",
"version": "1.3.0",
"version": "1.3.1",
"description": "Text and TextInput with mask for React Native applications",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 4d5a36f

Please sign in to comment.