Skip to content

Commit

Permalink
Merge pull request #13 from Workiva/link-2020/pseudo-static-lifecycle…
Browse files Browse the repository at this point in the history
…-cleanup

PseudoStaticLifecycleDiagnostic cleanup
  • Loading branch information
greglittlefield-wf committed Jun 15, 2020
2 parents e8f8916 + 519f4cc commit 5081ee2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:over_react_analyzer_plugin/src/diagnostic/component_usage.dart';

const staticMethodNames = ['getDefaultProps', 'getDerivedStateFromProps'];
const staticMethodNames = ['getDefaultProps', 'defaultProps', 'getDerivedStateFromProps'];
const instanceMemberWhitelist = [
'newProps',
'newState',
Expand Down
40 changes: 40 additions & 0 deletions playground/web/pseudo_static_lifecycle.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import 'package:over_react/over_react.dart';

part 'dom_prop_types.over_react.g.dart';

UiFactory<HammerTimeProps> HammerTime =
// ignore: undefined_identifier
_$HammerTime;

mixin HammerTimeProps on UiProps {
String somethingThatCanBeTouched;
}

mixin HammerTimeState on UiState {}

class HammerTimeComponent extends UiStatefulComponent2<HammerTimeProps, HammerTimeState> {
final mcHammer = 'cant touch this';

@override
get defaultProps {
return newProps()
..somethingThatCanBeTouched = mcHammer;
}

@override
getDerivedStateFromProps(Map nextProps, Map prevState) {
final tNextProps = typedPropsFactory(nextProps);
final tNextPropsJs = typedPropsFactoryJs(nextProps);
final tPrevState = typedStateFactory(prevState);
final tPrevStateJs = typedStateFactoryJs(prevState);

if (props.somethingThatCanBeTouched == mcHammer) {
return newState();
}

return null;
}

@override
render() {}
}

0 comments on commit 5081ee2

Please sign in to comment.