Skip to content

Commit

Permalink
Merge pull request #855 from Workiva/null-safety_public-util-components
Browse files Browse the repository at this point in the history
FED-1889 Null Safety: Audit public utility components
  • Loading branch information
greglittlefield-wf authored Dec 1, 2023
2 parents 2f189af + 594ce50 commit 5efd453
Show file tree
Hide file tree
Showing 43 changed files with 204 additions and 232 deletions.
8 changes: 2 additions & 6 deletions lib/src/component/_deprecated/abstract_transition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -382,17 +382,13 @@ abstract class AbstractTransitionComponent<T extends AbstractTransitionProps,

/// Method that will be called when [AbstractTransitionComponent] first enters the `hidden` state.
void handleHidden() {
if (props.onDidHide != null) {
props.onDidHide!();
}
props.onDidHide?.call();
}


/// Method that will be called when [AbstractTransitionComponent] first enters the `shown` state.
void handleShown() {
if (props.onDidShow != null) {
props.onDidShow!();
}
props.onDidShow?.call();
}

/// Returns attributes only available during testing that indicate the state of the transition.
Expand Down
14 changes: 4 additions & 10 deletions lib/src/component/_deprecated/error_boundary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,14 @@ class ErrorBoundaryComponent<T extends ErrorBoundaryProps, S extends ErrorBounda

@override
void componentDidCatch(error, ReactErrorInfo info) {
if (props.onComponentDidCatch != null) {
props.onComponentDidCatch!(error, info);
}

props.onComponentDidCatch?.call(error, info);
_logErrorCaughtByErrorBoundary(error, info);

if (props.onComponentIsUnrecoverable != null) {
props.onComponentIsUnrecoverable!(error, info);
}
props.onComponentIsUnrecoverable?.call(error, info);
}

@override
render() {
if (state.hasError!) { // [2]
if (state.hasError) { // [2]
return (Dom.div()
..key = 'ohnoes'
..addTestId('ErrorBoundary.unrecoverableErrorInnerHtmlContainerNode')
Expand All @@ -135,7 +129,7 @@ class ErrorBoundaryComponent<T extends ErrorBoundaryProps, S extends ErrorBounda
void componentDidUpdate(Map prevProps, Map prevState, [dynamic snapshot]) {
// If the child is different, and the error boundary is currently in an error state,
// give the children a chance to mount.
if (state.hasError!) {
if (state.hasError) {
final childThatCausedError = typedPropsFactory(prevProps).children!.single;
if (childThatCausedError != props.children!.single) {
reset();
Expand Down
12 changes: 5 additions & 7 deletions lib/src/component/_deprecated/error_boundary_mixins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ abstract class _$ErrorBoundaryStateMixin implements UiState {
/// more frequently than [ErrorBoundaryPropsMixin.identicalErrorFrequencyTolerance], a static copy of
/// the render tree's HTML that was captured at the time of the error will be rendered.
/// See: [ErrorBoundaryPropsMixin.onComponentIsUnrecoverable] for more information about this scenario.
bool? hasError;
late bool hasError;

/// Whether to show "fallback" UI when [hasError] is true.
///
/// This value will always be true if [ErrorBoundaryPropsMixin.fallbackUIRenderer] is non-null.
bool? showFallbackUIOnError;
late bool showFallbackUIOnError;
}

/// A component mixin you can use to implement / extend from the behaviors of an [ErrorBoundary]
Expand Down Expand Up @@ -231,9 +231,7 @@ mixin ErrorBoundaryMixin<T extends ErrorBoundaryPropsMixin, S extends ErrorBound
@mustCallSuper
@override
void componentDidCatch(/*Error||Exception*/dynamic error, ReactErrorInfo info) {
if (props.onComponentDidCatch != null) {
props.onComponentDidCatch!(error, info);
}
props.onComponentDidCatch?.call(error, info);

_handleErrorInComponentTree(error, info);
}
Expand All @@ -243,7 +241,7 @@ mixin ErrorBoundaryMixin<T extends ErrorBoundaryPropsMixin, S extends ErrorBound
void componentDidUpdate(Map prevProps, Map prevState, [dynamic snapshot]) {
// If the child is different, and the error boundary is currently in an error state,
// give the child a chance to remount itself and "recover" from the previous error.
if (state.hasError!) {
if (state.hasError) {
final childThatCausedError = typedPropsFactory(prevProps).children!.single;
if (childThatCausedError != props.children!.single) {
reset();
Expand All @@ -253,7 +251,7 @@ mixin ErrorBoundaryMixin<T extends ErrorBoundaryPropsMixin, S extends ErrorBound

@override
render() {
if (state.hasError! && state.showFallbackUIOnError!) {
if (state.hasError && state.showFallbackUIOnError) {
return (props.fallbackUIRenderer ?? _renderStringDomAfterUnrecoverableErrors)(
_errorLog.isNotEmpty ? _errorLog.last : null,
_callStackLog.isNotEmpty ? _callStackLog.last : null,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions lib/src/component/_deprecated/resize_sensor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,7 @@ class ResizeSensorComponent extends UiComponent2<ResizeSensorProps> with SafeAni
..scrollLeft = maxSensorSize
..scrollTop = maxSensorSize;

if (props.onDidReset != null) {
props.onDidReset!();
}
props.onDidReset?.call();
}

/// Call to repair / re-initialize a [ResizeSensor] that was detached from the DOM when it mounted.
Expand Down
28 changes: 12 additions & 16 deletions lib/src/component/abstract_transition.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mixin AbstractTransitionState on UiState {
/// The current phase of transition the [AbstractTransitionComponent] is in.
///
/// Default: [AbstractTransitionComponent.initiallyShown] ? [TransitionPhase.SHOWN] : [TransitionPhase.HIDDEN]
TransitionPhase? transitionPhase;
late TransitionPhase transitionPhase;
}

/// How to use [AbstractTransitionComponent]:
Expand Down Expand Up @@ -101,26 +101,26 @@ abstract class AbstractTransitionComponent<T extends AbstractTransitionProps,

@override
get initialState => (newState()
..transitionPhase = this.initiallyShown! ? TransitionPhase.SHOWN : TransitionPhase.HIDDEN
..transitionPhase = this.initiallyShown ? TransitionPhase.SHOWN : TransitionPhase.HIDDEN
);

/// Stream for listening to `transitionend` events on the [AbstractTransitionComponent].
StreamSubscription? _endTransitionSubscription;

/// Whether the [AbstractTransitionComponent] should be visible initially when mounted.
bool? get initiallyShown;
bool get initiallyShown;

/// Returns the DOM node that will transition.
Element? getTransitionDomNode();

/// Whether transitions are enabled for this component.
bool? get hasTransition => true;
bool get hasTransition => true;

/// Whether the Element returned by [getTransitionDomNode] will have a transition event when showing.
bool get hasTransitionIn => hasTransition! && transitionInCount > 0;
bool get hasTransitionIn => hasTransition && transitionInCount > 0;

/// Whether the Element returned by [getTransitionDomNode] will have a transition event when hiding.
bool get hasTransitionOut => hasTransition! && transitionOutCount > 0;
bool get hasTransitionOut => hasTransition && transitionOutCount > 0;

/// The number of `transitionend` events that occur when the transition node is shown.
///
Expand All @@ -133,7 +133,7 @@ abstract class AbstractTransitionComponent<T extends AbstractTransitionProps,
int get transitionOutCount => props.transitionOutCount ?? props.transitionCount ?? 1;

/// The duration that can elapse before a transition timeout occurs.
Duration? get transitionTimeout => const Duration(seconds: 1);
Duration get transitionTimeout => const Duration(seconds: 1);

/// Timer used to determine if a transition timeout has occurred.
Timer? _transitionEndTimer;
Expand Down Expand Up @@ -191,7 +191,7 @@ abstract class AbstractTransitionComponent<T extends AbstractTransitionProps,
_cancelTransitionEventListener();
_cancelTransitionEndTimer();

_transitionEndTimer = Timer(transitionTimeout!, () {
_transitionEndTimer = Timer(transitionTimeout, () {
assert(ValidationUtil.warn(
'The number of transitions expected to complete have not completed. Something is most likely wrong.',
this
Expand Down Expand Up @@ -274,7 +274,7 @@ abstract class AbstractTransitionComponent<T extends AbstractTransitionProps,
_cancelTransitionEventListener();
}

switch (state.transitionPhase!) {
switch (state.transitionPhase) {
case TransitionPhase.PRE_SHOWING:
handlePreShowing();
break;
Expand Down Expand Up @@ -367,17 +367,13 @@ abstract class AbstractTransitionComponent<T extends AbstractTransitionProps,

/// Method that will be called when [AbstractTransitionComponent] first enters the `hidden` state.
void handleHidden() {
if (props.onDidHide != null) {
props.onDidHide!();
}
props.onDidHide?.call();
}


/// Method that will be called when [AbstractTransitionComponent] first enters the `shown` state.
void handleShown() {
if (props.onDidShow != null) {
props.onDidShow!();
}
props.onDidShow?.call();
}

/// Returns attributes only available during testing that indicate the state of the transition.
Expand All @@ -393,7 +389,7 @@ abstract class AbstractTransitionComponent<T extends AbstractTransitionProps,
};

return {
transitionPhaseTestAttr: enumToAttrValue[state.transitionPhase!],
transitionPhaseTestAttr: enumToAttrValue[state.transitionPhase],
};
}

Expand Down
12 changes: 7 additions & 5 deletions lib/src/component/abstract_transition.over_react.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 6 additions & 12 deletions lib/src/component/error_boundary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ mixin ErrorBoundaryState on UiState {
/// more frequently than [ErrorBoundaryProps.identicalErrorFrequencyTolerance], a static copy of
/// the render tree's HTML that was captured at the time of the error will be rendered.
/// See: [ErrorBoundaryProps.onComponentIsUnrecoverable] for more information about this scenario.
bool? hasError;
late bool hasError;

/// Whether to show "fallback" UI when [hasError] is true.
///
/// This value will always be true if [ErrorBoundaryProps.fallbackUIRenderer] is non-null.
bool? showFallbackUIOnError;
late bool showFallbackUIOnError;
}

@Component2(isWrapper: true, isErrorBoundary: true)
Expand Down Expand Up @@ -195,20 +195,14 @@ class ErrorBoundaryComponent

@override
void componentDidCatch(error, ReactErrorInfo info) {
if (props.onComponentDidCatch != null) {
props.onComponentDidCatch!(error, info);
}

props.onComponentDidCatch?.call(error, info);
_logErrorCaughtByErrorBoundary(error, info);

if (props.onComponentIsUnrecoverable != null) {
props.onComponentIsUnrecoverable!(error, info);
}
props.onComponentIsUnrecoverable?.call(error, info);
}

@override
render() {
if (state.hasError!) { // [2]
if (state.hasError) { // [2]
return (Dom.div()
..key = 'ohnoes'
..addTestId('ErrorBoundary.unrecoverableErrorInnerHtmlContainerNode')
Expand All @@ -224,7 +218,7 @@ class ErrorBoundaryComponent
void componentDidUpdate(Map prevProps, Map prevState, [dynamic snapshot]) {
// If the child is different, and the error boundary is currently in an error state,
// give the children a chance to mount.
if (state.hasError!) {
if (state.hasError) {
final childThatCausedError = typedPropsFactory(prevProps).children!.single;
if (childThatCausedError != props.children!.single) {
reset();
Expand Down
22 changes: 12 additions & 10 deletions lib/src/component/error_boundary.over_react.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5efd453

Please sign in to comment.