-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #291 from Workiva/3.0.0/CPLAT-5599_js-error-boundary
CPLAT-5599 Add temporary JS error boundary
- Loading branch information
Showing
9 changed files
with
291 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import 'package:over_react/over_react.dart'; | ||
|
||
// ignore: uri_has_not_been_generated | ||
part 'flawed_component.over_react.g.dart'; | ||
|
||
@Factory() | ||
// ignore: undefined_identifier | ||
UiFactory<FlawedProps> Flawed = _$Flawed; | ||
|
||
@Props() | ||
class _$FlawedProps extends UiProps {} | ||
|
||
// AF-3369 This will be removed once the transition to Dart 2 is complete. | ||
// ignore: mixin_of_non_class, undefined_class | ||
class FlawedProps extends _$FlawedProps with _$FlawedPropsAccessorsMixin { | ||
// ignore: undefined_identifier, undefined_class, const_initialized_with_non_constant_value | ||
static const PropsMeta meta = _$metaForFlawedProps; | ||
} | ||
|
||
@State() | ||
class _$FlawedState extends UiState { | ||
bool hasError; | ||
} | ||
|
||
// AF-3369 This will be removed once the transition to Dart 2 is complete. | ||
// ignore: mixin_of_non_class, undefined_class | ||
class FlawedState extends _$FlawedState with _$FlawedStateAccessorsMixin { | ||
// ignore: undefined_identifier, undefined_class, const_initialized_with_non_constant_value | ||
static const StateMeta meta = _$metaForFlawedState; | ||
} | ||
|
||
@Component() | ||
class FlawedComponent extends UiStatefulComponent<FlawedProps, FlawedState> { | ||
@override | ||
Map getInitialState() => (newState()..hasError = false); | ||
|
||
@override | ||
void componentWillUpdate(_, Map nextState) { | ||
final tNextState = typedStateFactory(nextState); | ||
if (tNextState.hasError && !state.hasError) { | ||
throw new Error(); | ||
} | ||
} | ||
|
||
@override | ||
render() { | ||
return (Dom.button() | ||
..addTestId('flawedButton') | ||
..onClick = (_) { | ||
setState(newState()..hasError = true); | ||
} | ||
)('oh hai'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
part of over_react.web.demos; | ||
|
||
@Factory() | ||
// ignore: undefined_identifier | ||
UiFactory<FaultyProps> Faulty = _$Faulty; | ||
|
||
@Props() | ||
class _$FaultyProps extends UiProps {} | ||
|
||
// AF-3369 This will be removed once the transition to Dart 2 is complete. | ||
// ignore: mixin_of_non_class, undefined_class | ||
class FaultyProps extends _$FaultyProps with _$FaultyPropsAccessorsMixin { | ||
// ignore: undefined_identifier, undefined_class, const_initialized_with_non_constant_value | ||
static const PropsMeta meta = _$metaForFaultyProps; | ||
} | ||
|
||
@State() | ||
class _$FaultyState extends UiState { | ||
bool hasErrored; | ||
} | ||
|
||
// AF-3369 This will be removed once the transition to Dart 2 is complete. | ||
// ignore: mixin_of_non_class, undefined_class | ||
class FaultyState extends _$FaultyState with _$FaultyStateAccessorsMixin { | ||
// ignore: undefined_identifier, undefined_class, const_initialized_with_non_constant_value | ||
static const StateMeta meta = _$metaForFaultyState; | ||
} | ||
|
||
@Component() | ||
class FaultyComponent extends UiStatefulComponent<FaultyProps, FaultyState> { | ||
@override | ||
Map getInitialState() => (newState()..hasErrored = false); | ||
|
||
@override | ||
void componentWillUpdate(_, Map nextState) { | ||
final tNextState = typedStateFactory(nextState); | ||
if (tNextState.hasErrored && !state.hasErrored) { | ||
throw new Error(); | ||
} | ||
} | ||
|
||
@override | ||
render() { | ||
return (Dom.div()..className = 'btn-toolbar')( | ||
(Button()..onClick = (_) { | ||
setState(newState()..hasErrored = true); | ||
})('Click me to throw an error'), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.