Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement shouldComponentUpdate in some base components to limit rerenders #289

Merged
merged 8 commits into from
May 29, 2018

Conversation

pmuchowski
Copy link
Contributor

No description provided.

@pmuchowski pmuchowski changed the title gitkObpih 870 Implement shouldComponentUpdate in some base components to limit rerenders May 25, 2018
@awalkowiak
Copy link
Collaborator

awalkowiak commented May 28, 2018

@pmuchowski Actually i pulled those changes locally and I noticed that for ValueSelectorField column name (in ArrayField) is not displayed (the one that is set in componentConfig.label). Fix would be appreciated (i guess it should be placed right in specified field configuration - like type or attributes, instead inside componentConfig).

@pmuchowski
Copy link
Contributor Author

@awalkowiak I added the missing label

@@ -81,9 +81,25 @@ const PRODUCTS_MOCKS = [
{ value: '4', label: 'Similac Advance low iron 400g' },
];

const STOCK_LIST_ITEMS_MOCKS = {
1: [{ productCode: 1, maxQuantity: 10 },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The naming of this field doesn't really matter, I just wanted to point out that this is more like "default quantity" rather than "max quantity". In other words, the quantity value for the item will be set by this value, but it can be increased or decreased by the user.

}

shouldComponentUpdate(nextProps, nextState) {
if (this.state.touched !== nextState.touched) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain what this.state.touched is used for? Is this a way of detecting events that put focus on the component (like tabbing into a field or mouse click on the field)? Can you also explain this logic here? Is this saying as long as the next state isn't the same as the current state, we should update the component? In what scenario would the current state == next state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The touched property indicates if the element was visited (had focus), it's used in validation, the validation errors are displayed only when field is touched, so you don't have errors on every required field when displaying the form. By default React will update the component every time it will receive props even if those props was not changed. I'm using the shouldComponentUpdate method to limit rerenders and only do it when it's needed, because they are time consuming

@jmiranda jmiranda merged commit 1005169 into develop May 29, 2018
@pmuchowski pmuchowski deleted the OBPIH-870 branch May 30, 2018 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants