-
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
UIP-2529 Add validateProps method to UiComponent #88
UIP-2529 Add validateProps method to UiComponent #88
Conversation
RavenNumber of Findings: 0 |
Codecov Report
@@ Coverage Diff @@
## master #88 +/- ##
==========================================
+ Coverage 94.86% 94.87% +0.01%
==========================================
Files 31 31
Lines 1536 1537 +1
==========================================
+ Hits 1457 1458 +1
Misses 79 79 |
+1 |
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.
Nice! It'll be awesome to have this.
/// | ||
/// Use this as an opportunity validate props during the correct lifecycle of the component. | ||
@mustCallSuper | ||
void validateProps([Map appliedProps]) { |
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.
I think this should be a required positional parameter, so that consumers don't have to null-coalesce the argument in overrides.
@@ -124,6 +124,16 @@ abstract class UiComponent<TProps extends UiProps> extends react.Component { | |||
); | |||
} | |||
|
|||
/// Validation method called during [componentWillReceiveProps], and [componentWillMount]. | |||
/// | |||
/// Use this as an opportunity validate props during the correct lifecycle of the component. |
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 I think this comment could be a little more descriptive.
/// Throws a [PropError] if [appliedProps] are invalid.
///
/// This is called automatically with during [componentWillReceiveProps] and [componentWillMount],
/// and can also be called manually for custom validation.
///
/// Override with a custom implementation to easily add validation (and don't forget to call super!)
///
/// @mustCallSuper
/// void validateProps(Map appliedProps) {
/// super.validateProps(appliedProps);
///
/// var tProps = typedPropsFactory(appliedProps);
/// if (tProps.items.length.isOdd) {
/// throw new PropError.value(tProps.items, 'items', 'must have an even number of items, because reasons');
/// }
/// }
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.
Good idea 👍
component.componentWillReceiveProps({}); | ||
|
||
expect(calls, ['onValidateProps']); | ||
}); |
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.
These should also test that the correct props maps are passed into them
@@ -124,6 +124,27 @@ abstract class UiComponent<TProps extends UiProps> extends react.Component { | |||
); | |||
} | |||
|
|||
/// Throws a [PropError] if [appliedProps] are invalid. | |||
/// | |||
/// This is called automatically with during [componentWillReceiveProps] and [componentWillMount], |
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.
This is called automatically with during
Sorry, my typo here.
What about:
This is called automatically with the latest props available during
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.
:stare:
Still +1 |
+1 |
@jacehensley-wf This pull request has merge conflicts, please resolve. |
…s_method/dev # Conflicts: # test/over_react/component_declaration/component_base_test.dart
+1 |
QA +10
Merging. |
Ultimate problem:
componentWillReceiveProps
andcomponentWillMount
.How it was fixed:
validateProps
method that is called automatically during those lifecycle methods.Testing suggestions:
Potential areas of regression: