@@ -19,7 +19,15 @@ export 'package:react/src/context.dart';
19
19
export 'package:react/src/prop_validator.dart' ;
20
20
export 'package:react/react_client/react_interop.dart' show forwardRef, createRef;
21
21
22
+ typedef Error PropValidator <TProps >(TProps props, PropValidatorInfo info);
23
+
24
+ /// A React component declared using a function that takes in [props] and returns rendered output.
25
+ ///
26
+ /// See <https://facebook.github.io/react/docs/components-and-props.html#functional-and-class-components>.
27
+ typedef DartFunctionComponent = dynamic Function (Map props);
28
+
22
29
typedef T ComponentFactory <T extends Component >();
30
+
23
31
typedef ReactComponentFactoryProxy ComponentRegistrar (ComponentFactory componentFactory,
24
32
[Iterable <String > skipMethods]);
25
33
@@ -29,6 +37,9 @@ typedef ReactDartComponentFactoryProxy2 ComponentRegistrar2(
29
37
Component2BridgeFactory bridgeFactory,
30
38
});
31
39
40
+ typedef ReactDartFunctionComponentFactoryProxy FunctionComponentRegistrar (DartFunctionComponent componentFactory,
41
+ {String displayName});
42
+
32
43
/// Fragment component that allows the wrapping of children without the necessity of using
33
44
/// an element that adds an additional layer to the DOM (div, span, etc).
34
45
///
@@ -1210,6 +1221,23 @@ mixin TypedSnapshot<TSnapshot> {
1210
1221
1211
1222
/// Creates a ReactJS virtual DOM instance (`ReactElement` on the client).
1212
1223
abstract class ReactComponentFactoryProxy implements Function {
1224
+ /// The JS component factory used by this factory to build [ReactElement] s.
1225
+ ///
1226
+ /// Deprecated: Use [React.createElement()] instead and pass in [type] as
1227
+ /// the first argument, followed by `props` and `children` .
1228
+ ///
1229
+ /// Before:
1230
+ /// ```
1231
+ /// YourFactoryProxy.reactComponentFactory(props, children);
1232
+ /// ```
1233
+ ///
1234
+ /// After:
1235
+ /// ```
1236
+ /// React.createElement(YourFactoryProxy.type, props, children);
1237
+ /// ```
1238
+ @Deprecated ('6.0.0' )
1239
+ ReactJsComponentFactory reactComponentFactory;
1240
+
1213
1241
/// The type of component created by this factory.
1214
1242
get type;
1215
1243
@@ -1790,6 +1818,32 @@ ComponentRegistrar2 registerComponent2 = (
1790
1818
throw new Exception ('setClientConfiguration must be called before registerComponent.' );
1791
1819
};
1792
1820
1821
+ /// Registers [componentFactory] on client.
1822
+ ///
1823
+ /// Example:
1824
+ /// ```
1825
+ /// var myFunctionComponent = registerFunctionComponent((Map props) {
1826
+ /// return ['I am a function component', ...props.children];
1827
+ /// });
1828
+ /// ```
1829
+ ///
1830
+ /// Example with display name:
1831
+ /// ```
1832
+ /// var myFunctionComponent = registerFunctionComponent((Map props) {
1833
+ /// return ['I am a function component', ...props.children];
1834
+ /// }, displayName: 'myFunctionComponent');
1835
+ /// ```
1836
+ /// or with an inferred name from the Dart function
1837
+ /// ```
1838
+ /// myDartFunctionComponent(Map props) {
1839
+ /// return ['I am a function component', ...props.children];
1840
+ /// }
1841
+ /// var myFunctionComponent = registerFunctionComponent(myDartFunctionComponent);
1842
+ /// ```
1843
+ FunctionComponentRegistrar registerFunctionComponent = (DartFunctionComponent componentFactory, {String displayName}) {
1844
+ throw new Exception ('setClientConfiguration must be called before registerFunctionComponent.' );
1845
+ };
1846
+
1793
1847
/// The HTML `<a>` [AnchorElement] .
1794
1848
var a;
1795
1849
@@ -2594,9 +2648,15 @@ _createDOMComponents(creator) {
2594
2648
///
2595
2649
/// The arguments are assigned to global variables, and React DOM `Component` s are created by calling
2596
2650
/// [_createDOMComponents] with [domCreator] .
2597
- void setReactConfiguration (domCreator, customRegisterComponent, {ComponentRegistrar2 customRegisterComponent2}) {
2651
+ void setReactConfiguration (
2652
+ domCreator,
2653
+ customRegisterComponent, {
2654
+ ComponentRegistrar2 customRegisterComponent2,
2655
+ FunctionComponentRegistrar customRegisterFunctionComponent,
2656
+ }) {
2598
2657
registerComponent = customRegisterComponent;
2599
2658
registerComponent2 = customRegisterComponent2;
2659
+ registerFunctionComponent = customRegisterFunctionComponent;
2600
2660
// HTML Elements
2601
2661
_createDOMComponents (domCreator);
2602
2662
}
0 commit comments