Skip to content

Commit 2e2e684

Browse files
Address feedback
1 parent 6953523 commit 2e2e684

File tree

2 files changed

+5
-12
lines changed

2 files changed

+5
-12
lines changed

lib/src/dart3_suggestors/null_safety_prep/connect_required_props.dart

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import 'analyzer_plugin_utils.dart';
2828
class ConnectRequiredProps extends RecursiveAstVisitor with ClassSuggestor {
2929
/// Running list of props that should be ignored per mixin that will all be added
3030
/// at the end in [generatePatches].
31-
final _ignoredPropsByMixin = <InterfaceElement, List<String>>{};
31+
final _ignoredPropsByMixin = <InterfaceElement, Set<String>>{};
3232

3333
@override
3434
visitCascadeExpression(CascadeExpression node) {
@@ -57,13 +57,7 @@ class ConnectRequiredProps extends RecursiveAstVisitor with ClassSuggestor {
5757

5858
// Keep a running list of props to ignore per props mixin.
5959
final fieldName = field.name.name;
60-
if (_ignoredPropsByMixin[propsElement] != null) {
61-
if (!_ignoredPropsByMixin[propsElement]!.contains(fieldName)) {
62-
_ignoredPropsByMixin[propsElement]!.add(fieldName);
63-
}
64-
} else {
65-
_ignoredPropsByMixin[propsElement] = [fieldName];
66-
}
60+
_ignoredPropsByMixin.putIfAbsent(propsElement, () => {}).add(fieldName);
6761
}
6862
}
6963

@@ -79,8 +73,7 @@ class ConnectRequiredProps extends RecursiveAstVisitor with ClassSuggestor {
7973

8074
// Add the patches at the end so that all the props to be ignored can be collected
8175
// from the different args in `connect` before adding patches to avoid duplicate patches.
82-
for (final propsClass in _ignoredPropsByMixin.keys) {
83-
final propsToIgnore = _ignoredPropsByMixin[propsClass]!;
76+
_ignoredPropsByMixin.forEach((propsClass, propsToIgnore) {
8477
final classNode =
8578
NodeLocator2(propsClass.nameOffset).searchWithin(result.unit);
8679
if (classNode != null && classNode is NamedCompilationUnitMember) {
@@ -131,7 +124,7 @@ class ConnectRequiredProps extends RecursiveAstVisitor with ClassSuggestor {
131124
}
132125
}
133126
}
134-
}
127+
});
135128
}
136129

137130
static const connectArgNames = [

test/test_fixtures/required_props/test_package/lib/src/test_state.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ part 'test_state.over_react.g.dart';
88

99
UiFactory<FooProps> Foo = connect<FooState, FooProps>(
1010
mapStateToPropsWithOwnProps: (state, props) => Foo()..prop1 = 1,
11-
)(castUiFactory(_$Hoc)); // ignore: undefined_identifier
11+
)(castUiFactory(_$Foo)); // ignore: undefined_identifier
1212

1313
mixin FooProps on UiProps {
1414
int prop1;

0 commit comments

Comments
 (0)