-
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-1164 (OR): Provide easy access to DOM node in ValidationUtil.warn messages #60
UIP-1164 (OR): Provide easy access to DOM node in ValidationUtil.warn messages #60
Conversation
RavenNumber of Findings: 0 |
Codecov Report
@@ Coverage Diff @@
## master #60 +/- ##
==========================================
- Coverage 97.73% 97.67% -0.06%
==========================================
Files 28 28
Lines 1365 1372 +7
==========================================
+ Hits 1334 1340 +6
- Misses 31 32 +1 Continue to review full report at Codecov.
|
lib/src/util/validation_util.dart
Outdated
window.console.groupCollapsed('(Warning info)'); | ||
|
||
window.console.log(component); | ||
window.console.log('props: ${component.props}'); |
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.
Can we "pretty print" these props?
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.
UiProps.toString
has pretty-printing built in, so this will pretty-print them.
lib/src/util/validation_util.dart
Outdated
/// assert(ValidationUtil.warn('Some warning message', component)); | ||
/// | ||
/// The message will be printed out to the console. | ||
static bool warn(String message, [dynamic 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.
If we're expecting a component, we can type this to be react.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.
Hm, or I wonder if we should accept ReactElement
s as well (would we ever want to print just the child?)...
Could do something like:
static bool warn(String message, [dynamic data]) {
...
if (data != null) {
window.console.groupCollapsed('(Warning info)');
window.console.log(data);
if (isValidElement(data)) {
window.console.log('props: ${prettyPrintMap(getProps(data))}');
} else if (data is react.Component) {
window.console.log('props: ${prettyPrintMap(data.props)}');
}
}
...
}
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.
Not trying to move the goalposts of this PR, just putting it out there as an idea 😃.
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.
@greglittlefield-wf Do I need to use prettyPrintMap
in both cases? I thought that the toString
method on UiProps
already handled that for us.
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.
Nope, you're right. The only case it'd be needed is if they're using plain react-dart component, but we don't really have to worry about that.
+1 |
QA +1
Merging. |
This pull request is connected with UIP-1164 (WSD)
Ultimate problem:
ValidationUtil.warn
should take an optionalElement
parameter which will beconsole.log/.warn'd
to the browser console, allowing consumers to navigate to the offending DOM node in the inspector.All usages of
ValidationUtil.warn
should be updated to pass in the corresponding DOM node, where applicable.How it was fixed:
ValidationUtil.warn
is often used in components'render
methods, it cannot use thefindDomNode
method, since it causes the following error message:To get around this issue,
findDomNode
will no longer be called within theValidationUtil.warn
method. As a result, the component will be logged to the console rather than the DOM node itself.Make the
ValidationUtil.warn
method accept an optional second parameter for a component.Following the standard warning message, log the component itself as well as its props in a collapsed group.
Testing suggestions:
Potential areas of regression: