@@ -457,39 +457,43 @@ class ReactDartFunctionComponentFactoryProxy extends ReactComponentFactoryProxy
457
457
/// The React JS component definition of this Function Component.
458
458
final JsFunctionComponent reactFunction;
459
459
460
- ReactDartFunctionComponentFactoryProxy (this .reactFunction, [this .displayName]);
460
+ ReactDartFunctionComponentFactoryProxy (DartFunctionComponent dartFunctionComponent, {String displayName})
461
+ : this .displayName = displayName ?? _getJsFunctionName (dartFunctionComponent),
462
+ this .reactFunction = _wrapFunctionComponent (dartFunctionComponent,
463
+ displayName: displayName ?? _getJsFunctionName (dartFunctionComponent));
461
464
462
465
@override
463
466
JsFunctionComponent get type => reactFunction;
464
- }
465
467
466
- /// Creates a function component from the given [dartFunctionComponent] that can be used with React.
467
- ///
468
- /// [displayName] Sets the component name for debugging purposes.
469
- ///
470
- /// In DDC, this will be the [DartFunctionComponent] name, but in dart2js it will be null unless
471
- /// overridden, since using runtimeType can lead to larger dart2js output.
472
- ///
473
- /// This will result in the dart2js name being `ReactDartComponent2` (the
474
- /// name of the proxying JS component defined in _dart_helpers.js).
475
- JsFunctionComponent _wrapFunctionComponent (DartFunctionComponent dartFunctionComponent, {String displayName}) {
476
- displayName ?? = getProperty (dartFunctionComponent, 'name' ) ?? getProperty (dartFunctionComponent, '\$ static_name' );
477
-
478
- // dart2js uses null and undefined interchangeably, meaning returning `null` from dart
479
- // may show up in js as `undefined`, ReactJS doesnt like that and expects a js `null` to be returned,
480
- // and throws if it gets `undefined`. `jsNull` is an interop variable that holds a JS `null` value
481
- // to force `null` as the return value if user returns a Dart `null`.
482
- // See: https://github.com/dart-lang/sdk/issues/27485
483
- jsFunctionComponent (JsMap jsProps, [JsMap _legacyContext]) =>
484
- dartFunctionComponent (JsBackedMap .backedBy (jsProps)) ?? jsNull;
485
- JsFunctionComponent interopFunction = allowInterop (jsFunctionComponent);
486
- if (displayName != null ) {
487
- // This is a work-around to display the correct name in the React DevTools.
488
- _defineProperty (interopFunction, 'name' , jsify ({'value' : displayName}));
468
+ static String _getJsFunctionName (Function object) =>
469
+ getProperty (object, 'name' ) ?? getProperty (object, '\$ static_name' );
470
+
471
+ /// Creates a function component from the given [dartFunctionComponent] that can be used with React.
472
+ ///
473
+ /// [displayName] Sets the component name for debugging purposes.
474
+ ///
475
+ /// In DDC, this will be the [DartFunctionComponent] name, but in dart2js it will be null unless
476
+ /// overridden, since using runtimeType can lead to larger dart2js output.
477
+ ///
478
+ /// This will result in the dart2js name being `ReactDartComponent2` (the
479
+ /// name of the proxying JS component defined in _dart_helpers.js).
480
+ static JsFunctionComponent _wrapFunctionComponent (DartFunctionComponent dartFunctionComponent, {String displayName}) {
481
+ // dart2js uses null and undefined interchangeably, meaning returning `null` from dart
482
+ // may show up in js as `undefined`, ReactJS doesnt like that and expects a js `null` to be returned,
483
+ // and throws if it gets `undefined`. `jsNull` is an interop variable that holds a JS `null` value
484
+ // to force `null` as the return value if user returns a Dart `null`.
485
+ // See: https://github.com/dart-lang/sdk/issues/27485
486
+ jsFunctionComponent (JsMap jsProps, [JsMap _legacyContext]) =>
487
+ dartFunctionComponent (JsBackedMap .backedBy (jsProps)) ?? jsNull;
488
+ JsFunctionComponent interopFunction = allowInterop (jsFunctionComponent);
489
+ if (displayName != null ) {
490
+ // This is a work-around to display the correct name in the React DevTools.
491
+ _defineProperty (interopFunction, 'name' , jsify ({'value' : displayName}));
492
+ }
493
+ // ignore: invalid_use_of_protected_member
494
+ setProperty (interopFunction, 'dartComponentVersion' , ReactDartComponentVersion .component2);
495
+ return interopFunction;
489
496
}
490
- // ignore: invalid_use_of_protected_member
491
- setProperty (interopFunction, 'dartComponentVersion' , ReactDartComponentVersion .component2);
492
- return interopFunction;
493
497
}
494
498
495
499
/// Converts a list of variadic children arguments to children that should be passed to ReactJS.
@@ -996,7 +1000,7 @@ ReactDartComponentFactoryProxy2 _registerComponent2(
996
1000
/// which produces a new `JsFunctionComponent` .
997
1001
ReactDartFunctionComponentFactoryProxy _registerFunctionComponent (DartFunctionComponent dartFunctionComponent,
998
1002
{String displayName}) =>
999
- ReactDartFunctionComponentFactoryProxy (_wrapFunctionComponent ( dartFunctionComponent, displayName: displayName) );
1003
+ ReactDartFunctionComponentFactoryProxy (dartFunctionComponent, displayName: displayName);
1000
1004
1001
1005
/// A mapping from converted/wrapped JS handler functions (the result of [_convertEventHandlers] )
1002
1006
/// to the original Dart functions (the input of [_convertEventHandlers] ).
0 commit comments