Skip to content

Commit

Permalink
Start going through ValidationUtil.warn calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kaanaksoy-wk committed Mar 29, 2017
1 parent 44acae5 commit 6db030e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/src/component/abstract_transition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,14 @@ abstract class AbstractTransitionComponent<T extends AbstractTransitionProps, S
warningMessage += ' Instead of setting this prop to 0, override the `hasTransition` getter to return false.';
}

assert(ValidationUtil.warn(warningMessage));
assert(ValidationUtil.warn(warningMessage, this));

skipCount = 0;
}

var timer = new Timer(transitionTimeout, () {
assert(ValidationUtil.warn(
'The number of transitions expected to complete have not completed. Something is most likely wrong.'
'The number of transitions expected to complete have not completed. Something is most likely wrong.', this
));

complete();
Expand Down
2 changes: 1 addition & 1 deletion lib/src/component/resize_sensor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class ResizeSensorComponent extends UiComponent<ResizeSensorProps> with _SafeAni
void componentDidMount() {
if (props.quickMount) {
assert(props.onInitialize == null || ValidationUtil.warn(
'props.onInitialize will not be called when props.quickMount is true.'
'props.onInitialize will not be called when props.quickMount is true.', this
));

// [1] Initialize/reset the sensor in the next animation frame after mount
Expand Down
2 changes: 1 addition & 1 deletion lib/src/component_declaration/component_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ abstract class UiProps
);

// TODO: Remove ValidationUtil.warn call when https://github.com/dart-lang/sdk/issues/26093 is resolved.
ValidationUtil.warn(errorMessage);
ValidationUtil.warn(errorMessage, this);
throw new ArgumentError(errorMessage);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/util/dom_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void setSelectionRange(/* TextInputElement | TextAreaElement */Element input, in
Google Chrome does not support `setSelectionRange` on email or number inputs.
See: https://bugs.chromium.org/p/chromium/issues/detail?id=324360
'''
)));
), input));

return;
}
Expand Down
8 changes: 7 additions & 1 deletion lib/src/util/validation_util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ library over_react.validation_util;

import 'dart:html';

import 'package:over_react/over_react.dart';

typedef void ValidationUtilWarningCallback(String message);

/// Utility for logging validation errors or warning.
Expand All @@ -31,7 +33,7 @@ class ValidationUtil {
/// assert(ValidationUtil.warn('Some warning message'));
///
/// The message will get print out to the console.
static bool warn(String message) {
static bool warn(String message, [dynamic element]) {
WARNING_COUNT += 1;

if (onWarning != null) {
Expand All @@ -44,6 +46,10 @@ class ValidationUtil {
}

window.console.warn('VALIDATION WARNING: $message');

if(element != null) {
window.console.warn(findDomNode(element));
}
}

return true;
Expand Down
4 changes: 2 additions & 2 deletions web/src/demo_components/button_group.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,14 @@ class ButtonGroupComponent<T extends ButtonGroupProps, S extends ButtonGroupStat
if (isValidElement(child)) {
if (!isComponentOfType(child, childFactory)) {
assert(ValidationUtil.warn(
'An unexpected child type was found within this component.'
'An unexpected child type was found within this component.', this
));
}

isCloneable = true;
} else if (child != null) {
assert(ValidationUtil.warn(
'You are not using a valid ReactElement.'
'You are not using a valid ReactElement.', this
));
}

Expand Down

0 comments on commit 6db030e

Please sign in to comment.