@@ -95,18 +95,10 @@ abstract class TypedMapImplGenerator extends BoilerplateDeclarationGenerator {
9595 void _generateFactory () {
9696 assert (factoryNames.length == 1 , 'factoryNames must have a length of 1' );
9797
98- outputContentsBuffer.write (
99- '${names .implName } ${factoryNames .first .implName }([Map${nullSafety ? '?' : '' } backingProps]) => ' );
100-
101- if (! isComponent2) {
102- /// _$$FooProps _$Foo([Map backingProps] ) => _$$FooProps(backingProps);
103- outputContentsBuffer.writeln ('${names .implName }(backingProps);' );
104- } else {
105- /// _$$FooProps _$Foo([Map backingProps] ) => backingProps == null ? $jsMapImplName(JsBackedMap()) : _$$FooProps(backingProps);
106- // Optimize this case for when backingProps is null to promote inlining of `jsMapImplName` typing
107- outputContentsBuffer.writeln (
108- 'backingProps == null ? ${names .jsMapImplName }(JsBackedMap()) : ${names .implName }(backingProps);' );
109- }
98+ // _$$FooProps _$Foo([Map? backingProps]) => _$$FooProps(backingProps);
99+ outputContentsBuffer.writeln (
100+ '${names .implName } ${factoryNames .first .implName }([Map${nullSafety ? '?' : '' } backingProps])'
101+ ' => ${names .implName }(backingProps);' );
110102 }
111103
112104 String _generateImplClassHeader ();
@@ -168,70 +160,32 @@ abstract class TypedMapImplGenerator extends BoilerplateDeclarationGenerator {
168160 'componentFactoryName/propKeyNamespace must not be specified for state' );
169161 }
170162 }
171-
172- final classDeclaration = StringBuffer ();
173- if (isComponent2) {
174- // This class will only have a factory constructor that instantiates one
175- // of two subclasses.
176- classDeclaration.write ('abstract ' );
177- }
178-
179- classDeclaration
180- ..write (_generateImplClassHeader ())
181- ..write (' {' );
182-
183163 final propsOrState = isProps ? 'props' : 'state' ;
184164
185- // Class declaration
186165 final buffer = StringBuffer ()
166+ // Class declaration
187167 ..writeln ('// Concrete $propsOrState implementation.' )
188168 ..writeln ('//' )
189169 ..writeln (
190170 '// Implements constructor and backing map${isProps ? ', and links up to generated component factory' : '' }.' )
191171 ..write (internalGeneratedMemberDeprecationLine ())
192- ..writeln (classDeclaration);
193-
194- // Constructors
195- if (isComponent2) {
196- buffer
197- ..writeln (' ${names .implName }._();' )
198- ..writeln ()
199- ..writeln (' factory ${names .implName }(Map${nullSafety ? '?' : '' } backingMap) {' )
200- ..writeln (' if (backingMap == null || backingMap is JsBackedMap) {' )
201- ..writeln (
202- ' return ${names .jsMapImplName }(backingMap as JsBackedMap${nullSafety ? '?' : '' });' )
203- ..writeln (' } else {' )
204- ..writeln (' return ${names .plainMapImplName }(backingMap);' )
205- ..writeln (' }' )
206- ..writeln (' }' );
207- } else {
208- buffer
209- ..writeln (
210- ' // This initializer of `_$propsOrState ` to an empty map, as well as the reassignment' )
211- ..writeln (
212- ' // of `_$propsOrState ` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217' )
213- // TODO need to remove this workaround once https://github.com/dart-lang/sdk/issues/36217 is fixed get nice dart2js output
214- ..writeln (
215- ' ${names .implName }(Map${nullSafety ? '?' : '' } backingMap) : this._$propsOrState = {} {' )
216- ..writeln (' this._$propsOrState = backingMap ?? {};' )
217- ..writeln (' }' );
218- }
172+ ..write (_generateImplClassHeader ())
173+ ..writeln (' {' )
174+ // Constructor
175+ ..writeln (' ${names .implName }([Map${nullSafety ? '?' : '' } backingMap])'
176+ ' : this.$propsOrState = backingMap ?? JsBackedMap();' );
219177
220178 // This needs to be a top-level member and not a static member, and it needs to be unique
221179 // to avoid collisions across typed map impls within the library, potentially in multiple parts.
222180 // So, we'll just namespace it by the impl name.
223181 final topLevelGetPropKeyAliasName = '_\$ getPropKey\$ ${names .implName }' ;
224182
225183 // Members
226- if (! isComponent2) {
227- buffer
228- ..writeln ()
229- ..writeln (' /// The backing $propsOrState map proxied by this class.' )
230- ..writeln (' @override' )
231- ..writeln (' Map get $propsOrState => _$propsOrState ;' )
232- ..writeln (' Map _$propsOrState ;' );
233- }
234184 buffer
185+ ..writeln ()
186+ ..writeln (' /// The backing $propsOrState map proxied by this class.' )
187+ ..writeln (' @override' )
188+ ..writeln (' final Map $propsOrState ;' )
235189 ..writeln ()
236190 ..writeln (
237191 ' /// Let `${isProps ? 'UiProps' : 'UiState' }` internals know that this class has been generated.' )
@@ -296,38 +250,6 @@ abstract class TypedMapImplGenerator extends BoilerplateDeclarationGenerator {
296250 ..writeln ('const $topLevelGetPropKeyAliasName = getPropKey;' );
297251 }
298252
299- // Component2-specific classes
300- if (isComponent2) {
301- // TODO need to remove this workaround once https://github.com/dart-lang/sdk/issues/36217 is fixed get nice dart2js output
302- buffer
303- ..writeln ()
304- ..writeln ('''
305- // Concrete $propsOrState implementation that can be backed by any [Map].
306- ${internalGeneratedMemberDeprecationLine ()}class ${names .plainMapImplName }$typeParamsOnClass extends ${names .implName }$typeParamsOnSuper {
307- // This initializer of `_$propsOrState ` to an empty map, as well as the reassignment
308- // of `_$propsOrState ` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
309- ${names .plainMapImplName }(Map${nullSafety ? '?' : '' } backingMap) : this._$propsOrState = {}, super._() {
310- this._$propsOrState = backingMap ?? {};
311- }
312- /// The backing $propsOrState map proxied by this class.
313- @override
314- Map get $propsOrState => _$propsOrState ;
315- Map _$propsOrState ;
316- }
317- // Concrete $propsOrState implementation that can only be backed by [JsMap],
318- // allowing dart2js to compile more optimal code for key-value pair reads/writes.
319- ${internalGeneratedMemberDeprecationLine ()}class ${names .jsMapImplName }$typeParamsOnClass extends ${names .implName }$typeParamsOnSuper {
320- // This initializer of `_$propsOrState ` to an empty map, as well as the reassignment
321- // of `_$propsOrState ` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
322- ${names .jsMapImplName }(JsBackedMap${nullSafety ? '?' : '' } backingMap) : this._$propsOrState = JsBackedMap(), super._() {
323- this._$propsOrState = backingMap ?? JsBackedMap();
324- }
325- /// The backing $propsOrState map proxied by this class.
326- @override
327- JsBackedMap get $propsOrState => _$propsOrState ;
328- JsBackedMap _$propsOrState ;
329- }''' );
330- }
331253 return buffer.toString ();
332254 }
333255}
@@ -488,7 +410,7 @@ class _TypedMapImplGenerator extends TypedMapImplGenerator {
488410 '${factoryName .privateConfigName } = UiFactoryConfig(\n '
489411 'propsFactory: PropsFactory(\n '
490412 'map: (map) => ${names .implName }(map),\n '
491- 'jsMap: (map) => ${names .jsMapImplName }(map),),\n '
413+ 'jsMap: (map) => ${names .implName }(map),),\n '
492414 'displayName: \' ${factoryName .consumerName }\' );\n\n '
493415 '@Deprecated(r\' Use the private variable, ${factoryName .privateConfigName }, instead \'\n '
494416 '\' and update the `over_react` lower bound to version 4.1.0. \'\n '
0 commit comments