-
Notifications
You must be signed in to change notification settings - Fork 58
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
Add an option to make BuiltReduxUiComponent "pure" #140
Conversation
RavenNumber of Findings: 0MagpieNumber of findings: 0 |
Codecov Report
@@ 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 |
+10
|
@@ -85,6 +92,19 @@ abstract class BuiltReduxUiComponent< | |||
_tearDownSub(); | |||
} | |||
|
|||
@override |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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].
There was a problem hiding this comment.
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); | ||
}); |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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', () { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed
QA +1
Merging. |
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:
isPure
getter that, when returnstrue
, makes the component implementshouldComponentUpdate
and only redraw whenconnectedState
is changed.Testing suggestions:
Potential areas of regression: