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

Add an option to make BuiltReduxUiComponent "pure" #140

Conversation

jacehensley-wf
Copy link
Contributor

@jacehensley-wf jacehensley-wf commented Feb 16, 2018

Ultimate problem:

Implementing a "pure" component by extending BuiltReduxUiComponent proved to not be possible without making certain methods public and overridable.

How it was fixed:

  • Add an isPure getter that, when returns true, makes the component implement shouldComponentUpdate and only redraw when connectedState is changed.

Testing suggestions:

  • Verify tests pass
  • Verify this build passes.

Potential areas of regression:

  • None expected, all new logic is behind the new getter

FYA: @greglittlefield-wf @aaronlademann-wf @jacehensley-wf @clairesarsam-wf

@jacehensley-wf jacehensley-wf requested a review from a team as a code owner February 16, 2018 20:28
@aviary-wf
Copy link

Raven

Number of Findings: 0

Magpie

Number of findings: 0

@codecov-io
Copy link

codecov-io commented Feb 16, 2018

Codecov Report

Merging #140 into master will decrease coverage by 0.04%.
The diff coverage is 90%.

@@            Coverage Diff            @@
##           master    #140      +/-   ##
=========================================
- Coverage   94.54%   94.5%   -0.03%     
=========================================
  Files          33      33              
  Lines        1591    1599       +8     
=========================================
+ Hits         1504    1511       +7     
- Misses         87      88       +1

@brianbolton-wf
Copy link

+10

  • Improved speed in toolbar components

@@ -85,6 +92,19 @@ abstract class BuiltReduxUiComponent<
_tearDownSub();
}

@override
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this have a mustCallSuper?

@@ -145,6 +165,13 @@ abstract class BuiltReduxUiComponent<
/// Related: [connectedState]
Substate connect(V state);

/// Whether the component should be a "pure" component.
///
/// A "pure" component will only re-render when [connectedState] is updated or [redraw] is called directly.
Copy link
Contributor

Choose a reason for hiding this comment

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

Or when the store changes, right?

Should there also be a note showing usage of this? For example:

/// To enable this functionality, override this getter in a subclass to return `true`.
///
///  When using this, do not override [redraw] or [shouldComponentUpdate].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

component.redraw();

expect(component.numberOfRedraws, 2);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

There should also be a test that it updates as expected when props.store changes.


jacket.rerender((TestDefault()
..store = store
..id = 'new id'
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the purpose of this ID to change some unrelated props when rerendering? If so, it might be nice to call that out explicitly, perhaps in the reason of the next expect.

expect(component.numberOfRedraws, 1, 
    reason: 'should not redraw when rerendered, even if other props change');

expect(component.numberOfRedraws, 1);
});

test('when calling redraw', () {
Copy link
Contributor

Choose a reason for hiding this comment

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

#nit this looks like a duplicate test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed

@aaronlademann-wf
Copy link
Contributor

QA +1

  • Testing instruction
  • Dev +1's
  • Dev/QA +10
  • Unit tests created/updated
  • All unit tests pass
  • Rosie ran/Rosie comment displays expected info
  • Dependency Scan Clean

Merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants