Skip to content

Commit

Permalink
Eliminate a few more non-null assertion operators
Browse files Browse the repository at this point in the history
  • Loading branch information
greglittlefield-wf committed Nov 14, 2023
1 parent dcf2bca commit 363dade
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
46 changes: 23 additions & 23 deletions lib/src/builder/codegen/component_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,32 +90,32 @@ abstract class ComponentGenerator extends BoilerplateDeclarationGenerator {
' ${propsNames.implName} typedPropsFactory(Map${nullSafety ? '?' : ''} backingMap) => ${propsNames.implName}(backingMap);')
..writeln();

if (isComponent2 && hasState) {
outputContentsBuffer
..writeln(' ${nullSafety ? 'late ' : ''}${stateNames!.jsMapImplName} _cachedTypedState;')
..writeln(' @override')
..writeln(' ${stateNames!.jsMapImplName} get state => _cachedTypedState;')
..writeln()
..writeln(' @override')
..writeln(' set state(Map value) {')
..writeln(' assert(value is JsBackedMap, ')
..writeln(' \'Component2.state should only be set via \'')
..writeln(' \'initialState or setState.\');')
..writeln(' super.state = value;')
..writeln(' _cachedTypedState = typedStateFactoryJs(value as JsBackedMap);')
..writeln(' }')
..writeln()
..writeln(' @override ')
..writeln(' ${stateNames!.jsMapImplName} typedStateFactoryJs(JsBackedMap${nullSafety ? '?' : ''} backingMap)'
' => ${stateNames!.jsMapImplName}(backingMap);')
..writeln();
}

if (hasState) {
final stateNames = this.stateNames!;
if (isComponent2) {
outputContentsBuffer
..writeln(' ${nullSafety ? 'late ' : ''}${stateNames.jsMapImplName} _cachedTypedState;')
..writeln(' @override')
..writeln(' ${stateNames.jsMapImplName} get state => _cachedTypedState;')
..writeln()
..writeln(' @override')
..writeln(' set state(Map value) {')
..writeln(' assert(value is JsBackedMap, ')
..writeln(' \'Component2.state should only be set via \'')
..writeln(' \'initialState or setState.\');')
..writeln(' super.state = value;')
..writeln(' _cachedTypedState = typedStateFactoryJs(value as JsBackedMap);')
..writeln(' }')
..writeln()
..writeln(' @override ')
..writeln(' ${stateNames.jsMapImplName} typedStateFactoryJs(JsBackedMap${nullSafety ? '?' : ''} backingMap)'
' => ${stateNames.jsMapImplName}(backingMap);')
..writeln();
}
outputContentsBuffer
..writeln(' @override')
..writeln(' ${stateNames!.implName} typedStateFactory(Map${nullSafety ? '?' : ''} backingMap)'
' => ${stateNames!.implName}(backingMap);')
..writeln(' ${stateNames.implName} typedStateFactory(Map${nullSafety ? '?' : ''} backingMap)'
' => ${stateNames.implName}(backingMap);')
..writeln();
}

Expand Down
10 changes: 9 additions & 1 deletion lib/src/builder/parsing/declarations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ class LegacyClassComponentDeclaration extends BoilerplateDeclaration {
bool get isComponent2 => component.isComponent2(version);

@override
get _members => [factory, component, props, if (state != null) state!];
get _members {
final state = this.state;
return [
factory,
component,
props,
if (state != null) state,
];
}

@override
get type => DeclarationType.legacyClassComponentDeclaration;
Expand Down

0 comments on commit 363dade

Please sign in to comment.