Skip to content

Commit

Permalink
Update builder
Browse files Browse the repository at this point in the history
  • Loading branch information
joebingham-wk committed Oct 9, 2020
1 parent fbac108 commit 8855f7e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
11 changes: 1 addition & 10 deletions lib/src/builder/codegen/component_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,7 @@ class _ComponentGenerator extends ComponentGenerator {

@override
void _generateAdditionalComponentBody() {
outputContentsBuffer
..writeln()
..writeln(' @override')
..writeln(' PropsMetaCollection get propsMeta => const PropsMetaCollection({');
for (final name in declaration.allPropsMixins) {
final names = TypedMapNames(name.name);
outputContentsBuffer.write(' ${generatedMixinWarningCommentLine(names, isProps: true)}');
outputContentsBuffer.writeln(' ${names.consumerName}: ${names.publicGeneratedMetaName},');
}
outputContentsBuffer.writeln(' });');
generatePropsMeta(outputContentsBuffer, declaration.allPropsMixins);
}
}

Expand Down
11 changes: 11 additions & 0 deletions lib/src/builder/codegen/typed_map_impl_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ abstract class TypedMapImplGenerator extends BoilerplateDeclarationGenerator {
String _generateConcretePropsOrStateImpl({
String componentFactoryName,
String propKeyNamespace,
List<Identifier> allPropsMixins,
}) {
if (isProps) {
if (componentFactoryName == null || propKeyNamespace == null) {
Expand Down Expand Up @@ -222,6 +223,10 @@ abstract class TypedMapImplGenerator extends BoilerplateDeclarationGenerator {
' /// The default namespace for the prop getters/setters generated for this class.')
..writeln(' @override')
..writeln(' String get propKeyNamespace => ${stringLiteral(propKeyNamespace)};');

if (allPropsMixins != null) {
generatePropsMeta(buffer, allPropsMixins, classType: 'PropsInstanceMeta', fieldName: r'$meta', isConst: false);
}
}

// End of class body
Expand Down Expand Up @@ -345,10 +350,13 @@ class _TypedMapImplGenerator extends TypedMapImplGenerator {
@override
final Version version;

final List<Identifier> allPropsMixins;

_TypedMapImplGenerator.props(ClassComponentDeclaration declaration)
: names = TypedMapNames(declaration.props.either.name.name),
factoryNames = [FactoryNames(declaration.factory.name.name)],
member = declaration.props.either,
allPropsMixins = declaration.allPropsMixins,
isProps = true,
componentFactoryName = ComponentNames(declaration.component.name.name).componentFactoryName,
isFunctionComponentDeclaration = false,
Expand All @@ -358,6 +366,7 @@ class _TypedMapImplGenerator extends TypedMapImplGenerator {
: names = TypedMapNames(declaration.state.either.name.name),
factoryNames = [FactoryNames(declaration.factory.name.name)],
member = declaration.state.either,
allPropsMixins = null,
isProps = false,
componentFactoryName = ComponentNames(declaration.component.name.name).componentFactoryName,
isFunctionComponentDeclaration = false,
Expand All @@ -369,6 +378,7 @@ class _TypedMapImplGenerator extends TypedMapImplGenerator {
factoryNames =
declaration.factories.map((factory) => FactoryNames(factory.name.name)).toList(),
member = declaration.props.either,
allPropsMixins = declaration.props.either.nodeHelper.mixins?.map<Identifier>((mixin) => mixin.name)?.toList(),
isProps = true,
componentFactoryName = 'null',
isFunctionComponentDeclaration = declaration.factories.first.shouldGenerateConfig,
Expand Down Expand Up @@ -403,6 +413,7 @@ class _TypedMapImplGenerator extends TypedMapImplGenerator {
componentFactoryName: componentFactoryName,
// This doesn't really apply to the new boilerplate
propKeyNamespace: '',
allPropsMixins: allPropsMixins,
));
}

Expand Down
18 changes: 18 additions & 0 deletions lib/src/builder/codegen/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

import 'package:analyzer/dart/ast/ast.dart';
import 'package:logging/logging.dart';
import 'package:meta/meta.dart';
import 'package:over_react/src/component_declaration/annotations.dart' as annotations;
Expand Down Expand Up @@ -66,3 +67,20 @@ String generatedMixinWarningCommentLine(TypedMapNames mixinNames, {@required boo

return value;
}

void generatePropsMeta(StringBuffer buffer, List<Identifier> mixins, {
String classType = 'PropsMetaCollection',
String fieldName = 'propsMeta',
bool isConst = true,
}) {
buffer
..writeln()
..writeln(' @override')
..writeln(' $classType get $fieldName => ${isConst ? 'const' : ''} $classType({');
for (final name in mixins) {
final names = TypedMapNames(name.name);
buffer.write(' ${generatedMixinWarningCommentLine(names, isProps: true)}');
buffer.writeln(' ${names.consumerName}: ${names.publicGeneratedMetaName},');
}
buffer.writeln(' });');
}

0 comments on commit 8855f7e

Please sign in to comment.