From 53fd91964aa78b6884c077f75cb9739c38ed5776 Mon Sep 17 00:00:00 2001
From: Joe Bingham
Date: Wed, 29 Jul 2020 13:27:38 -0700
Subject: [PATCH 01/28] Initial implementation
---
lib/over_react.dart | 2 +-
lib/src/builder/parsing/ast_util.dart | 4 +-
lib/src/builder/parsing/members/factory.dart | 4 +-
lib/src/builder/parsing/members_from_ast.dart | 2 +-
lib/src/component/ref_util.dart | 110 ++++++++++++++++++
.../function_component.dart | 12 +-
6 files changed, 123 insertions(+), 11 deletions(-)
diff --git a/lib/over_react.dart b/lib/over_react.dart
index 11642bd9a..17f4485b2 100644
--- a/lib/over_react.dart
+++ b/lib/over_react.dart
@@ -61,7 +61,7 @@ export 'src/component_declaration/component_base_2.dart' show
UiStatefulMixin2;
export 'src/component_declaration/built_redux_component.dart';
export 'src/component_declaration/flux_component.dart';
-export 'src/component_declaration/function_component.dart';
+export 'src/component_declaration/function_component.dart' hide getFunctionName, GenericUiProps;
export 'src/util/character_constants.dart';
export 'src/util/class_names.dart';
export 'src/util/constants_base.dart';
diff --git a/lib/src/builder/parsing/ast_util.dart b/lib/src/builder/parsing/ast_util.dart
index 7326794b4..e1ef4274d 100644
--- a/lib/src/builder/parsing/ast_util.dart
+++ b/lib/src/builder/parsing/ast_util.dart
@@ -46,7 +46,7 @@ extension InitializerHelperTopLevel on TopLevelVariableDeclaration {
bool get hasGeneratedConfigArg {
return firstInitializer != null &&
anyDescendantIdentifiers(firstInitializer, (identifier) {
- if (identifier.name == 'uiFunction') {
+ if (identifier.isFunctionType) {
final args =
identifier.thisOrAncestorOfType()?.argumentList?.arguments;
if (args == null || args.length < 2) return false;
@@ -79,6 +79,8 @@ extension NameHelper on Identifier {
final self = this;
return self is PrefixedIdentifier ? self.identifier.name : self.name;
}
+
+ bool get isFunctionType => ['uiFunction', 'uiForwardRef'].contains(this.name);
}
/// Utilities related to detecting a super class on a [MixinDeclaration]
diff --git a/lib/src/builder/parsing/members/factory.dart b/lib/src/builder/parsing/members/factory.dart
index dcb3e8442..4396ee52d 100644
--- a/lib/src/builder/parsing/members/factory.dart
+++ b/lib/src/builder/parsing/members/factory.dart
@@ -40,7 +40,7 @@ class BoilerplateFactory extends BoilerplateMember {
if (isFunctionComponentFactory) {
final uiFunctionInvocation = getDescendantIdentifier(
- node.variables.firstInitializer, (identifier) => identifier.name == 'uiFunction');
+ node.variables.firstInitializer, (identifier) => identifier.isFunctionType);
final methodInvocation = uiFunctionInvocation.thisOrAncestorOfType();
final typeArgs = methodInvocation?.typeArguments?.arguments?.first;
return typeArgs;
@@ -56,7 +56,7 @@ class BoilerplateFactory extends BoilerplateMember {
bool get isFunctionComponentFactory =>
node.variables.firstInitializer != null &&
anyDescendantIdentifiers(
- node.variables.firstInitializer, (identifier) => identifier.name == 'uiFunction');
+ node.variables.firstInitializer, (identifier) => identifier.isFunctionType);
/// Verifies the correct implementation of a boilerplate factory
///
diff --git a/lib/src/builder/parsing/members_from_ast.dart b/lib/src/builder/parsing/members_from_ast.dart
index 02380d3ac..01cb2999c 100644
--- a/lib/src/builder/parsing/members_from_ast.dart
+++ b/lib/src/builder/parsing/members_from_ast.dart
@@ -170,7 +170,7 @@ class _BoilerplateMemberDetector {
final rightHandSide = node.variables.firstInitializer;
if (rightHandSide != null &&
- anyDescendantIdentifiers(rightHandSide, (identifier) => identifier.name == 'uiFunction')) {
+ anyDescendantIdentifiers(rightHandSide, (identifier) => identifier.isFunctionType)) {
onFactory(BoilerplateFactory(
node,
VersionConfidences(
diff --git a/lib/src/component/ref_util.dart b/lib/src/component/ref_util.dart
index 9d0b42300..083b64e03 100644
--- a/lib/src/component/ref_util.dart
+++ b/lib/src/component/ref_util.dart
@@ -15,6 +15,9 @@
import 'dart:js_util';
import 'package:over_react/src/component_declaration/component_type_checking.dart';
+import 'package:over_react/src/component_declaration/function_component.dart';
+import 'package:over_react/src/component_declaration/builder_helpers.dart' as bh;
+import 'package:react/react_client/js_backed_map.dart';
import 'package:react/react_client/react_interop.dart' as react_interop;
import 'package:react/react_client.dart';
import 'package:over_react/component_base.dart';
@@ -212,3 +215,110 @@ UiFactory Function(UiFactory) forwardRef
return wrapWithForwardRef;
}
+
+/// Automatically passes a [Ref] through a component to one of its children.
+///
+/// > __NOTE:__ This should only be used to wrap components that extend from `Component2`
+/// > or components using the function syntax.
+///
+/// __Example__:
+///
+/// mixin FooProps on UiProps {
+/// Ref forwardedRef;
+/// }
+///
+/// final FunctionComponentSyntax = uiForwardRef((props, ref) {
+/// return (Dom.button()
+/// ..ref = ref
+/// )('Click this button');
+/// },
+/// $FunctionSyntaxConfig, // ignore: undefined_identifier
+/// );
+///
+/// ___ OR ___
+///
+/// final DomComponentForwarded = uiForwardRef((props, ref) {
+/// return (Dom.div()
+/// ..ref = ref
+/// ..className = 'special-class'
+/// )(
+/// props.children
+/// );
+/// })(Dom.div);
+///
+/// ___ OR ___
+///
+/// final FooForwarded = uiForwardRef((props, ref) {
+/// return (Foo()
+/// ..forwardedRef = ref
+/// )();
+/// })(Foo);
+///
+/// UiFactory Foo = _$Foo;
+///
+/// mixin FooProps on UiProps {
+/// Ref forwardedRef;
+/// }
+///
+/// @Component2()
+/// class FooComponent extends UiComponent2 {
+/// @override
+/// render() {
+/// return (Dom.button()
+/// ..ref = props.forwardedRef
+/// )('Click this button');
+/// }
+/// }
+///
+/// Learn more: .
+UiFactory uiForwardRef(
+ dynamic Function(TProps props, dynamic ref) functionComponent,
+ FunctionComponentConfig config) {
+ ArgumentError.checkNotNull(config, 'config');
+
+ // ignore: invalid_use_of_protected_member
+ var propsFactory = config.propsFactory;
+
+ // Get the display name from the inner function if possible so it doesn't become `_uiFunctionWrapper`
+ final displayName = config.displayName ?? getFunctionName(functionComponent);
+
+ dynamic _uiFunctionWrapper(dynamic props, dynamic ref) {
+ return functionComponent(propsFactory.jsMap(props), ref);
+ }
+
+ ReactJsComponentFactoryProxy factory;
+
+ // It's not expected that `displayName` should ever be null, but if it is ever null and get's passed to `forwardRef`
+ // the name of the component becomes ' ' (an empty string). To protect against this ever happening, this check is in
+ // place so the name falls back to 'Anonymous'.
+ if (displayName != null) {
+ factory = react_interop.forwardRef(_uiFunctionWrapper, displayName: displayName);
+ } else {
+ factory = react_interop.forwardRef(_uiFunctionWrapper);
+ }
+
+ if (propsFactory == null) {
+ if (TProps != UiProps && TProps != GenericUiProps) {
+ throw ArgumentError(
+ 'config.propsFactory must be provided when using custom props classes');
+ }
+ propsFactory = PropsFactory.fromUiFactory(
+ ([backingMap]) => GenericUiProps(factory, backingMap))
+ as PropsFactory;
+ }
+
+ TProps _uiFactory([Map backingMap]) {
+ TProps builder;
+ if (backingMap == null) {
+ builder = propsFactory.jsMap(JsBackedMap());
+ } else if (backingMap is JsBackedMap) {
+ builder = propsFactory.jsMap(backingMap);
+ } else {
+ builder = propsFactory.map(backingMap);
+ }
+
+ return builder..componentFactory = factory;
+ }
+
+ return _uiFactory;
+}
diff --git a/lib/src/component_declaration/function_component.dart b/lib/src/component_declaration/function_component.dart
index 419ce6d13..20a74491b 100644
--- a/lib/src/component_declaration/function_component.dart
+++ b/lib/src/component_declaration/function_component.dart
@@ -98,7 +98,7 @@ UiFactory uiFunction(
var propsFactory = config.propsFactory;
// Get the display name from the inner function if possible so it doesn't become `_uiFunctionWrapper`
- final displayName = config.displayName ?? _getFunctionName(functionComponent);
+ final displayName = config.displayName ?? getFunctionName(functionComponent);
dynamic _uiFunctionWrapper(JsBackedMap props) {
return functionComponent(propsFactory.jsMap(props));
@@ -110,12 +110,12 @@ UiFactory uiFunction(
);
if (propsFactory == null) {
- if (TProps != UiProps && TProps != _GenericUiProps) {
+ if (TProps != UiProps && TProps != GenericUiProps) {
throw ArgumentError(
'config.propsFactory must be provided when using custom props classes');
}
propsFactory = PropsFactory.fromUiFactory(
- ([backingMap]) => _GenericUiProps(factory, backingMap))
+ ([backingMap]) => GenericUiProps(factory, backingMap))
as PropsFactory;
}
@@ -135,16 +135,16 @@ UiFactory uiFunction(
return _uiFactory;
}
-String _getFunctionName(Function function) {
+String getFunctionName(Function function) {
return getProperty(function, 'name') ??
getProperty(function, '\$static_name');
}
-class _GenericUiProps extends UiProps {
+class GenericUiProps extends UiProps {
@override
final Map props;
- _GenericUiProps(ReactComponentFactoryProxy componentFactory, [Map props])
+ GenericUiProps(ReactComponentFactoryProxy componentFactory, [Map props])
: this.props = props ?? JsBackedMap() {
this.componentFactory = componentFactory;
}
From 968de33e4502819a796123d56b153eda098d1f0d Mon Sep 17 00:00:00 2001
From: Joe Bingham
Date: Wed, 29 Jul 2020 13:28:18 -0700
Subject: [PATCH 02/28] Add first go at examples
---
web/component2/index.dart | 17 +-
web/component2/index.html | 12 +-
web/component2/src/demos/forward_ref.dart | 256 ++++-
.../src/demos/forward_ref.over_react.g.dart | 897 ++++++++++++++++--
4 files changed, 1085 insertions(+), 97 deletions(-)
diff --git a/web/component2/index.dart b/web/component2/index.dart
index 962f9ff5a..2ee42ccd4 100644
--- a/web/component2/index.dart
+++ b/web/component2/index.dart
@@ -22,7 +22,6 @@ import 'src/demos.dart';
void main() {
setClientConfiguration();
- final fancyButtonNodeRef = createRef();
react_dom.render(
buttonExamplesDemo(), querySelector('$demoMountNodeSelectorPrefix--button'));
@@ -42,18 +41,6 @@ void main() {
react_dom.render(
radioToggleButtonDemo(), querySelector('$demoMountNodeSelectorPrefix--radio-toggle'));
- react_dom.render(
- (LogProps()
- ..builder = FancyButton
- ..className = 'btn btn-primary'
- ..ref = fancyButtonNodeRef
- ..onClick = (_) {
- print(fancyButtonNodeRef.current.outerHtml);
- }
- )(),
- querySelector('$demoMountNodeSelectorPrefix--forwardRef'),
- );
-
react_dom.render(
(v2.ErrorBoundary()
..onComponentDidCatch = (error, info) {
@@ -102,4 +89,8 @@ void main() {
react_dom.render(ListExample()(), querySelector('$demoMountNodeSelectorPrefix--list-component'));
react_dom.render(NumExample()(), querySelector('$demoMountNodeSelectorPrefix--num-component'));
react_dom.render(StringExample()(), querySelector('$demoMountNodeSelectorPrefix--string-component'));
+ react_dom.render(
+ (RefDemoContainer())(),
+ querySelector('$demoMountNodeSelectorPrefix--forwardRef'),
+ );
}
diff --git a/web/component2/index.html b/web/component2/index.html
index bf1dee7aa..17e432657 100644
--- a/web/component2/index.html
+++ b/web/component2/index.html
@@ -67,12 +67,6 @@ ToggleButton (Radio)
around with the component rendered below.
-
-
ForwardRef
-
Modify the source of /web/component2/src/demos/forward_ref.dart to play
- around with the component rendered below.
-
-
Component That Throws A Caught Error
(Deprecated ErrorBoundary Component)
@@ -129,6 +123,12 @@
String Component
Num Component
+
+
Ref Examples
+
Modify the source of /web/component2/src/demos/forward_ref.dart to play
+ around with the component rendered below.
+
+
diff --git a/web/component2/src/demos/forward_ref.dart b/web/component2/src/demos/forward_ref.dart
index 3b0fffb1f..fb49a9dc4 100644
--- a/web/component2/src/demos/forward_ref.dart
+++ b/web/component2/src/demos/forward_ref.dart
@@ -1,31 +1,99 @@
+import 'dart:html';
+
import 'package:over_react/over_react.dart';
// ignore: uri_has_not_been_generated
part 'forward_ref.over_react.g.dart';
-final FancyButton = forwardRef((props, ref) {
- final classes = ClassNameBuilder.fromProps(props)
- ..add('FancyButton');
+// ------------ `uiForwardRef` with a function component (simple) ------------
+mixin UiForwardRefLogsFunctionComponentProps on UiProps {
+ BuilderOnlyUiFactory builder;
+
+ // Private since we only use this to pass along the value of `ref` to
+ // the return value of forwardRef.
+ //
+ // Consumers can set this private field value using the public `ref` setter.
+ Ref _forwardedRef;
+}
+
+final UiForwardRefLogsFunctionComponent = uiForwardRef(
+ (props, ref) {
+ return ((props.builder()
+ ..id = props.id
+ ..className = props.className
+ ..onClick = props.onClick
+ ..ref = ref)(props.children));
+ },
+ $UiForwardRefLogsFunctionComponentConfig, // ignore: undefined_identifier
+);
+
+// ------------ `uiForwardRef` with a function component (complex) ------------
+mixin UiForwardRefLogsPropsComplexFunctionComponentPropsMixin on UiProps {
+ String buttonDescription;
+}
+
+class UiForwardRefLogsPropsComplexFunctionComponentProps = UiProps
+ with
+ UiForwardRefLogsPropsComplexFunctionComponentPropsMixin,
+ UiForwardRefLogsFunctionComponentProps;
+
+final UiForwardRefLogsPropsComplexFunctionComponent =
+ uiForwardRef(
+ (props, ref) {
+ return (Fragment()(
+ Dom.div()(props.buttonDescription),
+ (props.builder()
+ ..id = props.id
+ ..className = props.className
+ ..onClick = props.onClick
+ ..ref = ref)(props.children),
+ ));
+ },
+ $UiForwardRefLogsPropsComplexFunctionComponentConfig, // ignore: undefined_identifier
+);
+
+// ------------ `uiForwardRef` with a class component (simple) ------------
+final UiForwardRefLogsPropsComponent = uiForwardRef(
+ (props, ref) {
+ return (_LogsPropsFunctionComponent()
+ ..addProps(props)
+ .._forwardedRef = ref)();
+ },
+ FunctionComponentConfig(
+ propsFactory: PropsFactory.fromUiFactory(_LogsPropsFunctionComponent), displayName: null),
+);
+
+// ------------ `uiForwardRef` with a class component (complex) ------------
+mixin UiForwardRefLogsPropsComplexComponentPropsMixin on UiProps {
+ String buttonDescription;
+}
+
+class UiForwardRefLogsPropsComplexComponentProps = UiProps
+ with UiForwardRefLogsPropsComplexFunctionComponentPropsMixin, LogPropsProps;
- return (Dom.button()
- ..addProps(getPropsToForward(props, onlyCopyDomProps: true))
- ..className = classes.toClassName()
- ..ref = ref
- )('Click me!');
-}, displayName: 'FancyButton')(Dom.button);
+final UiForwardRefLogsPropsComplexComponent =
+ uiForwardRef(
+ (props, ref) {
+ return Fragment()(
+ Dom.div()(props.buttonDescription),
+ (_LogsPropsFunctionComponent()
+ ..addProps(props)
+ .._forwardedRef = ref)(),
+ );
+ },
+ $UiForwardRefLogsPropsComplexComponentConfig, // ignore: undefined_identifier
+);
+// ------------ `forwardRef` (deprecated) with class component ------------
final LogProps = forwardRef((props, ref) {
return (_LogProps()
..addProps(props)
- .._forwardedRef = ref
- )('Click me!');
+ .._forwardedRef = ref)();
}, displayName: 'LogProps')(_LogProps);
-@Factory()
UiFactory _LogProps = _$_LogProps;
-@Props()
-class _$LogPropsProps extends UiProps {
+mixin LogPropsProps on UiProps {
BuilderOnlyUiFactory builder;
// Private since we only use this to pass along the value of `ref` to
@@ -35,7 +103,6 @@ class _$LogPropsProps extends UiProps {
Ref _forwardedRef;
}
-@Component2()
class LogPropsComponent extends UiComponent2 {
@override
void componentDidUpdate(Map prevProps, _, [__]) {
@@ -47,7 +114,160 @@ class LogPropsComponent extends UiComponent2 {
render() {
return (props.builder()
..modifyProps(addUnconsumedDomProps)
- ..ref = props._forwardedRef
- )(props.children);
+ ..ref = props._forwardedRef)(props.children);
}
-}
\ No newline at end of file
+}
+
+// ------------ `forwardRef` (deprecated) with Function component ------------
+final LogsPropsFunctionComponent = forwardRef<_LogsPropsFunctionComponentProps>((props, ref) {
+ return (_LogsPropsFunctionComponent()
+ ..addProps(props)
+ .._forwardedRef = ref)();
+}, displayName: 'LogsPropsFunctionComponent')(_LogsPropsFunctionComponent);
+
+class _LogsPropsFunctionComponentProps = UiProps with LogPropsProps;
+
+final _LogsPropsFunctionComponent = uiFunction<_LogsPropsFunctionComponentProps>(
+ (props) {
+ return ((props.builder()
+ ..id = props.id
+ ..className = props.className
+ ..onClick = props.onClick
+ ..ref = props._forwardedRef)(props.children));
+ },
+ $_LogsPropsFunctionComponentConfig, // ignore: undefined_identifier
+);
+
+// -------------------------------- Demo Display Logic --------------------------------
+final FancyButton = uiForwardRef(
+ (props, ref) {
+ final classes = ClassNameBuilder.fromProps(props)..add('FancyButton');
+
+ return (Dom.button()
+ ..addProps(getPropsToForward(props, onlyCopyDomProps: true))
+ ..className = classes.toClassName()
+ ..ref = ref)('Click me!');
+ },
+ FunctionComponentConfig(propsFactory: PropsFactory.fromUiFactory(Dom.button), displayName: null),
+);
+
+mixin RefDemoProps on UiProps {}
+
+final RefDemoContainer = uiFunction(
+ (props) {
+ // `uiForwardRef` Refs
+ final buttonNodeRefForSimpleFunctionComponent = createRef();
+ final buttonNodeRefForComplexFunctionComponent = createRef();
+ final buttonNodeRefForSimpleComponent = createRef();
+ final buttonNodeRefForComplexComponent = createRef();
+
+ // `forwardRef` Refs
+ final fancyButtonNodeRef = createRef();
+ final fancyFunctionalButtonNodeRef = createRef();
+
+ return ((Dom.div()..style = {'padding': 10})(
+ (RefDemoSection()..sectionTitle = 'uiForwardRef Demos')(
+ (RefDemoHoc()..demoTitle = '`uiForwardRef` with a function component (simple)')(
+ (UiForwardRefLogsFunctionComponent()
+ ..builder = FancyButton
+ ..id = 'uiForwardRef-function-component'
+ ..className = 'btn btn-primary'
+ ..ref = buttonNodeRefForSimpleFunctionComponent
+ ..onClick = (_) {
+ print(buttonNodeRefForSimpleFunctionComponent.current.outerHtml);
+ })(),
+ ),
+ (RefDemoHoc()..demoTitle = '`uiForwardRef` with a function component (complex)')(
+ (UiForwardRefLogsPropsComplexFunctionComponent()
+ ..buttonDescription = 'A button that logs the innerHtml'
+ ..builder = FancyButton
+ ..id = 'uiForwardRef-function-complex-component'
+ ..className = 'btn btn-success'
+ ..ref = buttonNodeRefForComplexFunctionComponent
+ ..onClick = (_) {
+ print(buttonNodeRefForComplexFunctionComponent.current.outerHtml);
+ })(),
+ ),
+ (RefDemoHoc()..demoTitle = '`uiForwardRef` with a class component (simple)')(
+ (UiForwardRefLogsPropsComponent()
+ ..builder = FancyButton
+ ..id = 'uiForwardRef-component'
+ ..className = 'btn btn-warning'
+ ..ref = buttonNodeRefForSimpleComponent
+ ..onClick = (_) {
+ print(buttonNodeRefForSimpleComponent.current.outerHtml);
+ })(),
+ ),
+ (RefDemoHoc()..demoTitle = '`uiForwardRef` with a class component (complex)')(
+ (UiForwardRefLogsPropsComplexComponent()
+ ..buttonDescription = 'A button that logs the innerHtml'
+ ..builder = FancyButton
+ ..id = 'uiForwardRef-complex-component'
+ ..className = 'btn btn-danger'
+ ..ref = buttonNodeRefForComplexComponent
+ ..onClick = (_) {
+ print(buttonNodeRefForComplexComponent.current.outerHtml);
+ })(),
+ ),
+ ),
+ (RefDemoSection()..sectionTitle = 'forwardRef (deprecated) Demos')(
+ (RefDemoHoc()..demoTitle = '`forwardRef` with class component')(
+ (LogProps()
+ ..builder = FancyButton
+ ..id = 'forwardRef-component'
+ ..className = 'btn btn-primary'
+ ..ref = fancyButtonNodeRef
+ ..onClick = (_) {
+ print(fancyButtonNodeRef.current.outerHtml);
+ })(),
+ ),
+ (RefDemoHoc()..demoTitle = '`uiForwardRef` with function component')(
+ (LogsPropsFunctionComponent()
+ ..builder = FancyButton
+ ..id = 'forwardRef-function-component'
+ ..className = 'btn btn-success'
+ ..ref = fancyFunctionalButtonNodeRef
+ ..onClick = (_) {
+ print(fancyFunctionalButtonNodeRef.current.outerHtml);
+ })(),
+ ),
+ ),
+ ));
+ },
+ $RefDemoContainerConfig, // ignore: undefined_identifier
+);
+
+mixin RefDemoSectionProps on UiProps {
+ String sectionTitle;
+}
+
+final RefDemoSection = uiFunction(
+ (props) {
+ return (Fragment()(
+ (Dom.h3()..style = {'color': 'gray', 'borderBottom': '1px solid gray', 'marginTop': 10})(
+ props.sectionTitle,
+ ),
+ (Dom.div()
+ ..style = {
+ 'display': 'flex',
+ 'flexWrap': 'wrap',
+ })(
+ props.children,
+ )));
+ },
+ $RefDemoSectionConfig, // ignore: undefined_identifier
+);
+
+mixin RefDemoHocProps on UiProps {
+ String demoTitle;
+}
+
+final RefDemoHoc = uiFunction(
+ (props) {
+ return ((Dom.div()..style = {'flex': '0 50%', 'width': '100%', 'marginTop': 10})(
+ Dom.h4()(props.demoTitle),
+ props.children,
+ ));
+ },
+ $RefDemoHocConfig, // ignore: undefined_identifier
+);
diff --git a/web/component2/src/demos/forward_ref.over_react.g.dart b/web/component2/src/demos/forward_ref.over_react.g.dart
index ff2b05aa5..3abfce35a 100644
--- a/web/component2/src/demos/forward_ref.over_react.g.dart
+++ b/web/component2/src/demos/forward_ref.over_react.g.dart
@@ -10,66 +10,17 @@ part of 'forward_ref.dart';
// React component factory implementation.
//
// Registers component implementation and links type meta to builder factory.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
final $LogPropsComponentFactory = registerComponent2(
() => _$LogPropsComponent(),
- builderFactory: _LogProps,
+ builderFactory: _$_LogProps,
componentClass: LogPropsComponent,
isWrapper: false,
parentType: null,
displayName: '_LogProps',
);
-abstract class _$LogPropsPropsAccessorsMixin implements _$LogPropsProps {
- @override
- Map get props;
-
- ///
- @override
- BuilderOnlyUiFactory get builder =>
- props[_$key__builder___$LogPropsProps] ??
- null; // Add ` ?? null` to workaround DDC bug: ;
- ///
- @override
- set builder(BuilderOnlyUiFactory value) =>
- props[_$key__builder___$LogPropsProps] = value;
-
- ///
- @override
- Ref get _forwardedRef =>
- props[_$key___forwardedRef___$LogPropsProps] ??
- null; // Add ` ?? null` to workaround DDC bug: ;
- ///
- @override
- set _forwardedRef(Ref value) =>
- props[_$key___forwardedRef___$LogPropsProps] = value;
- /* GENERATED CONSTANTS */
- static const PropDescriptor _$prop__builder___$LogPropsProps =
- PropDescriptor(_$key__builder___$LogPropsProps);
- static const PropDescriptor _$prop___forwardedRef___$LogPropsProps =
- PropDescriptor(_$key___forwardedRef___$LogPropsProps);
- static const String _$key__builder___$LogPropsProps = 'LogPropsProps.builder';
- static const String _$key___forwardedRef___$LogPropsProps =
- 'LogPropsProps._forwardedRef';
-
- static const List $props = [
- _$prop__builder___$LogPropsProps,
- _$prop___forwardedRef___$LogPropsProps
- ];
- static const List $propKeys = [
- _$key__builder___$LogPropsProps,
- _$key___forwardedRef___$LogPropsProps
- ];
-}
-
-const PropsMeta _$metaForLogPropsProps = PropsMeta(
- fields: _$LogPropsPropsAccessorsMixin.$props,
- keys: _$LogPropsPropsAccessorsMixin.$propKeys,
-);
-
-class LogPropsProps extends _$LogPropsProps with _$LogPropsPropsAccessorsMixin {
- static const PropsMeta meta = _$metaForLogPropsProps;
-}
-
_$$LogPropsProps _$_LogProps([Map backingProps]) => backingProps == null
? _$$LogPropsProps$JsMap(JsBackedMap())
: _$$LogPropsProps(backingProps);
@@ -77,9 +28,13 @@ _$$LogPropsProps _$_LogProps([Map backingProps]) => backingProps == null
// Concrete props implementation.
//
// Implements constructor and backing map, and links up to generated component factory.
-abstract class _$$LogPropsProps extends _$LogPropsProps
- with _$LogPropsPropsAccessorsMixin
- implements LogPropsProps {
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+abstract class _$$LogPropsProps extends UiProps
+ with
+ LogPropsProps,
+ $LogPropsProps // If this generated mixin is undefined, it's likely because LogPropsProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of LogPropsProps.
+{
_$$LogPropsProps._();
factory _$$LogPropsProps(Map backingMap) {
@@ -101,10 +56,12 @@ abstract class _$$LogPropsProps extends _$LogPropsProps
/// The default namespace for the prop getters/setters generated for this class.
@override
- String get propKeyNamespace => 'LogPropsProps.';
+ String get propKeyNamespace => '';
}
// Concrete props implementation that can be backed by any [Map].
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
class _$$LogPropsProps$PlainMap extends _$$LogPropsProps {
// This initializer of `_props` to an empty map, as well as the reassignment
// of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
@@ -122,6 +79,8 @@ class _$$LogPropsProps$PlainMap extends _$$LogPropsProps {
// Concrete props implementation that can only be backed by [JsMap],
// allowing dart2js to compile more optimal code for key-value pair reads/writes.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
class _$$LogPropsProps$JsMap extends _$$LogPropsProps {
// This initializer of `_props` to an empty map, as well as the reassignment
// of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
@@ -141,6 +100,8 @@ class _$$LogPropsProps$JsMap extends _$$LogPropsProps {
//
// Implements typed props/state factories, defaults `consumedPropKeys` to the keys
// generated for the associated props class.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
class _$LogPropsComponent extends LogPropsComponent {
_$$LogPropsProps$JsMap _cachedTypedProps;
@@ -172,10 +133,826 @@ class _$LogPropsComponent extends LogPropsComponent {
@override
bool get $isClassGenerated => true;
- /// The default consumed props, taken from _$LogPropsProps.
- /// Used in `ConsumedProps` if [consumedProps] is not overridden.
+ /// The default consumed props, comprising all props mixins used by LogPropsProps.
+ /// Used in `*ConsumedProps` methods if [consumedProps] is not overridden.
+ @override
+ get $defaultConsumedProps => propsMeta.all;
+
+ @override
+ PropsMetaCollection get propsMeta => const PropsMetaCollection({
+ // If this generated mixin is undefined, it's likely because LogPropsProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of LogPropsProps.
+ LogPropsProps: $LogPropsProps.meta,
+ });
+}
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.'
+ ' EXCEPTION: this may be used in legacy boilerplate until'
+ ' it is transitioned to the new mixin-based boilerplate.')
+mixin $UiForwardRefLogsFunctionComponentProps
+ on UiForwardRefLogsFunctionComponentProps {
+ static const PropsMeta meta = _$metaForUiForwardRefLogsFunctionComponentProps;
@override
- final List $defaultConsumedProps = const [
- _$metaForLogPropsProps
+ BuilderOnlyUiFactory get builder =>
+ props[_$key__builder__UiForwardRefLogsFunctionComponentProps] ??
+ null; // Add ` ?? null` to workaround DDC bug: ;
+ @override
+ set builder(BuilderOnlyUiFactory value) =>
+ props[_$key__builder__UiForwardRefLogsFunctionComponentProps] = value;
+ @override
+ Ref get _forwardedRef =>
+ props[_$key___forwardedRef__UiForwardRefLogsFunctionComponentProps] ??
+ null; // Add ` ?? null` to workaround DDC bug: ;
+ @override
+ set _forwardedRef(Ref value) =>
+ props[_$key___forwardedRef__UiForwardRefLogsFunctionComponentProps] =
+ value;
+ /* GENERATED CONSTANTS */
+ static const PropDescriptor
+ _$prop__builder__UiForwardRefLogsFunctionComponentProps =
+ PropDescriptor(_$key__builder__UiForwardRefLogsFunctionComponentProps);
+ static const PropDescriptor
+ _$prop___forwardedRef__UiForwardRefLogsFunctionComponentProps =
+ PropDescriptor(
+ _$key___forwardedRef__UiForwardRefLogsFunctionComponentProps);
+ static const String _$key__builder__UiForwardRefLogsFunctionComponentProps =
+ 'UiForwardRefLogsFunctionComponentProps.builder';
+ static const String
+ _$key___forwardedRef__UiForwardRefLogsFunctionComponentProps =
+ 'UiForwardRefLogsFunctionComponentProps._forwardedRef';
+
+ static const List $props = [
+ _$prop__builder__UiForwardRefLogsFunctionComponentProps,
+ _$prop___forwardedRef__UiForwardRefLogsFunctionComponentProps
+ ];
+ static const List $propKeys = [
+ _$key__builder__UiForwardRefLogsFunctionComponentProps,
+ _$key___forwardedRef__UiForwardRefLogsFunctionComponentProps
+ ];
+}
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+const PropsMeta _$metaForUiForwardRefLogsFunctionComponentProps = PropsMeta(
+ fields: $UiForwardRefLogsFunctionComponentProps.$props,
+ keys: $UiForwardRefLogsFunctionComponentProps.$propKeys,
+);
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.'
+ ' EXCEPTION: this may be used in legacy boilerplate until'
+ ' it is transitioned to the new mixin-based boilerplate.')
+mixin $UiForwardRefLogsPropsComplexFunctionComponentPropsMixin
+ on UiForwardRefLogsPropsComplexFunctionComponentPropsMixin {
+ static const PropsMeta meta =
+ _$metaForUiForwardRefLogsPropsComplexFunctionComponentPropsMixin;
+ @override
+ String get buttonDescription =>
+ props[
+ _$key__buttonDescription__UiForwardRefLogsPropsComplexFunctionComponentPropsMixin] ??
+ null; // Add ` ?? null` to workaround DDC bug: ;
+ @override
+ set buttonDescription(String value) => props[
+ _$key__buttonDescription__UiForwardRefLogsPropsComplexFunctionComponentPropsMixin] =
+ value;
+ /* GENERATED CONSTANTS */
+ static const PropDescriptor
+ _$prop__buttonDescription__UiForwardRefLogsPropsComplexFunctionComponentPropsMixin =
+ PropDescriptor(
+ _$key__buttonDescription__UiForwardRefLogsPropsComplexFunctionComponentPropsMixin);
+ static const String
+ _$key__buttonDescription__UiForwardRefLogsPropsComplexFunctionComponentPropsMixin =
+ 'UiForwardRefLogsPropsComplexFunctionComponentPropsMixin.buttonDescription';
+
+ static const List $props = [
+ _$prop__buttonDescription__UiForwardRefLogsPropsComplexFunctionComponentPropsMixin
+ ];
+ static const List $propKeys = [
+ _$key__buttonDescription__UiForwardRefLogsPropsComplexFunctionComponentPropsMixin
+ ];
+}
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+const PropsMeta
+ _$metaForUiForwardRefLogsPropsComplexFunctionComponentPropsMixin =
+ PropsMeta(
+ fields: $UiForwardRefLogsPropsComplexFunctionComponentPropsMixin.$props,
+ keys: $UiForwardRefLogsPropsComplexFunctionComponentPropsMixin.$propKeys,
+);
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.'
+ ' EXCEPTION: this may be used in legacy boilerplate until'
+ ' it is transitioned to the new mixin-based boilerplate.')
+mixin $UiForwardRefLogsPropsComplexComponentPropsMixin
+ on UiForwardRefLogsPropsComplexComponentPropsMixin {
+ static const PropsMeta meta =
+ _$metaForUiForwardRefLogsPropsComplexComponentPropsMixin;
+ @override
+ String get buttonDescription =>
+ props[
+ _$key__buttonDescription__UiForwardRefLogsPropsComplexComponentPropsMixin] ??
+ null; // Add ` ?? null` to workaround DDC bug: ;
+ @override
+ set buttonDescription(String value) => props[
+ _$key__buttonDescription__UiForwardRefLogsPropsComplexComponentPropsMixin] =
+ value;
+ /* GENERATED CONSTANTS */
+ static const PropDescriptor
+ _$prop__buttonDescription__UiForwardRefLogsPropsComplexComponentPropsMixin =
+ PropDescriptor(
+ _$key__buttonDescription__UiForwardRefLogsPropsComplexComponentPropsMixin);
+ static const String
+ _$key__buttonDescription__UiForwardRefLogsPropsComplexComponentPropsMixin =
+ 'UiForwardRefLogsPropsComplexComponentPropsMixin.buttonDescription';
+
+ static const List $props = [
+ _$prop__buttonDescription__UiForwardRefLogsPropsComplexComponentPropsMixin
+ ];
+ static const List $propKeys = [
+ _$key__buttonDescription__UiForwardRefLogsPropsComplexComponentPropsMixin
+ ];
+}
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+const PropsMeta _$metaForUiForwardRefLogsPropsComplexComponentPropsMixin =
+ PropsMeta(
+ fields: $UiForwardRefLogsPropsComplexComponentPropsMixin.$props,
+ keys: $UiForwardRefLogsPropsComplexComponentPropsMixin.$propKeys,
+);
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.'
+ ' EXCEPTION: this may be used in legacy boilerplate until'
+ ' it is transitioned to the new mixin-based boilerplate.')
+mixin $LogPropsProps on LogPropsProps {
+ static const PropsMeta meta = _$metaForLogPropsProps;
+ @override
+ BuilderOnlyUiFactory get builder =>
+ props[_$key__builder__LogPropsProps] ??
+ null; // Add ` ?? null` to workaround DDC bug: ;
+ @override
+ set builder(BuilderOnlyUiFactory value) =>
+ props[_$key__builder__LogPropsProps] = value;
+ @override
+ Ref get _forwardedRef =>
+ props[_$key___forwardedRef__LogPropsProps] ??
+ null; // Add ` ?? null` to workaround DDC bug: ;
+ @override
+ set _forwardedRef(Ref value) =>
+ props[_$key___forwardedRef__LogPropsProps] = value;
+ /* GENERATED CONSTANTS */
+ static const PropDescriptor _$prop__builder__LogPropsProps =
+ PropDescriptor(_$key__builder__LogPropsProps);
+ static const PropDescriptor _$prop___forwardedRef__LogPropsProps =
+ PropDescriptor(_$key___forwardedRef__LogPropsProps);
+ static const String _$key__builder__LogPropsProps = 'LogPropsProps.builder';
+ static const String _$key___forwardedRef__LogPropsProps =
+ 'LogPropsProps._forwardedRef';
+
+ static const List $props = [
+ _$prop__builder__LogPropsProps,
+ _$prop___forwardedRef__LogPropsProps
+ ];
+ static const List $propKeys = [
+ _$key__builder__LogPropsProps,
+ _$key___forwardedRef__LogPropsProps
+ ];
+}
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+const PropsMeta _$metaForLogPropsProps = PropsMeta(
+ fields: $LogPropsProps.$props,
+ keys: $LogPropsProps.$propKeys,
+);
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.'
+ ' EXCEPTION: this may be used in legacy boilerplate until'
+ ' it is transitioned to the new mixin-based boilerplate.')
+mixin $RefDemoProps on RefDemoProps {
+ static const PropsMeta meta = _$metaForRefDemoProps;
+ /* GENERATED CONSTANTS */
+
+ static const List $props = [];
+ static const List $propKeys = [];
+}
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+const PropsMeta _$metaForRefDemoProps = PropsMeta(
+ fields: $RefDemoProps.$props,
+ keys: $RefDemoProps.$propKeys,
+);
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.'
+ ' EXCEPTION: this may be used in legacy boilerplate until'
+ ' it is transitioned to the new mixin-based boilerplate.')
+mixin $RefDemoSectionProps on RefDemoSectionProps {
+ static const PropsMeta meta = _$metaForRefDemoSectionProps;
+ @override
+ String get sectionTitle =>
+ props[_$key__sectionTitle__RefDemoSectionProps] ??
+ null; // Add ` ?? null` to workaround DDC bug: ;
+ @override
+ set sectionTitle(String value) =>
+ props[_$key__sectionTitle__RefDemoSectionProps] = value;
+ /* GENERATED CONSTANTS */
+ static const PropDescriptor _$prop__sectionTitle__RefDemoSectionProps =
+ PropDescriptor(_$key__sectionTitle__RefDemoSectionProps);
+ static const String _$key__sectionTitle__RefDemoSectionProps =
+ 'RefDemoSectionProps.sectionTitle';
+
+ static const List $props = [
+ _$prop__sectionTitle__RefDemoSectionProps
+ ];
+ static const List $propKeys = [
+ _$key__sectionTitle__RefDemoSectionProps
];
}
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+const PropsMeta _$metaForRefDemoSectionProps = PropsMeta(
+ fields: $RefDemoSectionProps.$props,
+ keys: $RefDemoSectionProps.$propKeys,
+);
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.'
+ ' EXCEPTION: this may be used in legacy boilerplate until'
+ ' it is transitioned to the new mixin-based boilerplate.')
+mixin $RefDemoHocProps on RefDemoHocProps {
+ static const PropsMeta meta = _$metaForRefDemoHocProps;
+ @override
+ String get demoTitle =>
+ props[_$key__demoTitle__RefDemoHocProps] ??
+ null; // Add ` ?? null` to workaround DDC bug: ;
+ @override
+ set demoTitle(String value) =>
+ props[_$key__demoTitle__RefDemoHocProps] = value;
+ /* GENERATED CONSTANTS */
+ static const PropDescriptor _$prop__demoTitle__RefDemoHocProps =
+ PropDescriptor(_$key__demoTitle__RefDemoHocProps);
+ static const String _$key__demoTitle__RefDemoHocProps =
+ 'RefDemoHocProps.demoTitle';
+
+ static const List $props = [
+ _$prop__demoTitle__RefDemoHocProps
+ ];
+ static const List $propKeys = [_$key__demoTitle__RefDemoHocProps];
+}
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+const PropsMeta _$metaForRefDemoHocProps = PropsMeta(
+ fields: $RefDemoHocProps.$props,
+ keys: $RefDemoHocProps.$propKeys,
+);
+
+final FunctionComponentConfig<_$$UiForwardRefLogsFunctionComponentProps>
+ $UiForwardRefLogsFunctionComponentConfig = FunctionComponentConfig(
+ propsFactory: PropsFactory(
+ map: (map) => _$$UiForwardRefLogsFunctionComponentProps(map),
+ jsMap: (map) => _$$UiForwardRefLogsFunctionComponentProps$JsMap(map),
+ ),
+ displayName: 'UiForwardRefLogsFunctionComponent');
+
+// Concrete props implementation.
+//
+// Implements constructor and backing map, and links up to generated component factory.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+abstract class _$$UiForwardRefLogsFunctionComponentProps extends UiProps
+ with
+ UiForwardRefLogsFunctionComponentProps,
+ $UiForwardRefLogsFunctionComponentProps // If this generated mixin is undefined, it's likely because UiForwardRefLogsFunctionComponentProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of UiForwardRefLogsFunctionComponentProps.
+{
+ _$$UiForwardRefLogsFunctionComponentProps._();
+
+ factory _$$UiForwardRefLogsFunctionComponentProps(Map backingMap) {
+ if (backingMap == null || backingMap is JsBackedMap) {
+ return _$$UiForwardRefLogsFunctionComponentProps$JsMap(backingMap);
+ } else {
+ return _$$UiForwardRefLogsFunctionComponentProps$PlainMap(backingMap);
+ }
+ }
+
+ /// Let `UiProps` internals know that this class has been generated.
+ @override
+ bool get $isClassGenerated => true;
+
+ /// The default namespace for the prop getters/setters generated for this class.
+ @override
+ String get propKeyNamespace => '';
+}
+
+// Concrete props implementation that can be backed by any [Map].
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$UiForwardRefLogsFunctionComponentProps$PlainMap
+ extends _$$UiForwardRefLogsFunctionComponentProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$UiForwardRefLogsFunctionComponentProps$PlainMap(Map backingMap)
+ : this._props = {},
+ super._() {
+ this._props = backingMap ?? {};
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ Map get props => _props;
+ Map _props;
+}
+
+// Concrete props implementation that can only be backed by [JsMap],
+// allowing dart2js to compile more optimal code for key-value pair reads/writes.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$UiForwardRefLogsFunctionComponentProps$JsMap
+ extends _$$UiForwardRefLogsFunctionComponentProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$UiForwardRefLogsFunctionComponentProps$JsMap(JsBackedMap backingMap)
+ : this._props = JsBackedMap(),
+ super._() {
+ this._props = backingMap ?? JsBackedMap();
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ JsBackedMap get props => _props;
+ JsBackedMap _props;
+}
+
+final FunctionComponentConfig<
+ _$$UiForwardRefLogsPropsComplexFunctionComponentProps>
+ $UiForwardRefLogsPropsComplexFunctionComponentConfig =
+ FunctionComponentConfig(
+ propsFactory: PropsFactory(
+ map: (map) =>
+ _$$UiForwardRefLogsPropsComplexFunctionComponentProps(map),
+ jsMap: (map) =>
+ _$$UiForwardRefLogsPropsComplexFunctionComponentProps$JsMap(map),
+ ),
+ displayName: 'UiForwardRefLogsPropsComplexFunctionComponent');
+
+// Concrete props implementation.
+//
+// Implements constructor and backing map, and links up to generated component factory.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+abstract class _$$UiForwardRefLogsPropsComplexFunctionComponentProps
+ extends UiProps
+ with
+ UiForwardRefLogsPropsComplexFunctionComponentPropsMixin,
+ $UiForwardRefLogsPropsComplexFunctionComponentPropsMixin, // If this generated mixin is undefined, it's likely because UiForwardRefLogsPropsComplexFunctionComponentPropsMixin is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of UiForwardRefLogsPropsComplexFunctionComponentPropsMixin.
+ UiForwardRefLogsFunctionComponentProps,
+ $UiForwardRefLogsFunctionComponentProps // If this generated mixin is undefined, it's likely because UiForwardRefLogsFunctionComponentProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of UiForwardRefLogsFunctionComponentProps.
+ implements
+ UiForwardRefLogsPropsComplexFunctionComponentProps {
+ _$$UiForwardRefLogsPropsComplexFunctionComponentProps._();
+
+ factory _$$UiForwardRefLogsPropsComplexFunctionComponentProps(
+ Map backingMap) {
+ if (backingMap == null || backingMap is JsBackedMap) {
+ return _$$UiForwardRefLogsPropsComplexFunctionComponentProps$JsMap(
+ backingMap);
+ } else {
+ return _$$UiForwardRefLogsPropsComplexFunctionComponentProps$PlainMap(
+ backingMap);
+ }
+ }
+
+ /// Let `UiProps` internals know that this class has been generated.
+ @override
+ bool get $isClassGenerated => true;
+
+ /// The default namespace for the prop getters/setters generated for this class.
+ @override
+ String get propKeyNamespace => '';
+}
+
+// Concrete props implementation that can be backed by any [Map].
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$UiForwardRefLogsPropsComplexFunctionComponentProps$PlainMap
+ extends _$$UiForwardRefLogsPropsComplexFunctionComponentProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$UiForwardRefLogsPropsComplexFunctionComponentProps$PlainMap(Map backingMap)
+ : this._props = {},
+ super._() {
+ this._props = backingMap ?? {};
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ Map get props => _props;
+ Map _props;
+}
+
+// Concrete props implementation that can only be backed by [JsMap],
+// allowing dart2js to compile more optimal code for key-value pair reads/writes.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$UiForwardRefLogsPropsComplexFunctionComponentProps$JsMap
+ extends _$$UiForwardRefLogsPropsComplexFunctionComponentProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$UiForwardRefLogsPropsComplexFunctionComponentProps$JsMap(
+ JsBackedMap backingMap)
+ : this._props = JsBackedMap(),
+ super._() {
+ this._props = backingMap ?? JsBackedMap();
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ JsBackedMap get props => _props;
+ JsBackedMap _props;
+}
+
+final FunctionComponentConfig<_$$UiForwardRefLogsPropsComplexComponentProps>
+ $UiForwardRefLogsPropsComplexComponentConfig = FunctionComponentConfig(
+ propsFactory: PropsFactory(
+ map: (map) => _$$UiForwardRefLogsPropsComplexComponentProps(map),
+ jsMap: (map) =>
+ _$$UiForwardRefLogsPropsComplexComponentProps$JsMap(map),
+ ),
+ displayName: 'UiForwardRefLogsPropsComplexComponent');
+
+// Concrete props implementation.
+//
+// Implements constructor and backing map, and links up to generated component factory.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+abstract class _$$UiForwardRefLogsPropsComplexComponentProps extends UiProps
+ with
+ UiForwardRefLogsPropsComplexFunctionComponentPropsMixin,
+ $UiForwardRefLogsPropsComplexFunctionComponentPropsMixin, // If this generated mixin is undefined, it's likely because UiForwardRefLogsPropsComplexFunctionComponentPropsMixin is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of UiForwardRefLogsPropsComplexFunctionComponentPropsMixin.
+ LogPropsProps,
+ $LogPropsProps // If this generated mixin is undefined, it's likely because LogPropsProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of LogPropsProps.
+ implements
+ UiForwardRefLogsPropsComplexComponentProps {
+ _$$UiForwardRefLogsPropsComplexComponentProps._();
+
+ factory _$$UiForwardRefLogsPropsComplexComponentProps(Map backingMap) {
+ if (backingMap == null || backingMap is JsBackedMap) {
+ return _$$UiForwardRefLogsPropsComplexComponentProps$JsMap(backingMap);
+ } else {
+ return _$$UiForwardRefLogsPropsComplexComponentProps$PlainMap(backingMap);
+ }
+ }
+
+ /// Let `UiProps` internals know that this class has been generated.
+ @override
+ bool get $isClassGenerated => true;
+
+ /// The default namespace for the prop getters/setters generated for this class.
+ @override
+ String get propKeyNamespace => '';
+}
+
+// Concrete props implementation that can be backed by any [Map].
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$UiForwardRefLogsPropsComplexComponentProps$PlainMap
+ extends _$$UiForwardRefLogsPropsComplexComponentProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$UiForwardRefLogsPropsComplexComponentProps$PlainMap(Map backingMap)
+ : this._props = {},
+ super._() {
+ this._props = backingMap ?? {};
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ Map get props => _props;
+ Map _props;
+}
+
+// Concrete props implementation that can only be backed by [JsMap],
+// allowing dart2js to compile more optimal code for key-value pair reads/writes.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$UiForwardRefLogsPropsComplexComponentProps$JsMap
+ extends _$$UiForwardRefLogsPropsComplexComponentProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$UiForwardRefLogsPropsComplexComponentProps$JsMap(JsBackedMap backingMap)
+ : this._props = JsBackedMap(),
+ super._() {
+ this._props = backingMap ?? JsBackedMap();
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ JsBackedMap get props => _props;
+ JsBackedMap _props;
+}
+
+final FunctionComponentConfig<_$$_LogsPropsFunctionComponentProps>
+ $_LogsPropsFunctionComponentConfig = FunctionComponentConfig(
+ propsFactory: PropsFactory(
+ map: (map) => _$$_LogsPropsFunctionComponentProps(map),
+ jsMap: (map) => _$$_LogsPropsFunctionComponentProps$JsMap(map),
+ ),
+ displayName: '_LogsPropsFunctionComponent');
+
+// Concrete props implementation.
+//
+// Implements constructor and backing map, and links up to generated component factory.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+abstract class _$$_LogsPropsFunctionComponentProps extends UiProps
+ with
+ LogPropsProps,
+ $LogPropsProps // If this generated mixin is undefined, it's likely because LogPropsProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of LogPropsProps.
+ implements
+ _LogsPropsFunctionComponentProps {
+ _$$_LogsPropsFunctionComponentProps._();
+
+ factory _$$_LogsPropsFunctionComponentProps(Map backingMap) {
+ if (backingMap == null || backingMap is JsBackedMap) {
+ return _$$_LogsPropsFunctionComponentProps$JsMap(backingMap);
+ } else {
+ return _$$_LogsPropsFunctionComponentProps$PlainMap(backingMap);
+ }
+ }
+
+ /// Let `UiProps` internals know that this class has been generated.
+ @override
+ bool get $isClassGenerated => true;
+
+ /// The default namespace for the prop getters/setters generated for this class.
+ @override
+ String get propKeyNamespace => '';
+}
+
+// Concrete props implementation that can be backed by any [Map].
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$_LogsPropsFunctionComponentProps$PlainMap
+ extends _$$_LogsPropsFunctionComponentProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$_LogsPropsFunctionComponentProps$PlainMap(Map backingMap)
+ : this._props = {},
+ super._() {
+ this._props = backingMap ?? {};
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ Map get props => _props;
+ Map _props;
+}
+
+// Concrete props implementation that can only be backed by [JsMap],
+// allowing dart2js to compile more optimal code for key-value pair reads/writes.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$_LogsPropsFunctionComponentProps$JsMap
+ extends _$$_LogsPropsFunctionComponentProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$_LogsPropsFunctionComponentProps$JsMap(JsBackedMap backingMap)
+ : this._props = JsBackedMap(),
+ super._() {
+ this._props = backingMap ?? JsBackedMap();
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ JsBackedMap get props => _props;
+ JsBackedMap _props;
+}
+
+final FunctionComponentConfig<_$$RefDemoProps> $RefDemoContainerConfig =
+ FunctionComponentConfig(
+ propsFactory: PropsFactory(
+ map: (map) => _$$RefDemoProps(map),
+ jsMap: (map) => _$$RefDemoProps$JsMap(map),
+ ),
+ displayName: 'RefDemoContainer');
+
+// Concrete props implementation.
+//
+// Implements constructor and backing map, and links up to generated component factory.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+abstract class _$$RefDemoProps extends UiProps
+ with
+ RefDemoProps,
+ $RefDemoProps // If this generated mixin is undefined, it's likely because RefDemoProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of RefDemoProps.
+{
+ _$$RefDemoProps._();
+
+ factory _$$RefDemoProps(Map backingMap) {
+ if (backingMap == null || backingMap is JsBackedMap) {
+ return _$$RefDemoProps$JsMap(backingMap);
+ } else {
+ return _$$RefDemoProps$PlainMap(backingMap);
+ }
+ }
+
+ /// Let `UiProps` internals know that this class has been generated.
+ @override
+ bool get $isClassGenerated => true;
+
+ /// The default namespace for the prop getters/setters generated for this class.
+ @override
+ String get propKeyNamespace => '';
+}
+
+// Concrete props implementation that can be backed by any [Map].
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$RefDemoProps$PlainMap extends _$$RefDemoProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$RefDemoProps$PlainMap(Map backingMap)
+ : this._props = {},
+ super._() {
+ this._props = backingMap ?? {};
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ Map get props => _props;
+ Map _props;
+}
+
+// Concrete props implementation that can only be backed by [JsMap],
+// allowing dart2js to compile more optimal code for key-value pair reads/writes.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$RefDemoProps$JsMap extends _$$RefDemoProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$RefDemoProps$JsMap(JsBackedMap backingMap)
+ : this._props = JsBackedMap(),
+ super._() {
+ this._props = backingMap ?? JsBackedMap();
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ JsBackedMap get props => _props;
+ JsBackedMap _props;
+}
+
+final FunctionComponentConfig<_$$RefDemoSectionProps> $RefDemoSectionConfig =
+ FunctionComponentConfig(
+ propsFactory: PropsFactory(
+ map: (map) => _$$RefDemoSectionProps(map),
+ jsMap: (map) => _$$RefDemoSectionProps$JsMap(map),
+ ),
+ displayName: 'RefDemoSection');
+
+// Concrete props implementation.
+//
+// Implements constructor and backing map, and links up to generated component factory.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+abstract class _$$RefDemoSectionProps extends UiProps
+ with
+ RefDemoSectionProps,
+ $RefDemoSectionProps // If this generated mixin is undefined, it's likely because RefDemoSectionProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of RefDemoSectionProps.
+{
+ _$$RefDemoSectionProps._();
+
+ factory _$$RefDemoSectionProps(Map backingMap) {
+ if (backingMap == null || backingMap is JsBackedMap) {
+ return _$$RefDemoSectionProps$JsMap(backingMap);
+ } else {
+ return _$$RefDemoSectionProps$PlainMap(backingMap);
+ }
+ }
+
+ /// Let `UiProps` internals know that this class has been generated.
+ @override
+ bool get $isClassGenerated => true;
+
+ /// The default namespace for the prop getters/setters generated for this class.
+ @override
+ String get propKeyNamespace => '';
+}
+
+// Concrete props implementation that can be backed by any [Map].
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$RefDemoSectionProps$PlainMap extends _$$RefDemoSectionProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$RefDemoSectionProps$PlainMap(Map backingMap)
+ : this._props = {},
+ super._() {
+ this._props = backingMap ?? {};
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ Map get props => _props;
+ Map _props;
+}
+
+// Concrete props implementation that can only be backed by [JsMap],
+// allowing dart2js to compile more optimal code for key-value pair reads/writes.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$RefDemoSectionProps$JsMap extends _$$RefDemoSectionProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$RefDemoSectionProps$JsMap(JsBackedMap backingMap)
+ : this._props = JsBackedMap(),
+ super._() {
+ this._props = backingMap ?? JsBackedMap();
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ JsBackedMap get props => _props;
+ JsBackedMap _props;
+}
+
+final FunctionComponentConfig<_$$RefDemoHocProps> $RefDemoHocConfig =
+ FunctionComponentConfig(
+ propsFactory: PropsFactory(
+ map: (map) => _$$RefDemoHocProps(map),
+ jsMap: (map) => _$$RefDemoHocProps$JsMap(map),
+ ),
+ displayName: 'RefDemoHoc');
+
+// Concrete props implementation.
+//
+// Implements constructor and backing map, and links up to generated component factory.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+abstract class _$$RefDemoHocProps extends UiProps
+ with
+ RefDemoHocProps,
+ $RefDemoHocProps // If this generated mixin is undefined, it's likely because RefDemoHocProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of RefDemoHocProps.
+{
+ _$$RefDemoHocProps._();
+
+ factory _$$RefDemoHocProps(Map backingMap) {
+ if (backingMap == null || backingMap is JsBackedMap) {
+ return _$$RefDemoHocProps$JsMap(backingMap);
+ } else {
+ return _$$RefDemoHocProps$PlainMap(backingMap);
+ }
+ }
+
+ /// Let `UiProps` internals know that this class has been generated.
+ @override
+ bool get $isClassGenerated => true;
+
+ /// The default namespace for the prop getters/setters generated for this class.
+ @override
+ String get propKeyNamespace => '';
+}
+
+// Concrete props implementation that can be backed by any [Map].
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$RefDemoHocProps$PlainMap extends _$$RefDemoHocProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$RefDemoHocProps$PlainMap(Map backingMap)
+ : this._props = {},
+ super._() {
+ this._props = backingMap ?? {};
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ Map get props => _props;
+ Map _props;
+}
+
+// Concrete props implementation that can only be backed by [JsMap],
+// allowing dart2js to compile more optimal code for key-value pair reads/writes.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$RefDemoHocProps$JsMap extends _$$RefDemoHocProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$RefDemoHocProps$JsMap(JsBackedMap backingMap)
+ : this._props = JsBackedMap(),
+ super._() {
+ this._props = backingMap ?? JsBackedMap();
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ JsBackedMap get props => _props;
+ JsBackedMap _props;
+}
From c5420330a3ec08455d3bcb7a16a36a5ab34cb4e8 Mon Sep 17 00:00:00 2001
From: Joe Bingham
Date: Thu, 30 Jul 2020 12:02:17 -0700
Subject: [PATCH 03/28] Add extension method
---
lib/src/component/ref_util.dart | 260 +++++++++++++++---
.../component_declaration/component_base.dart | 6 +
web/component2/src/demos/forward_ref.dart | 76 +++--
.../src/demos/forward_ref.over_react.g.dart | 34 +--
4 files changed, 292 insertions(+), 84 deletions(-)
diff --git a/lib/src/component/ref_util.dart b/lib/src/component/ref_util.dart
index 083b64e03..57bf3ccfc 100644
--- a/lib/src/component/ref_util.dart
+++ b/lib/src/component/ref_util.dart
@@ -80,7 +80,6 @@ Ref createRef() {
/// // ---------- Component Consumption ----------
///
/// void main() {
-/// setClientConfiguration();
/// final ref = createRef();
///
/// react_dom.render(
@@ -137,7 +136,6 @@ Ref createRef() {
/// Ref _forwardedRef;
/// }
///
-/// @Component2()
/// class LogPropsComponent extends UiComponent2 {
/// @override
/// void componentDidUpdate(Map prevProps, _, [__]) {
@@ -221,54 +219,233 @@ UiFactory Function(UiFactory) forwardRef
/// > __NOTE:__ This should only be used to wrap components that extend from `Component2`
/// > or components using the function syntax.
///
-/// __Example__:
+/// __Example 1:__ Forwarding refs to DOM components
///
-/// mixin FooProps on UiProps {
-/// Ref forwardedRef;
-/// }
+/// ```dart
+/// import 'dart:html';
+/// import 'package:over_react/over_react.dart';
+/// import 'package:over_react/react_dom.dart' as react_dom;
///
-/// final FunctionComponentSyntax = uiForwardRef((props, ref) {
-/// return (Dom.button()
-/// ..ref = ref
-/// )('Click this button');
-/// },
-/// $FunctionSyntaxConfig, // ignore: undefined_identifier
-/// );
+/// // ---------- Component Definition ----------
///
-/// ___ OR ___
+/// final FancyButton = uiForwardRef((props, ref) {
+/// final classes = ClassNameBuilder.fromProps(props)..add('FancyButton');
///
-/// final DomComponentForwarded = uiForwardRef((props, ref) {
-/// return (Dom.div()
+/// return (Dom.button()
+/// ..addProps(getPropsToForward(props, onlyCopyDomProps: true))
+/// ..className = classes.toClassName()
+/// ..ref = ref
+/// )('Click me!');
+/// },
+/// Dom.button.asForwardRefConfig(displayName: 'FancyButton'),
+/// );
+///
+/// // ---------- Component Consumption ----------
+///
+/// void main() {
+/// final ref = createRef();
+///
+/// react_dom.render(
+/// (FancyButton()
/// ..ref = ref
-/// ..className = 'special-class'
-/// )(
-/// props.children
-/// );
-/// })(Dom.div);
+/// ..onClick = (_) {
+/// print(ref.current.outerHtml);
+/// }
+/// )(),
+/// querySelector('#idOfSomeNodeInTheDom')
+/// );
///
-/// ___ OR ___
+/// // You can still get a ref directly to the DOM button:
+/// final buttonNode = ref.current;
+/// }
+/// ```
///
-/// final FooForwarded = uiForwardRef((props, ref) {
-/// return (Foo()
-/// ..forwardedRef = ref
-/// )();
-/// })(Foo);
+/// __Example 2:__ Forwarding refs in higher-order (non-function) components
///
-/// UiFactory Foo = _$Foo;
+/// ```dart
+/// import 'dart:html';
+/// import 'package:over_react/over_react.dart';
+/// import 'package:over_react/react_dom.dart' as react_dom;
///
-/// mixin FooProps on UiProps {
-/// Ref forwardedRef;
-/// }
+/// // ---------- Component Definitions ----------
///
-/// @Component2()
-/// class FooComponent extends UiComponent2 {
-/// @override
-/// render() {
-/// return (Dom.button()
-/// ..ref = props.forwardedRef
-/// )('Click this button');
+/// final FancyButton = uiForwardRef((props, ref) {
+/// final classes = ClassNameBuilder.fromProps(props)..add('FancyButton');
+///
+/// return (Dom.button()
+/// ..addProps(getPropsToForward(props, onlyCopyDomProps: true))
+/// ..className = classes.toClassName()
+/// ..ref = ref
+/// )('Click me!');
+/// },
+/// Dom.button.asForwardRefConfig(displayName: 'FancyButton'),
+/// );
+///
+/// // ---------- Wrapping a Class Component ----------
+/// // Here you have two options:
+/// // - Option 1: Use the class component's UI Factory to construct a function
+/// // component config. This needs to be done because the builder recognizes
+/// // `LogPropsProps` as already consumed (by the class component).
+/// //
+/// // - Option 2: Create a new props class. This just works around the issue
+/// // described for Option 1 because it is creating a new props class, but it
+/// // only needs to mixin in the props mixins that the original props class used.
+/// //
+/// // Choosing between the options is likely circumstantial or at least preferential
+/// // if all else is the same. The advantage to Option 1 is that if the class component
+/// // has numerous mixins, it is much more concise to create the function component
+/// // config. Option 2 has the benefit that it matches the declaration of standard
+/// // function components (which `uiForwardRef` returns). Additionally, Option 2
+/// // illustrates how one could add additional props to the wrapping function component.
+///
+/// // Option 1 Example
+/// final LogsPropsComponent = uiForwardRef((props, ref) {
+/// return (_LogProps()
+/// ..addProps(props)
+/// .._forwardedRef = ref)();
+/// },
+/// _LogProps.asForwardRefConfig(displayName: 'LogsProps'),
+/// );
+///
+/// // Option 2 Example:
+///
+/// // This is not necessary but is just in place to illustrate that more props
+/// // can be specified and consumed.
+/// mixin AnotherPropsMixin on UiProps {
+/// String anExampleAdditionalProp;
+/// }
+///
+/// class LogsPropsComponent2Props = UiProps with AnotherPropsMixin, LogPropsProps;
+///
+/// final LogsPropsComponent2 = uiForwardRef((props, ref) {
+/// useEffect(() {
+/// print(props.anExampleAdditionalProp);
+/// });
+///
+/// return (_LogProps()
+/// ..addProps(props)
+/// .._forwardedRef = ref)();
+/// },
+/// $LogsPropsComponent2Config
+/// );
+///
+/// UiFactory _LogProps = _$_LogProps;
+///
+/// mixin LogPropsProps on UiProps {
+/// BuilderOnlyUiFactory builder;
+///
+/// // Private since we only use this to pass along the value of `ref` to
+/// // the return value of forwardRef.
+/// //
+/// // Consumers can set this private field value using the public `ref` setter.
+/// Ref _forwardedRef;
+/// }
+///
+/// class LogPropsComponent extends UiComponent2 {
+/// @override
+/// void componentDidUpdate(Map prevProps, _, [__]) {
+/// print('old props: $prevProps');
+/// print('new props: $props');
+/// }
+///
+/// @override
+/// render() {
+/// return (props.builder()
+/// ..modifyProps(addUnconsumedDomProps)
+/// ..ref = props._forwardedRef
+/// )(props.children);
+/// }
+/// }
+///
+/// // ---------- Component Consumption ----------
+///
+/// void main() {
+/// final ref = createRef();
+///
+/// react_dom.render(
+/// (LogProps()
+/// ..builder = FancyButton
+/// ..className = 'btn btn-primary'
+/// ..ref = ref
+/// ..onClick = (_) {
+/// print(ref.current.outerHtml);
+/// }
+/// )(),
+/// querySelector('#idOfSomeNodeInTheDom')
+/// );
+///
+/// // You can still get a ref directly to the DOM button:
+/// final buttonNode = ref.current;
+/// }
+/// ```
+///
+/// __Example 3:__ Forwarding refs in higher-order (all function) components
+///
+/// ```dart
+/// import 'dart:html';
+/// import 'package:over_react/over_react.dart';
+/// import 'package:over_react/react_dom.dart' as react_dom;
+/// import 'package:react/hooks.dart';
+///
+/// // ---------- Component Definitions ----------
+///
+/// final FancyButton = uiForwardRef((props, ref) {
+/// final classes = ClassNameBuilder.fromProps(props)..add('FancyButton');
+///
+/// return (Dom.button()
+/// ..addProps(getPropsToForward(props, onlyCopyDomProps: true))
+/// ..className = classes.toClassName()
+/// ..ref = ref
+/// )('Click me!');
+/// },
+/// Dom.button.asForwardRefConfig(displayName: 'FancyButton'),
+/// );
+///
+/// mixin LogPropsProps on UiProps {
+/// BuilderOnlyUiFactory builder;
+/// }
+///
+/// final LogProps = uiForwardRef(
+/// (props, ref) {
+/// final prevPropsRef = useRef(null);
+///
+/// useEffect(() {
+/// if (prevPropsRef.current != null) {
+/// print('old props: ${prevPropsRef.current}');
+/// print('new props: $props');
/// }
-/// }
+///
+/// prevPropsRef.current = props;
+/// });
+///
+/// return ((props.builder()
+/// ..addProps(getPropsToForward(props, onlyCopyDomProps: true))
+/// ..ref = ref)(props.children));
+/// },
+/// $LogPropsConfig, // ignore: undefined_identifier
+/// );
+///
+/// // ---------- Component Consumption ----------
+///
+/// void main() {
+/// final ref = createRef();
+///
+/// react_dom.render(
+/// (LogProps()
+/// ..builder = FancyButton
+/// ..className = 'btn btn-primary'
+/// ..ref = ref
+/// ..onClick = (_) {
+/// print(ref.current.outerHtml);
+/// }
+/// )(),
+/// querySelector('#idOfSomeNodeInTheDom')
+/// );
+///
+/// // You can still get a ref directly to the DOM button:
+/// final buttonNode = ref.current;
+/// }
+/// ```
///
/// Learn more: .
UiFactory uiForwardRef(
@@ -288,9 +465,8 @@ UiFactory uiForwardRef(
ReactJsComponentFactoryProxy factory;
- // It's not expected that `displayName` should ever be null, but if it is ever null and get's passed to `forwardRef`
- // the name of the component becomes ' ' (an empty string). To protect against this ever happening, this check is in
- // place so the name falls back to 'Anonymous'.
+ // If a consumer uses `asForwardRefConfig` to generate the function component
+ // config, displayName could be `null`.
if (displayName != null) {
factory = react_interop.forwardRef(_uiFunctionWrapper, displayName: displayName);
} else {
diff --git a/lib/src/component_declaration/component_base.dart b/lib/src/component_declaration/component_base.dart
index f775d21bb..4c018ade6 100644
--- a/lib/src/component_declaration/component_base.dart
+++ b/lib/src/component_declaration/component_base.dart
@@ -20,6 +20,8 @@ import 'dart:collection';
import 'package:meta/meta.dart';
import 'package:over_react/src/component/dummy_component.dart';
import 'package:over_react/src/component/prop_mixins.dart';
+import 'package:over_react/src/component_declaration/builder_helpers.dart' as bh;
+import 'package:over_react/src/component_declaration/function_component.dart';
import 'package:over_react/src/util/class_names.dart';
import 'package:over_react/src/util/map_util.dart';
import 'package:over_react/src/util/pretty_print.dart';
@@ -91,6 +93,10 @@ ReactDartComponentFactoryProxy registerAbstractComponent(Type abstractComponentC
/// via a fluent-style builder interface.
typedef TProps UiFactory([Map backingProps]);
+extension UiFactoryHelpers on UiFactory {
+ FunctionComponentConfig asForwardRefConfig({String displayName}) => FunctionComponentConfig(propsFactory: PropsFactory.fromUiFactory(this), displayName: displayName);
+}
+
/// A utility variation on [UiFactory], __without__ a `backingProps` parameter.
///
/// I.e., a function that takes no parameters and returns a new [TProps] instance backed by a new, empty Map.
diff --git a/web/component2/src/demos/forward_ref.dart b/web/component2/src/demos/forward_ref.dart
index fb49a9dc4..a6b16ed73 100644
--- a/web/component2/src/demos/forward_ref.dart
+++ b/web/component2/src/demos/forward_ref.dart
@@ -1,6 +1,7 @@
import 'dart:html';
import 'package:over_react/over_react.dart';
+import 'package:react/hooks.dart';
// ignore: uri_has_not_been_generated
part 'forward_ref.over_react.g.dart';
@@ -8,20 +9,23 @@ part 'forward_ref.over_react.g.dart';
// ------------ `uiForwardRef` with a function component (simple) ------------
mixin UiForwardRefLogsFunctionComponentProps on UiProps {
BuilderOnlyUiFactory builder;
-
- // Private since we only use this to pass along the value of `ref` to
- // the return value of forwardRef.
- //
- // Consumers can set this private field value using the public `ref` setter.
- Ref _forwardedRef;
}
final UiForwardRefLogsFunctionComponent = uiForwardRef(
(props, ref) {
+ final prevPropsRef = useRef(null);
+
+ useEffect(() {
+ if (prevPropsRef.current != null) {
+ print(prevPropsRef.current);
+ print(props);
+ }
+
+ prevPropsRef.current = props;
+ });
+
return ((props.builder()
- ..id = props.id
- ..className = props.className
- ..onClick = props.onClick
+ ..addProps(getPropsToForward(props, onlyCopyDomProps: true))
..ref = ref)(props.children));
},
$UiForwardRefLogsFunctionComponentConfig, // ignore: undefined_identifier
@@ -40,12 +44,21 @@ class UiForwardRefLogsPropsComplexFunctionComponentProps = UiProps
final UiForwardRefLogsPropsComplexFunctionComponent =
uiForwardRef(
(props, ref) {
+ final prevPropsRef = useRef(null);
+
+ useEffect(() {
+ if (prevPropsRef.current != null) {
+ print(prevPropsRef.current);
+ print(props);
+ }
+
+ prevPropsRef.current = props;
+ });
+
return (Fragment()(
Dom.div()(props.buttonDescription),
(props.builder()
- ..id = props.id
- ..className = props.className
- ..onClick = props.onClick
+ ..addProps(getPropsToForward(props, onlyCopyDomProps: true))
..ref = ref)(props.children),
));
},
@@ -55,12 +68,11 @@ final UiForwardRefLogsPropsComplexFunctionComponent =
// ------------ `uiForwardRef` with a class component (simple) ------------
final UiForwardRefLogsPropsComponent = uiForwardRef(
(props, ref) {
- return (_LogsPropsFunctionComponent()
+ return (_LogProps()
..addProps(props)
.._forwardedRef = ref)();
},
- FunctionComponentConfig(
- propsFactory: PropsFactory.fromUiFactory(_LogsPropsFunctionComponent), displayName: null),
+ _LogProps.asForwardRefConfig(displayName: 'UiForwardRefLogsProps'),
);
// ------------ `uiForwardRef` with a class component (complex) ------------
@@ -76,7 +88,7 @@ final UiForwardRefLogsPropsComplexComponent =
(props, ref) {
return Fragment()(
Dom.div()(props.buttonDescription),
- (_LogsPropsFunctionComponent()
+ (_LogProps()
..addProps(props)
.._forwardedRef = ref)(),
);
@@ -96,6 +108,9 @@ UiFactory _LogProps = _$_LogProps;
mixin LogPropsProps on UiProps {
BuilderOnlyUiFactory builder;
+ // A simple prop to change in order to trigger the print.
+ bool thisWasClickedLast;
+
// Private since we only use this to pass along the value of `ref` to
// the return value of forwardRef.
//
@@ -112,9 +127,11 @@ class LogPropsComponent extends UiComponent2 {
@override
render() {
- return (props.builder()
- ..modifyProps(addUnconsumedDomProps)
- ..ref = props._forwardedRef)(props.children);
+ return Dom.div()(
+ Dom.p()('This was the last button clicked: ${props.thisWasClickedLast}'),
+ (props.builder()
+ ..modifyProps(addUnconsumedDomProps)
+ ..ref = props._forwardedRef)(props.children));
}
}
@@ -129,10 +146,19 @@ class _LogsPropsFunctionComponentProps = UiProps with LogPropsProps;
final _LogsPropsFunctionComponent = uiFunction<_LogsPropsFunctionComponentProps>(
(props) {
+ final prevPropsRef = useRef<_LogsPropsFunctionComponentProps>(null);
+
+ useEffect(() {
+ if (prevPropsRef.current != null) {
+ print(prevPropsRef.current);
+ print(props);
+ }
+
+ prevPropsRef.current = props;
+ });
+
return ((props.builder()
- ..id = props.id
- ..className = props.className
- ..onClick = props.onClick
+ ..addProps(getPropsToForward(props, onlyCopyDomProps: true))
..ref = props._forwardedRef)(props.children));
},
$_LogsPropsFunctionComponentConfig, // ignore: undefined_identifier
@@ -148,7 +174,7 @@ final FancyButton = uiForwardRef(
..className = classes.toClassName()
..ref = ref)('Click me!');
},
- FunctionComponentConfig(propsFactory: PropsFactory.fromUiFactory(Dom.button), displayName: null),
+ Dom.button.asForwardRefConfig(displayName: 'FancyButton'),
);
mixin RefDemoProps on UiProps {}
@@ -165,6 +191,8 @@ final RefDemoContainer = uiFunction(
final fancyButtonNodeRef = createRef();
final fancyFunctionalButtonNodeRef = createRef();
+ final lastClickedRef = useState[(null);
+
return ((Dom.div()..style = {'padding': 10})(
(RefDemoSection()..sectionTitle = 'uiForwardRef Demos')(
(RefDemoHoc()..demoTitle = '`uiForwardRef` with a function component (simple)')(
@@ -219,6 +247,7 @@ final RefDemoContainer = uiFunction(
..ref = fancyButtonNodeRef
..onClick = (_) {
print(fancyButtonNodeRef.current.outerHtml);
+ lastClickedRef.set(fancyButtonNodeRef);
})(),
),
(RefDemoHoc()..demoTitle = '`uiForwardRef` with function component')(
@@ -229,6 +258,7 @@ final RefDemoContainer = uiFunction(
..ref = fancyFunctionalButtonNodeRef
..onClick = (_) {
print(fancyFunctionalButtonNodeRef.current.outerHtml);
+ lastClickedRef.set(fancyFunctionalButtonNodeRef);
})(),
),
),
diff --git a/web/component2/src/demos/forward_ref.over_react.g.dart b/web/component2/src/demos/forward_ref.over_react.g.dart
index 3abfce35a..b6ee921af 100644
--- a/web/component2/src/demos/forward_ref.over_react.g.dart
+++ b/web/component2/src/demos/forward_ref.over_react.g.dart
@@ -159,35 +159,18 @@ mixin $UiForwardRefLogsFunctionComponentProps
@override
set builder(BuilderOnlyUiFactory value) =>
props[_$key__builder__UiForwardRefLogsFunctionComponentProps] = value;
- @override
- Ref get _forwardedRef =>
- props[_$key___forwardedRef__UiForwardRefLogsFunctionComponentProps] ??
- null; // Add ` ?? null` to workaround DDC bug: ;
- @override
- set _forwardedRef(Ref value) =>
- props[_$key___forwardedRef__UiForwardRefLogsFunctionComponentProps] =
- value;
/* GENERATED CONSTANTS */
static const PropDescriptor
_$prop__builder__UiForwardRefLogsFunctionComponentProps =
PropDescriptor(_$key__builder__UiForwardRefLogsFunctionComponentProps);
- static const PropDescriptor
- _$prop___forwardedRef__UiForwardRefLogsFunctionComponentProps =
- PropDescriptor(
- _$key___forwardedRef__UiForwardRefLogsFunctionComponentProps);
static const String _$key__builder__UiForwardRefLogsFunctionComponentProps =
'UiForwardRefLogsFunctionComponentProps.builder';
- static const String
- _$key___forwardedRef__UiForwardRefLogsFunctionComponentProps =
- 'UiForwardRefLogsFunctionComponentProps._forwardedRef';
static const List $props = [
- _$prop__builder__UiForwardRefLogsFunctionComponentProps,
- _$prop___forwardedRef__UiForwardRefLogsFunctionComponentProps
+ _$prop__builder__UiForwardRefLogsFunctionComponentProps
];
static const List $propKeys = [
- _$key__builder__UiForwardRefLogsFunctionComponentProps,
- _$key___forwardedRef__UiForwardRefLogsFunctionComponentProps
+ _$key__builder__UiForwardRefLogsFunctionComponentProps
];
}
@@ -297,6 +280,13 @@ mixin $LogPropsProps on LogPropsProps {
set builder(BuilderOnlyUiFactory value) =>
props[_$key__builder__LogPropsProps] = value;
@override
+ bool get thisWasClickedLast =>
+ props[_$key__thisWasClickedLast__LogPropsProps] ??
+ null; // Add ` ?? null` to workaround DDC bug: ;
+ @override
+ set thisWasClickedLast(bool value) =>
+ props[_$key__thisWasClickedLast__LogPropsProps] = value;
+ @override
Ref get _forwardedRef =>
props[_$key___forwardedRef__LogPropsProps] ??
null; // Add ` ?? null` to workaround DDC bug: ;
@@ -306,18 +296,24 @@ mixin $LogPropsProps on LogPropsProps {
/* GENERATED CONSTANTS */
static const PropDescriptor _$prop__builder__LogPropsProps =
PropDescriptor(_$key__builder__LogPropsProps);
+ static const PropDescriptor _$prop__thisWasClickedLast__LogPropsProps =
+ PropDescriptor(_$key__thisWasClickedLast__LogPropsProps);
static const PropDescriptor _$prop___forwardedRef__LogPropsProps =
PropDescriptor(_$key___forwardedRef__LogPropsProps);
static const String _$key__builder__LogPropsProps = 'LogPropsProps.builder';
+ static const String _$key__thisWasClickedLast__LogPropsProps =
+ 'LogPropsProps.thisWasClickedLast';
static const String _$key___forwardedRef__LogPropsProps =
'LogPropsProps._forwardedRef';
static const List $props = [
_$prop__builder__LogPropsProps,
+ _$prop__thisWasClickedLast__LogPropsProps,
_$prop___forwardedRef__LogPropsProps
];
static const List $propKeys = [
_$key__builder__LogPropsProps,
+ _$key__thisWasClickedLast__LogPropsProps,
_$key___forwardedRef__LogPropsProps
];
}
From 841d102292a3dd7cdfeb9a6f1de6750b272b3acc Mon Sep 17 00:00:00 2001
From: Joe Bingham
Date: Mon, 3 Aug 2020 10:05:39 -0700
Subject: [PATCH 04/28] Add tests
---
lib/src/component/ref_util.dart | 2 +-
test/over_react/component/ref_test.dart | 331 +++++++++++++++++
.../component/ref_test.over_react.g.dart | 343 ++++++++++++++++++
test/over_react_component_test.dart | 7 +-
4 files changed, 677 insertions(+), 6 deletions(-)
create mode 100644 test/over_react/component/ref_test.dart
create mode 100644 test/over_react/component/ref_test.over_react.g.dart
diff --git a/lib/src/component/ref_util.dart b/lib/src/component/ref_util.dart
index 57bf3ccfc..bbd055461 100644
--- a/lib/src/component/ref_util.dart
+++ b/lib/src/component/ref_util.dart
@@ -467,7 +467,7 @@ UiFactory uiForwardRef(
// If a consumer uses `asForwardRefConfig` to generate the function component
// config, displayName could be `null`.
- if (displayName != null) {
+ if (displayName != null && displayName.trim().isNotEmpty) {
factory = react_interop.forwardRef(_uiFunctionWrapper, displayName: displayName);
} else {
factory = react_interop.forwardRef(_uiFunctionWrapper);
diff --git a/test/over_react/component/ref_test.dart b/test/over_react/component/ref_test.dart
new file mode 100644
index 000000000..4841d1792
--- /dev/null
+++ b/test/over_react/component/ref_test.dart
@@ -0,0 +1,331 @@
+// Copyright 2020 Workiva Inc.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+library forward_ref_test;
+
+import 'dart:html';
+import 'dart:js_util';
+
+import 'package:meta/meta.dart';
+import 'package:test/test.dart';
+import 'package:over_react/over_react.dart';
+import 'package:over_react/src/component/dom_components.dart';
+
+import '../../test_util/test_util.dart';
+import '../component/fixtures/basic_child_component.dart';
+import 'fixtures/basic_ui_component.dart';
+
+part 'ref_test.over_react.g.dart'; // ignore: uri_has_not_been_generated
+
+main() {
+ group('forward ref -', () {
+ test('errors when wrapping a UiComponent', () {
+ expect(() => forwardRef((props, ref) {
+ return (BasicUiComponent()
+ ..ref = ref
+ )();
+ })(BasicUiComponent), throwsArgumentError);
+ });
+
+ commonRefForwardingTests();
+ });
+
+ group('uiForwardRef -', () {
+ group('fundamentally behaves the same as `forwardRef', () {
+ commonRefForwardingTests(useUiForwardRef: true);
+ });
+
+ group('on a function component child', () {
+ standardForwardRefTest(BasicChild, verifyRefValue: (ref) {
+ expect(ref, TypeMatcher());
+ }, useUiForwardRef: true);
+
+ group('using the factory\'s `asForwardRefConfig` syntax', () {
+ test('- sets displayName on the rendered component as expected', () {
+ final BasicForwarded = uiForwardRef((props, ref) {
+ return (BasicUiFunction()..ref = ref)();
+ }, BasicUiFunction.asForwardRefConfig());
+
+ final Ref refObject = createRef();
+ final vDomElement = (BasicForwarded()..ref = refObject)();
+
+ expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), 'Anonymous');
+ });
+
+ test('when displayName argument is passed to the config constructor', () {
+ final BasicForwarded = uiForwardRef((props, ref) {
+ return (BasicUiFunction()..ref = ref)();
+ }, BasicUiFunction.asForwardRefConfig(displayName: displayName));
+
+ final Ref refObject = createRef();
+ final vDomElement = (BasicForwarded()..ref = refObject)();
+
+ expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), displayName);
+ });
+
+ group('returns normally when passed children', () {
+ test('that are in a List literal', () {
+ final BasicForwarded = uiForwardRef((props, ref) {
+ return (BasicUiFunction()..ref = ref)();
+ }, BasicUiFunction.asForwardRefConfig());
+
+ expect(() => mount(BasicForwarded()(['test'])), returnsNormally);
+ });
+
+ test('that are not in a List literal', () {
+ final BasicForwarded = uiForwardRef((props, ref) {
+ return (BasicUiFunction()..ref = ref)();
+ }, BasicUiFunction.asForwardRefConfig());
+
+ expect(() => mount(BasicForwarded()('test')), returnsNormally);
+ });
+ });
+ });
+ });
+
+ group('using a generated factory', () {
+ test('- sets displayName on the rendered component as expected', () {
+ final Ref refObject = createRef();
+ final vDomElement = (TopLevelForwardUiRefFunction()..ref = refObject)();
+
+ expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), 'TopLevelForwardUiRefFunction');
+ });
+
+ group('returns normally when passed children', () {
+ test('that are in a List literal', () {
+ expect(() => mount(TopLevelForwardUiRefFunction()(['test'])), returnsNormally);
+ });
+
+ test('that are not in a List literal', () {
+ expect(() => mount(TopLevelForwardUiRefFunction()('test')), returnsNormally);
+ });
+ });
+ });
+
+ test('throws an argument error if the config is null', () {
+ expect(() {
+ uiForwardRef((_, __) => Dom.div()('Example'), null);
+ }, throwsArgumentError);
+ });
+ });
+}
+
+@isTestGroup
+void commonRefForwardingTests({bool useUiForwardRef = false}) {
+ UiFactory getFactoryForBasic({
+ String displayName,
+ }) {
+ if (useUiForwardRef) {
+ if (displayName == null) {
+ return uiForwardRef((props, ref) {
+ return (Basic()..ref = ref)(props.children);
+ }, Basic.asForwardRefConfig());
+ } else {
+ return uiForwardRef((props, ref) {
+ return (Basic()..ref = ref)(props.children);
+ }, Basic.asForwardRefConfig(displayName: displayName));
+ }
+ } else {
+ if (displayName == null) {
+ return forwardRef((props, ref) {
+ return (Basic()..ref = ref)(props.children);
+ })(Basic);
+ } else {
+ return forwardRef((props, ref) {
+ return (Basic()..ref = ref)(props.children);
+ }, displayName: displayName)(Basic);
+ }
+ }
+ }
+
+ UiFactory getFactoryForDiv({
+ String displayName,
+ }) {
+ ReactElement div(Ref ref, dynamic children) => (Dom.div()
+ ..ref = ref
+ )(children);
+
+ if (useUiForwardRef) {
+ if (displayName == null) {
+ return uiForwardRef((props, ref) {
+ return div(ref, props.children);
+ }, Dom.div.asForwardRefConfig());
+ } else {
+ return uiForwardRef((props, ref) {
+ return div(ref, props.children);
+ }, Dom.div.asForwardRefConfig(displayName: displayName));
+ }
+ } else {
+ if (displayName == null) {
+ return forwardRef((props, ref) {
+ return div(ref, props.children);
+ })(Dom.div);
+ } else {
+ return forwardRef((props, ref) {
+ return div(ref, props.children);
+ }, displayName: displayName)(Dom.div);
+ }
+ }
+ }
+
+ group('- commonRefForwardingTests -', () {
+ group('on a component with a dom component child', () {
+ standardForwardRefTest(Dom.span, verifyRefValue: (ref) {
+ expect(ref, TypeMatcher());
+ }, useUiForwardRef: useUiForwardRef);
+
+ test('- using DomProps', () {
+ UiFactory DivForwarded = getFactoryForDiv();
+
+ final Ref refObject = createRef();
+
+ mount((DivForwarded()
+ ..ref = refObject
+ )());
+
+ expect(refObject.current, TypeMatcher());
+ });
+
+ group('- sets displayName on the rendered component as expected', () {
+ test('when displayName argument is not passed to forwardRef', () {
+ UiFactory DivForwarded = getFactoryForDiv();
+
+ final refObject = createRef();
+ final vDomElement = (DivForwarded()..ref = refObject)();
+
+ expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), useUiForwardRef ? 'Anonymous' : 'div');
+ });
+
+ test('when displayName argument is passed to the config constructor', () {
+ UiFactory DivForwarded = getFactoryForDiv(displayName: displayName);
+
+ final refObject = createRef();
+ final vDomElement = (DivForwarded()..ref = refObject)();
+
+ expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), displayName);
+ });
+ });
+
+ group('returns normally when passed children', () {
+ test('that are in a List literal', () {
+ expect(() => mount(getFactoryForDiv()()(['test'])), returnsNormally);
+ });
+
+ test('that are not in a List literal', () {
+ expect(() => mount(getFactoryForDiv()()('test')), returnsNormally);
+ });
+ });
+ });
+
+ group('on a component with a dart component child', () {
+ standardForwardRefTest(Basic, verifyRefValue: (ref) {
+ expect(ref, TypeMatcher());
+ }, useUiForwardRef: useUiForwardRef);
+
+ group('- sets displayName on the rendered component as expected', () {
+ test('when displayName argument is not passed to forwardRef', () {
+ final BasicForwarded = getFactoryForBasic();
+
+ final Ref refObject = createRef();
+ final vDomElement = (BasicForwarded()..ref = refObject)();
+
+ expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), useUiForwardRef ? 'Anonymous' : 'Basic');
+ });
+
+ test('when displayName argument is passed to the config constructor', () {
+ final BasicForwarded = getFactoryForBasic(displayName: displayName);
+
+ final Ref refObject = createRef();
+ final vDomElement = (BasicForwarded()..ref = refObject)();
+
+ expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), displayName);
+ });
+ });
+
+ group('returns normally when passed children', () {
+ test('that are in a List literal', () {
+ expect(() => mount(getFactoryForBasic()()(['test'])), returnsNormally);
+ });
+
+ test('that are not in a List literal', () {
+ expect(() => mount(getFactoryForBasic()()('test')), returnsNormally);
+ });
+ });
+ });
+ });
+}
+
+const displayName = 'AVerySpecificDisplayName';
+
+void standardForwardRefTest(dynamic factory, {void Function(dynamic refValue) verifyRefValue, useUiForwardRef = false}) {
+ test('- passes a ref through the parent to its child', () {
+ UiFactory BasicForwarded = useUiForwardRef ? uiForwardRef((props, ref) {
+ return (factory()
+ ..ref = ref
+ ..id = props.childId
+ )();
+ }, Basic.asForwardRefConfig()) : forwardRef((props, ref) {
+ return (factory()
+ ..ref = ref
+ ..id = props.childId
+ )();
+ })(Basic);
+
+ final Ref refObject = createRef();
+
+ mount((BasicForwarded()
+ ..ref = refObject
+ ..childId = 'test'
+ )());
+
+ // component props are accessed differently depending on if it is a dom component
+ // or a dart component
+ String idValue;
+ if (refObject.current is Element) {
+ idValue = refObject.current.id;
+ } else {
+ idValue = refObject.current.props['id'];
+ }
+
+ expect(idValue, equals('test'), reason: 'child component should have access to parent props');
+ verifyRefValue(refObject.current);
+ });
+}
+
+UiFactory Basic = _$Basic; // ignore: undefined_identifier
+
+mixin BasicProps on UiProps {
+ String childId;
+}
+
+class BasicComponent extends UiComponent2 {
+ @override
+ render() => props.children.isEmpty ? 'basic component' : props.children;
+}
+
+mixin BasicUiFunctionProps on UiProps {}
+
+class SecondaryBasicUiFunctionProps = UiProps with BasicUiFunctionProps;
+
+final BasicUiFunction = uiFunction((props) {
+ return props.children.isEmpty ? 'basic component' : props.children;
+ },
+ $BasicUiFunctionConfig, // ignore: undefined_identifier
+);
+
+final TopLevelForwardUiRefFunction = uiForwardRef((props, ref) {
+ return (BasicUiFunction()..ref = ref)(props.children);
+},
+ $TopLevelForwardUiRefFunctionConfig, // ignore: undefined_identifier
+);
\ No newline at end of file
diff --git a/test/over_react/component/ref_test.over_react.g.dart b/test/over_react/component/ref_test.over_react.g.dart
new file mode 100644
index 000000000..85bd54ee2
--- /dev/null
+++ b/test/over_react/component/ref_test.over_react.g.dart
@@ -0,0 +1,343 @@
+// GENERATED CODE - DO NOT MODIFY BY HAND
+
+// ignore_for_file: deprecated_member_use_from_same_package, unnecessary_null_in_if_null_operators, prefer_null_aware_operators
+part of 'ref_test.dart';
+
+// **************************************************************************
+// OverReactBuilder (package:over_react/src/builder.dart)
+// **************************************************************************
+
+// React component factory implementation.
+//
+// Registers component implementation and links type meta to builder factory.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+final $BasicComponentFactory = registerComponent2(
+ () => _$BasicComponent(),
+ builderFactory: _$Basic,
+ componentClass: BasicComponent,
+ isWrapper: false,
+ parentType: null,
+ displayName: 'Basic',
+);
+
+_$$BasicProps _$Basic([Map backingProps]) => backingProps == null
+ ? _$$BasicProps$JsMap(JsBackedMap())
+ : _$$BasicProps(backingProps);
+
+// Concrete props implementation.
+//
+// Implements constructor and backing map, and links up to generated component factory.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+abstract class _$$BasicProps extends UiProps
+ with
+ BasicProps,
+ $BasicProps // If this generated mixin is undefined, it's likely because BasicProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of BasicProps.
+{
+ _$$BasicProps._();
+
+ factory _$$BasicProps(Map backingMap) {
+ if (backingMap == null || backingMap is JsBackedMap) {
+ return _$$BasicProps$JsMap(backingMap);
+ } else {
+ return _$$BasicProps$PlainMap(backingMap);
+ }
+ }
+
+ /// Let `UiProps` internals know that this class has been generated.
+ @override
+ bool get $isClassGenerated => true;
+
+ /// The `ReactComponentFactory` associated with the component built by this class.
+ @override
+ ReactComponentFactoryProxy get componentFactory =>
+ super.componentFactory ?? $BasicComponentFactory;
+
+ /// The default namespace for the prop getters/setters generated for this class.
+ @override
+ String get propKeyNamespace => '';
+}
+
+// Concrete props implementation that can be backed by any [Map].
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$BasicProps$PlainMap extends _$$BasicProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$BasicProps$PlainMap(Map backingMap)
+ : this._props = {},
+ super._() {
+ this._props = backingMap ?? {};
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ Map get props => _props;
+ Map _props;
+}
+
+// Concrete props implementation that can only be backed by [JsMap],
+// allowing dart2js to compile more optimal code for key-value pair reads/writes.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$BasicProps$JsMap extends _$$BasicProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$BasicProps$JsMap(JsBackedMap backingMap)
+ : this._props = JsBackedMap(),
+ super._() {
+ this._props = backingMap ?? JsBackedMap();
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ JsBackedMap get props => _props;
+ JsBackedMap _props;
+}
+
+// Concrete component implementation mixin.
+//
+// Implements typed props/state factories, defaults `consumedPropKeys` to the keys
+// generated for the associated props class.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$BasicComponent extends BasicComponent {
+ _$$BasicProps$JsMap _cachedTypedProps;
+
+ @override
+ _$$BasicProps$JsMap get props => _cachedTypedProps;
+
+ @override
+ set props(Map value) {
+ assert(
+ getBackingMap(value) is JsBackedMap,
+ 'Component2.props should never be set directly in '
+ 'production. If this is required for testing, the '
+ 'component should be rendered within the test. If '
+ 'that does not have the necessary result, the last '
+ 'resort is to use typedPropsFactoryJs.');
+ super.props = value;
+ _cachedTypedProps = typedPropsFactoryJs(getBackingMap(value));
+ }
+
+ @override
+ _$$BasicProps$JsMap typedPropsFactoryJs(JsBackedMap backingMap) =>
+ _$$BasicProps$JsMap(backingMap);
+
+ @override
+ _$$BasicProps typedPropsFactory(Map backingMap) => _$$BasicProps(backingMap);
+
+ /// Let `UiComponent` internals know that this class has been generated.
+ @override
+ bool get $isClassGenerated => true;
+
+ /// The default consumed props, comprising all props mixins used by BasicProps.
+ /// Used in `*ConsumedProps` methods if [consumedProps] is not overridden.
+ @override
+ get $defaultConsumedProps => propsMeta.all;
+
+ @override
+ PropsMetaCollection get propsMeta => const PropsMetaCollection({
+ // If this generated mixin is undefined, it's likely because BasicProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of BasicProps.
+ BasicProps: $BasicProps.meta,
+ });
+}
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.'
+ ' EXCEPTION: this may be used in legacy boilerplate until'
+ ' it is transitioned to the new mixin-based boilerplate.')
+mixin $BasicProps on BasicProps {
+ static const PropsMeta meta = _$metaForBasicProps;
+ @override
+ String get childId =>
+ props[_$key__childId__BasicProps] ??
+ null; // Add ` ?? null` to workaround DDC bug: ;
+ @override
+ set childId(String value) => props[_$key__childId__BasicProps] = value;
+ /* GENERATED CONSTANTS */
+ static const PropDescriptor _$prop__childId__BasicProps =
+ PropDescriptor(_$key__childId__BasicProps);
+ static const String _$key__childId__BasicProps = 'BasicProps.childId';
+
+ static const List $props = [_$prop__childId__BasicProps];
+ static const List $propKeys = [_$key__childId__BasicProps];
+}
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+const PropsMeta _$metaForBasicProps = PropsMeta(
+ fields: $BasicProps.$props,
+ keys: $BasicProps.$propKeys,
+);
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.'
+ ' EXCEPTION: this may be used in legacy boilerplate until'
+ ' it is transitioned to the new mixin-based boilerplate.')
+mixin $BasicUiFunctionProps on BasicUiFunctionProps {
+ static const PropsMeta meta = _$metaForBasicUiFunctionProps;
+ /* GENERATED CONSTANTS */
+
+ static const List $props = [];
+ static const List $propKeys = [];
+}
+
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+const PropsMeta _$metaForBasicUiFunctionProps = PropsMeta(
+ fields: $BasicUiFunctionProps.$props,
+ keys: $BasicUiFunctionProps.$propKeys,
+);
+
+final FunctionComponentConfig<_$$BasicUiFunctionProps> $BasicUiFunctionConfig =
+ FunctionComponentConfig(
+ propsFactory: PropsFactory(
+ map: (map) => _$$BasicUiFunctionProps(map),
+ jsMap: (map) => _$$BasicUiFunctionProps$JsMap(map),
+ ),
+ displayName: 'BasicUiFunction');
+
+// Concrete props implementation.
+//
+// Implements constructor and backing map, and links up to generated component factory.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+abstract class _$$BasicUiFunctionProps extends UiProps
+ with
+ BasicUiFunctionProps,
+ $BasicUiFunctionProps // If this generated mixin is undefined, it's likely because BasicUiFunctionProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of BasicUiFunctionProps.
+{
+ _$$BasicUiFunctionProps._();
+
+ factory _$$BasicUiFunctionProps(Map backingMap) {
+ if (backingMap == null || backingMap is JsBackedMap) {
+ return _$$BasicUiFunctionProps$JsMap(backingMap);
+ } else {
+ return _$$BasicUiFunctionProps$PlainMap(backingMap);
+ }
+ }
+
+ /// Let `UiProps` internals know that this class has been generated.
+ @override
+ bool get $isClassGenerated => true;
+
+ /// The default namespace for the prop getters/setters generated for this class.
+ @override
+ String get propKeyNamespace => '';
+}
+
+// Concrete props implementation that can be backed by any [Map].
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$BasicUiFunctionProps$PlainMap extends _$$BasicUiFunctionProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$BasicUiFunctionProps$PlainMap(Map backingMap)
+ : this._props = {},
+ super._() {
+ this._props = backingMap ?? {};
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ Map get props => _props;
+ Map _props;
+}
+
+// Concrete props implementation that can only be backed by [JsMap],
+// allowing dart2js to compile more optimal code for key-value pair reads/writes.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$BasicUiFunctionProps$JsMap extends _$$BasicUiFunctionProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$BasicUiFunctionProps$JsMap(JsBackedMap backingMap)
+ : this._props = JsBackedMap(),
+ super._() {
+ this._props = backingMap ?? JsBackedMap();
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ JsBackedMap get props => _props;
+ JsBackedMap _props;
+}
+
+final FunctionComponentConfig<_$$SecondaryBasicUiFunctionProps>
+ $TopLevelForwardUiRefFunctionConfig = FunctionComponentConfig(
+ propsFactory: PropsFactory(
+ map: (map) => _$$SecondaryBasicUiFunctionProps(map),
+ jsMap: (map) => _$$SecondaryBasicUiFunctionProps$JsMap(map),
+ ),
+ displayName: 'TopLevelForwardUiRefFunction');
+
+// Concrete props implementation.
+//
+// Implements constructor and backing map, and links up to generated component factory.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+abstract class _$$SecondaryBasicUiFunctionProps extends UiProps
+ with
+ BasicUiFunctionProps,
+ $BasicUiFunctionProps // If this generated mixin is undefined, it's likely because BasicUiFunctionProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of BasicUiFunctionProps.
+ implements
+ SecondaryBasicUiFunctionProps {
+ _$$SecondaryBasicUiFunctionProps._();
+
+ factory _$$SecondaryBasicUiFunctionProps(Map backingMap) {
+ if (backingMap == null || backingMap is JsBackedMap) {
+ return _$$SecondaryBasicUiFunctionProps$JsMap(backingMap);
+ } else {
+ return _$$SecondaryBasicUiFunctionProps$PlainMap(backingMap);
+ }
+ }
+
+ /// Let `UiProps` internals know that this class has been generated.
+ @override
+ bool get $isClassGenerated => true;
+
+ /// The default namespace for the prop getters/setters generated for this class.
+ @override
+ String get propKeyNamespace => '';
+}
+
+// Concrete props implementation that can be backed by any [Map].
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$SecondaryBasicUiFunctionProps$PlainMap
+ extends _$$SecondaryBasicUiFunctionProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$SecondaryBasicUiFunctionProps$PlainMap(Map backingMap)
+ : this._props = {},
+ super._() {
+ this._props = backingMap ?? {};
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ Map get props => _props;
+ Map _props;
+}
+
+// Concrete props implementation that can only be backed by [JsMap],
+// allowing dart2js to compile more optimal code for key-value pair reads/writes.
+@Deprecated('This API is for use only within generated code.'
+ ' Do not reference it in your code, as it may change at any time.')
+class _$$SecondaryBasicUiFunctionProps$JsMap
+ extends _$$SecondaryBasicUiFunctionProps {
+ // This initializer of `_props` to an empty map, as well as the reassignment
+ // of `_props` in the constructor body is necessary to work around a DDC bug: https://github.com/dart-lang/sdk/issues/36217
+ _$$SecondaryBasicUiFunctionProps$JsMap(JsBackedMap backingMap)
+ : this._props = JsBackedMap(),
+ super._() {
+ this._props = backingMap ?? JsBackedMap();
+ }
+
+ /// The backing props map proxied by this class.
+ @override
+ JsBackedMap get props => _props;
+ JsBackedMap _props;
+}
diff --git a/test/over_react_component_test.dart b/test/over_react_component_test.dart
index d13cb8078..ee940a875 100644
--- a/test/over_react_component_test.dart
+++ b/test/over_react_component_test.dart
@@ -20,7 +20,6 @@
library over_react_component_test;
import 'package:over_react/over_react.dart';
-import 'package:react/react_client.dart';
import 'package:test/test.dart';
import 'over_react/component/_deprecated/abstract_transition_test.dart' as deprecated_abstract_transition_test;
@@ -29,7 +28,7 @@ import 'over_react/component/dom_components_test.dart' as dom_components_test;
import 'over_react/component/error_boundary_test.dart' as error_boundary_test;
import 'over_react/component/_deprecated/error_boundary_mixin_test.dart' as deprecated_error_boundary_mixin_test;
import 'over_react/component/_deprecated/error_boundary_test.dart' as deprecated_error_boundary_test;
-import 'over_react/component/forward_ref_test.dart' as forward_ref_test;
+import 'over_react/component/ref_test.dart' as ref_test;
import 'over_react/component/prop_mixins_test.dart' as prop_mixins_test;
import 'over_react/component/prop_typedefs_test.dart' as prop_typedefs_test;
import 'over_react/component/pure_component_mixin_test.dart' as pure_component_mixin_test;
@@ -41,8 +40,6 @@ import 'over_react/component/context_test.dart' as context_test;
import 'over_react/component/typed_factory_test.dart' as typed_factory_test;
void main() {
- setClientConfiguration();
-
enableTestMode();
pure_component_mixin_test.main();
@@ -51,7 +48,7 @@ void main() {
error_boundary_test.main();
deprecated_error_boundary_mixin_test.main();
deprecated_error_boundary_test.main();
- forward_ref_test.main();
+ ref_test.main();
dom_components_test.main();
prop_mixins_test.main();
prop_typedefs_test.main();
From 117cadb5bf276f05fa27e3f31f48ef812ba87910 Mon Sep 17 00:00:00 2001
From: Joe Bingham
Date: Mon, 3 Aug 2020 11:24:16 -0700
Subject: [PATCH 05/28] Format tests
---
test/over_react/component/ref_test.dart | 73 +++++++++++++------------
1 file changed, 37 insertions(+), 36 deletions(-)
diff --git a/test/over_react/component/ref_test.dart b/test/over_react/component/ref_test.dart
index 4841d1792..b0ddbae1d 100644
--- a/test/over_react/component/ref_test.dart
+++ b/test/over_react/component/ref_test.dart
@@ -31,11 +31,11 @@ part 'ref_test.over_react.g.dart'; // ignore: uri_has_not_been_generated
main() {
group('forward ref -', () {
test('errors when wrapping a UiComponent', () {
- expect(() => forwardRef((props, ref) {
- return (BasicUiComponent()
- ..ref = ref
- )();
- })(BasicUiComponent), throwsArgumentError);
+ expect(
+ () => forwardRef((props, ref) {
+ return (BasicUiComponent()..ref = ref)();
+ })(BasicUiComponent),
+ throwsArgumentError);
});
commonRefForwardingTests();
@@ -99,7 +99,8 @@ main() {
final Ref refObject = createRef();
final vDomElement = (TopLevelForwardUiRefFunction()..ref = refObject)();
- expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), 'TopLevelForwardUiRefFunction');
+ expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'),
+ 'TopLevelForwardUiRefFunction');
});
group('returns normally when passed children', () {
@@ -152,9 +153,7 @@ void commonRefForwardingTests({bool useUiForwardRef = false}) {
UiFactory getFactoryForDiv({
String displayName,
}) {
- ReactElement div(Ref ref, dynamic children) => (Dom.div()
- ..ref = ref
- )(children);
+ ReactElement div(Ref ref, dynamic children) => (Dom.div()..ref = ref)(children);
if (useUiForwardRef) {
if (displayName == null) {
@@ -190,9 +189,7 @@ void commonRefForwardingTests({bool useUiForwardRef = false}) {
final Ref refObject = createRef();
- mount((DivForwarded()
- ..ref = refObject
- )());
+ mount((DivForwarded()..ref = refObject)());
expect(refObject.current, TypeMatcher());
});
@@ -204,7 +201,8 @@ void commonRefForwardingTests({bool useUiForwardRef = false}) {
final refObject = createRef();
final vDomElement = (DivForwarded()..ref = refObject)();
- expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), useUiForwardRef ? 'Anonymous' : 'div');
+ expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'),
+ useUiForwardRef ? 'Anonymous' : 'div');
});
test('when displayName argument is passed to the config constructor', () {
@@ -240,7 +238,8 @@ void commonRefForwardingTests({bool useUiForwardRef = false}) {
final Ref refObject = createRef();
final vDomElement = (BasicForwarded()..ref = refObject)();
- expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'), useUiForwardRef ? 'Anonymous' : 'Basic');
+ expect(getProperty(getProperty(vDomElement.type, 'render'), 'displayName'),
+ useUiForwardRef ? 'Anonymous' : 'Basic');
});
test('when displayName argument is passed to the config constructor', () {
@@ -268,26 +267,26 @@ void commonRefForwardingTests({bool useUiForwardRef = false}) {
const displayName = 'AVerySpecificDisplayName';
-void standardForwardRefTest(dynamic factory, {void Function(dynamic refValue) verifyRefValue, useUiForwardRef = false}) {
+void standardForwardRefTest(dynamic factory,
+ {void Function(dynamic refValue) verifyRefValue, useUiForwardRef = false}) {
test('- passes a ref through the parent to its child', () {
- UiFactory BasicForwarded = useUiForwardRef ? uiForwardRef((props, ref) {
- return (factory()
- ..ref = ref
- ..id = props.childId
- )();
- }, Basic.asForwardRefConfig()) : forwardRef((props, ref) {
- return (factory()
- ..ref = ref
- ..id = props.childId
- )();
- })(Basic);
+ UiFactory BasicForwarded = useUiForwardRef
+ ? uiForwardRef((props, ref) {
+ return (factory()
+ ..ref = ref
+ ..id = props.childId)();
+ }, Basic.asForwardRefConfig())
+ : forwardRef((props, ref) {
+ return (factory()
+ ..ref = ref
+ ..id = props.childId)();
+ })(Basic);
final Ref refObject = createRef();
mount((BasicForwarded()
..ref = refObject
- ..childId = 'test'
- )());
+ ..childId = 'test')());
// component props are accessed differently depending on if it is a dom component
// or a dart component
@@ -318,14 +317,16 @@ mixin BasicUiFunctionProps on UiProps {}
class SecondaryBasicUiFunctionProps = UiProps with BasicUiFunctionProps;
-final BasicUiFunction = uiFunction((props) {
- return props.children.isEmpty ? 'basic component' : props.children;
- },
- $BasicUiFunctionConfig, // ignore: undefined_identifier
+final BasicUiFunction = uiFunction(
+ (props) {
+ return props.children.isEmpty ? 'basic component' : props.children;
+ },
+ $BasicUiFunctionConfig, // ignore: undefined_identifier
);
-final TopLevelForwardUiRefFunction = uiForwardRef((props, ref) {
- return (BasicUiFunction()..ref = ref)(props.children);
-},
+final TopLevelForwardUiRefFunction = uiForwardRef(
+ (props, ref) {
+ return (BasicUiFunction()..ref = ref)(props.children);
+ },
$TopLevelForwardUiRefFunctionConfig, // ignore: undefined_identifier
-);
\ No newline at end of file
+);
From 96ba4ff72e9e3c80ace929e65f6cf0fbf118dd02 Mon Sep 17 00:00:00 2001
From: Joe Bingham
Date: Mon, 3 Aug 2020 12:44:16 -0700
Subject: [PATCH 06/28] Clean up
---
test/over_react/component/{ref_test.dart => ref_util_test.dart} | 2 +-
...f_test.over_react.g.dart => ref_util_test.over_react.g.dart} | 2 +-
test/over_react_component_test.dart | 2 +-
web/component2/src/demos/forward_ref.dart | 1 -
4 files changed, 3 insertions(+), 4 deletions(-)
rename test/over_react/component/{ref_test.dart => ref_util_test.dart} (99%)
rename test/over_react/component/{ref_test.over_react.g.dart => ref_util_test.over_react.g.dart} (99%)
diff --git a/test/over_react/component/ref_test.dart b/test/over_react/component/ref_util_test.dart
similarity index 99%
rename from test/over_react/component/ref_test.dart
rename to test/over_react/component/ref_util_test.dart
index b0ddbae1d..064957d1b 100644
--- a/test/over_react/component/ref_test.dart
+++ b/test/over_react/component/ref_util_test.dart
@@ -26,7 +26,7 @@ import '../../test_util/test_util.dart';
import '../component/fixtures/basic_child_component.dart';
import 'fixtures/basic_ui_component.dart';
-part 'ref_test.over_react.g.dart'; // ignore: uri_has_not_been_generated
+part 'ref_util_test.over_react.g.dart'; // ignore: uri_has_not_been_generated
main() {
group('forward ref -', () {
diff --git a/test/over_react/component/ref_test.over_react.g.dart b/test/over_react/component/ref_util_test.over_react.g.dart
similarity index 99%
rename from test/over_react/component/ref_test.over_react.g.dart
rename to test/over_react/component/ref_util_test.over_react.g.dart
index 85bd54ee2..6052baf77 100644
--- a/test/over_react/component/ref_test.over_react.g.dart
+++ b/test/over_react/component/ref_util_test.over_react.g.dart
@@ -1,7 +1,7 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: deprecated_member_use_from_same_package, unnecessary_null_in_if_null_operators, prefer_null_aware_operators
-part of 'ref_test.dart';
+part of 'ref_util_test.dart';
// **************************************************************************
// OverReactBuilder (package:over_react/src/builder.dart)
diff --git a/test/over_react_component_test.dart b/test/over_react_component_test.dart
index 08b3f121a..93ea59e4f 100644
--- a/test/over_react_component_test.dart
+++ b/test/over_react_component_test.dart
@@ -32,7 +32,7 @@ import 'over_react/component/_deprecated/error_boundary_mixin_test.dart'
as deprecated_error_boundary_mixin_test;
import 'over_react/component/_deprecated/error_boundary_test.dart'
as deprecated_error_boundary_test;
-import 'over_react/component/ref_test.dart' as ref_test;
+import 'over_react/component/ref_util_test.dart' as ref_test;
import 'over_react/component/memo_test.dart' as memo_test;
import 'over_react/component/prop_mixins_test.dart' as prop_mixins_test;
import 'over_react/component/prop_typedefs_test.dart' as prop_typedefs_test;
diff --git a/web/component2/src/demos/forward_ref.dart b/web/component2/src/demos/forward_ref.dart
index a6b16ed73..af88c0ca7 100644
--- a/web/component2/src/demos/forward_ref.dart
+++ b/web/component2/src/demos/forward_ref.dart
@@ -1,7 +1,6 @@
import 'dart:html';
import 'package:over_react/over_react.dart';
-import 'package:react/hooks.dart';
// ignore: uri_has_not_been_generated
part 'forward_ref.over_react.g.dart';
From de947874649dfc632e33ae7ddcc943b23732b139 Mon Sep 17 00:00:00 2001
From: Joe Bingham
Date: Mon, 3 Aug 2020 12:57:34 -0700
Subject: [PATCH 07/28] Rename FunctionComponentConfig to UiFactoryConfig
---
doc/new_boilerplate_migration.md | 4 +-
example/builder/src/function_component.dart | 4 +-
.../src/function_component.over_react.g.dart | 28 ++++++------
.../use_callback_example.over_react.g.dart | 4 +-
.../use_context_example.over_react.g.dart | 8 ++--
.../use_debug_value_example.over_react.g.dart | 8 ++--
...mperative_handle_example.over_react.g.dart | 17 ++++----
...se_layout_effect_example.over_react.g.dart | 4 +-
.../hooks/use_memo_example.over_react.g.dart | 4 +-
.../use_reducer_example.over_react.g.dart | 4 +-
.../hooks/use_ref_example.over_react.g.dart | 4 +-
.../hooks/use_state_example.over_react.g.dart | 4 +-
.../codegen/typed_map_impl_generator.dart | 8 ++--
lib/src/component/ref_util.dart | 2 +-
.../component_declaration/component_base.dart | 2 +-
.../function_component.dart | 10 ++---
lib/src/util/memo.dart | 2 +-
test/over_react/component/memo_test.dart | 2 +-
.../component/memo_test.over_react.g.dart | 4 +-
.../component/ref_util_test.over_react.g.dart | 8 ++--
.../function_component_test.dart | 6 +--
.../function_component_test.over_react.g.dart | 43 +++++++++----------
test/vm_tests/builder/codegen_test.dart | 8 ++--
.../builder/declaration_parsing_test.dart | 8 ++--
.../builder/parsing/ast_util_test.dart | 4 +-
.../src/demos/forward_ref.over_react.g.dart | 39 ++++++++---------
26 files changed, 115 insertions(+), 124 deletions(-)
diff --git a/doc/new_boilerplate_migration.md b/doc/new_boilerplate_migration.md
index 0781a2ea7..2fbf73ea3 100644
--- a/doc/new_boilerplate_migration.md
+++ b/doc/new_boilerplate_migration.md
@@ -772,7 +772,7 @@ UiFactory Foo = uiFunction(
(props) {
return 'id: ${props.id}';
},
- FunctionComponentConfig(
+ UiFactoryConfig(
displayName: 'Foo',
),
);
@@ -823,7 +823,7 @@ UiFactory createFooHoc(UiFactory otherFactory) {
Dom.div()('prop foo: ${props.foo}'),
);
},
- FunctionComponentConfig(
+ UiFactoryConfig(
displayName: 'FooHoc',
propsFactory: PropsFactory.fromUiFactory(Foo),
),
diff --git a/example/builder/src/function_component.dart b/example/builder/src/function_component.dart
index 704996b3a..453cbf978 100644
--- a/example/builder/src/function_component.dart
+++ b/example/builder/src/function_component.dart
@@ -78,7 +78,7 @@ ReactElement functionComponentContent() {
final genericFactory = uiFunction(
GenericFactory,
- FunctionComponentConfig(),
+ UiFactoryConfig(),
);
final basicFactory = uiFunction(
@@ -88,7 +88,7 @@ ReactElement functionComponentContent() {
Dom.div()('prop basic1: ${props.basic1}'),
);
},
- FunctionComponentConfig(
+ UiFactoryConfig(
propsFactory: PropsFactory.fromUiFactory(Basic),
displayName: 'basicFactory',
)
diff --git a/example/builder/src/function_component.over_react.g.dart b/example/builder/src/function_component.over_react.g.dart
index 068a71a8e..7ac74f604 100644
--- a/example/builder/src/function_component.over_react.g.dart
+++ b/example/builder/src/function_component.over_react.g.dart
@@ -123,21 +123,19 @@ const PropsMeta _$metaForFooProps = PropsMeta(
keys: $FooProps.$propKeys,
);
-final FunctionComponentConfig<_$$BasicProps> $_BasicConfig =
- FunctionComponentConfig(
- propsFactory: PropsFactory(
- map: (map) => _$$BasicProps(map),
- jsMap: (map) => _$$BasicProps$JsMap(map),
- ),
- displayName: '_Basic');
+final UiFactoryConfig<_$$BasicProps> $_BasicConfig = UiFactoryConfig(
+ propsFactory: PropsFactory(
+ map: (map) => _$$BasicProps(map),
+ jsMap: (map) => _$$BasicProps$JsMap(map),
+ ),
+ displayName: '_Basic');
-final FunctionComponentConfig<_$$BasicProps> $SimpleConfig =
- FunctionComponentConfig(
- propsFactory: PropsFactory(
- map: (map) => _$$BasicProps(map),
- jsMap: (map) => _$$BasicProps$JsMap(map),
- ),
- displayName: 'Simple');
+final UiFactoryConfig<_$$BasicProps> $SimpleConfig = UiFactoryConfig(
+ propsFactory: PropsFactory(
+ map: (map) => _$$BasicProps(map),
+ jsMap: (map) => _$$BasicProps$JsMap(map),
+ ),
+ displayName: 'Simple');
// Concrete props implementation.
//
@@ -205,7 +203,7 @@ class _$$BasicProps$JsMap extends _$$BasicProps {
JsBackedMap _props;
}
-final FunctionComponentConfig<_$$FooProps> $FooConfig = FunctionComponentConfig(
+final UiFactoryConfig<_$$FooProps> $FooConfig = UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$FooProps(map),
jsMap: (map) => _$$FooProps$JsMap(map),
diff --git a/example/hooks/use_callback_example.over_react.g.dart b/example/hooks/use_callback_example.over_react.g.dart
index 513cb3a26..17a76bbdf 100644
--- a/example/hooks/use_callback_example.over_react.g.dart
+++ b/example/hooks/use_callback_example.over_react.g.dart
@@ -26,8 +26,8 @@ const PropsMeta _$metaForUseCallbackExampleProps = PropsMeta(
keys: $UseCallbackExampleProps.$propKeys,
);
-final FunctionComponentConfig<_$$UseCallbackExampleProps>
- $UseCallbackExampleConfig = FunctionComponentConfig(
+final UiFactoryConfig<_$$UseCallbackExampleProps> $UseCallbackExampleConfig =
+ UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$UseCallbackExampleProps(map),
jsMap: (map) => _$$UseCallbackExampleProps$JsMap(map),
diff --git a/example/hooks/use_context_example.over_react.g.dart b/example/hooks/use_context_example.over_react.g.dart
index 1faa2a374..ebc10b77c 100644
--- a/example/hooks/use_context_example.over_react.g.dart
+++ b/example/hooks/use_context_example.over_react.g.dart
@@ -45,8 +45,8 @@ const PropsMeta _$metaForNewContextProviderProps = PropsMeta(
keys: $NewContextProviderProps.$propKeys,
);
-final FunctionComponentConfig<_$$UseContextExampleProps>
- $UseContextExampleConfig = FunctionComponentConfig(
+final UiFactoryConfig<_$$UseContextExampleProps> $UseContextExampleConfig =
+ UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$UseContextExampleProps(map),
jsMap: (map) => _$$UseContextExampleProps$JsMap(map),
@@ -119,8 +119,8 @@ class _$$UseContextExampleProps$JsMap extends _$$UseContextExampleProps {
JsBackedMap _props;
}
-final FunctionComponentConfig<_$$NewContextProviderProps>
- $NewContextProviderConfig = FunctionComponentConfig(
+final UiFactoryConfig<_$$NewContextProviderProps> $NewContextProviderConfig =
+ UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$NewContextProviderProps(map),
jsMap: (map) => _$$NewContextProviderProps$JsMap(map),
diff --git a/example/hooks/use_debug_value_example.over_react.g.dart b/example/hooks/use_debug_value_example.over_react.g.dart
index 27f140c6d..ddea2e6e4 100644
--- a/example/hooks/use_debug_value_example.over_react.g.dart
+++ b/example/hooks/use_debug_value_example.over_react.g.dart
@@ -58,8 +58,8 @@ const PropsMeta _$metaForUseDebugValueExampleProps = PropsMeta(
keys: $UseDebugValueExampleProps.$propKeys,
);
-final FunctionComponentConfig<_$$FriendListItemProps> $FriendListItemConfig =
- FunctionComponentConfig(
+final UiFactoryConfig<_$$FriendListItemProps> $FriendListItemConfig =
+ UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$FriendListItemProps(map),
jsMap: (map) => _$$FriendListItemProps$JsMap(map),
@@ -132,8 +132,8 @@ class _$$FriendListItemProps$JsMap extends _$$FriendListItemProps {
JsBackedMap _props;
}
-final FunctionComponentConfig<_$$UseDebugValueExampleProps>
- $UseDebugValueExampleConfig = FunctionComponentConfig(
+final UiFactoryConfig<_$$UseDebugValueExampleProps>
+ $UseDebugValueExampleConfig = UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$UseDebugValueExampleProps(map),
jsMap: (map) => _$$UseDebugValueExampleProps$JsMap(map),
diff --git a/example/hooks/use_imperative_handle_example.over_react.g.dart b/example/hooks/use_imperative_handle_example.over_react.g.dart
index 3b50275c3..721eec8d9 100644
--- a/example/hooks/use_imperative_handle_example.over_react.g.dart
+++ b/example/hooks/use_imperative_handle_example.over_react.g.dart
@@ -83,13 +83,12 @@ const PropsMeta _$metaForUseImperativeHandleExampleProps = PropsMeta(
keys: $UseImperativeHandleExampleProps.$propKeys,
);
-final FunctionComponentConfig<_$$FancyInputProps> $_FancyInputConfig =
- FunctionComponentConfig(
- propsFactory: PropsFactory(
- map: (map) => _$$FancyInputProps(map),
- jsMap: (map) => _$$FancyInputProps$JsMap(map),
- ),
- displayName: '_FancyInput');
+final UiFactoryConfig<_$$FancyInputProps> $_FancyInputConfig = UiFactoryConfig(
+ propsFactory: PropsFactory(
+ map: (map) => _$$FancyInputProps(map),
+ jsMap: (map) => _$$FancyInputProps$JsMap(map),
+ ),
+ displayName: '_FancyInput');
// Concrete props implementation.
//
@@ -157,8 +156,8 @@ class _$$FancyInputProps$JsMap extends _$$FancyInputProps {
JsBackedMap _props;
}
-final FunctionComponentConfig<_$$UseImperativeHandleExampleProps>
- $UseImperativeHandleExampleConfig = FunctionComponentConfig(
+final UiFactoryConfig<_$$UseImperativeHandleExampleProps>
+ $UseImperativeHandleExampleConfig = UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$UseImperativeHandleExampleProps(map),
jsMap: (map) => _$$UseImperativeHandleExampleProps$JsMap(map),
diff --git a/example/hooks/use_layout_effect_example.over_react.g.dart b/example/hooks/use_layout_effect_example.over_react.g.dart
index 05e554d0f..65006e460 100644
--- a/example/hooks/use_layout_effect_example.over_react.g.dart
+++ b/example/hooks/use_layout_effect_example.over_react.g.dart
@@ -26,8 +26,8 @@ const PropsMeta _$metaForUseLayoutEffectProps = PropsMeta(
keys: $UseLayoutEffectProps.$propKeys,
);
-final FunctionComponentConfig<_$$UseLayoutEffectProps>
- $UseLayoutEffectExampleConfig = FunctionComponentConfig(
+final UiFactoryConfig<_$$UseLayoutEffectProps> $UseLayoutEffectExampleConfig =
+ UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$UseLayoutEffectProps(map),
jsMap: (map) => _$$UseLayoutEffectProps$JsMap(map),
diff --git a/example/hooks/use_memo_example.over_react.g.dart b/example/hooks/use_memo_example.over_react.g.dart
index f830d9a29..dbce4a042 100644
--- a/example/hooks/use_memo_example.over_react.g.dart
+++ b/example/hooks/use_memo_example.over_react.g.dart
@@ -26,8 +26,8 @@ const PropsMeta _$metaForUseMemoExampleProps = PropsMeta(
keys: $UseMemoExampleProps.$propKeys,
);
-final FunctionComponentConfig<_$$UseMemoExampleProps> $UseMemoExampleConfig =
- FunctionComponentConfig(
+final UiFactoryConfig<_$$UseMemoExampleProps> $UseMemoExampleConfig =
+ UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$UseMemoExampleProps(map),
jsMap: (map) => _$$UseMemoExampleProps$JsMap(map),
diff --git a/example/hooks/use_reducer_example.over_react.g.dart b/example/hooks/use_reducer_example.over_react.g.dart
index 25c35d9ed..be8c974fe 100644
--- a/example/hooks/use_reducer_example.over_react.g.dart
+++ b/example/hooks/use_reducer_example.over_react.g.dart
@@ -41,8 +41,8 @@ const PropsMeta _$metaForUseReducerExampleProps = PropsMeta(
keys: $UseReducerExampleProps.$propKeys,
);
-final FunctionComponentConfig<_$$UseReducerExampleProps>
- $UseReducerExampleConfig = FunctionComponentConfig(
+final UiFactoryConfig<_$$UseReducerExampleProps> $UseReducerExampleConfig =
+ UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$UseReducerExampleProps(map),
jsMap: (map) => _$$UseReducerExampleProps$JsMap(map),
diff --git a/example/hooks/use_ref_example.over_react.g.dart b/example/hooks/use_ref_example.over_react.g.dart
index ee23135ec..bdb66cbb3 100644
--- a/example/hooks/use_ref_example.over_react.g.dart
+++ b/example/hooks/use_ref_example.over_react.g.dart
@@ -26,8 +26,8 @@ const PropsMeta _$metaForUseRefExampleProps = PropsMeta(
keys: $UseRefExampleProps.$propKeys,
);
-final FunctionComponentConfig<_$$UseRefExampleProps> $UseRefExampleConfig =
- FunctionComponentConfig(
+final UiFactoryConfig<_$$UseRefExampleProps> $UseRefExampleConfig =
+ UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$UseRefExampleProps(map),
jsMap: (map) => _$$UseRefExampleProps$JsMap(map),
diff --git a/example/hooks/use_state_example.over_react.g.dart b/example/hooks/use_state_example.over_react.g.dart
index 83c3ca39c..138da435c 100644
--- a/example/hooks/use_state_example.over_react.g.dart
+++ b/example/hooks/use_state_example.over_react.g.dart
@@ -26,8 +26,8 @@ const PropsMeta _$metaForUseStateExampleProps = PropsMeta(
keys: $UseStateExampleProps.$propKeys,
);
-final FunctionComponentConfig<_$$UseStateExampleProps> $UseStateExampleConfig =
- FunctionComponentConfig(
+final UiFactoryConfig<_$$UseStateExampleProps> $UseStateExampleConfig =
+ UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$UseStateExampleProps(map),
jsMap: (map) => _$$UseStateExampleProps$JsMap(map),
diff --git a/lib/src/builder/codegen/typed_map_impl_generator.dart b/lib/src/builder/codegen/typed_map_impl_generator.dart
index 19f095119..8e860d278 100644
--- a/lib/src/builder/codegen/typed_map_impl_generator.dart
+++ b/lib/src/builder/codegen/typed_map_impl_generator.dart
@@ -377,9 +377,9 @@ class _TypedMapImplGenerator extends TypedMapImplGenerator {
@override
bool get isComponent2 => true;
- String _generateFunctionComponentConfig(FactoryNames factoryName) {
- return 'final FunctionComponentConfig<${names.implName}> '
- '${factoryName.configName} = FunctionComponentConfig(\n'
+ String _generateUiFactoryConfig(FactoryNames factoryName) {
+ return 'final UiFactoryConfig<${names.implName}> '
+ '${factoryName.configName} = UiFactoryConfig(\n'
'propsFactory: PropsFactory(\n'
'map: (map) => ${names.implName}(map),\n'
'jsMap: (map) => ${names.jsMapImplName}(map),),\n'
@@ -390,7 +390,7 @@ class _TypedMapImplGenerator extends TypedMapImplGenerator {
void _generateFactory() {
if (isFunctionComponentDeclaration) {
for (final factoryName in factoryNames) {
- outputContentsBuffer.write(_generateFunctionComponentConfig(factoryName));
+ outputContentsBuffer.write(_generateUiFactoryConfig(factoryName));
}
} else {
super._generateFactory();
diff --git a/lib/src/component/ref_util.dart b/lib/src/component/ref_util.dart
index bbd055461..6092e1170 100644
--- a/lib/src/component/ref_util.dart
+++ b/lib/src/component/ref_util.dart
@@ -450,7 +450,7 @@ UiFactory Function(UiFactory) forwardRef
/// Learn more: .
UiFactory uiForwardRef(
dynamic Function(TProps props, dynamic ref) functionComponent,
- FunctionComponentConfig config) {
+ UiFactoryConfig config) {
ArgumentError.checkNotNull(config, 'config');
// ignore: invalid_use_of_protected_member
diff --git a/lib/src/component_declaration/component_base.dart b/lib/src/component_declaration/component_base.dart
index 4c018ade6..412761385 100644
--- a/lib/src/component_declaration/component_base.dart
+++ b/lib/src/component_declaration/component_base.dart
@@ -94,7 +94,7 @@ ReactDartComponentFactoryProxy registerAbstractComponent(Type abstractComponentC
typedef TProps UiFactory([Map backingProps]);
extension UiFactoryHelpers on UiFactory {
- FunctionComponentConfig asForwardRefConfig({String displayName}) => FunctionComponentConfig(propsFactory: PropsFactory.fromUiFactory(this), displayName: displayName);
+ UiFactoryConfig asForwardRefConfig({String displayName}) => UiFactoryConfig(propsFactory: PropsFactory.fromUiFactory(this), displayName: displayName);
}
/// A utility variation on [UiFactory], __without__ a `backingProps` parameter.
diff --git a/lib/src/component_declaration/function_component.dart b/lib/src/component_declaration/function_component.dart
index c306c2604..64fb2e9ce 100644
--- a/lib/src/component_declaration/function_component.dart
+++ b/lib/src/component_declaration/function_component.dart
@@ -69,7 +69,7 @@ export 'component_type_checking.dart'
/// (props) {
/// return (Dom.button()..disabled = props.isDisabled)('Click me!');
/// },
-/// FunctionComponentConfig(
+/// UiFactoryConfig(
/// propsFactory: PropsFactory.fromUiFactory(Foo),
/// displayName: 'Bar',
/// ),
@@ -83,7 +83,7 @@ export 'component_type_checking.dart'
/// (props) {
/// return Dom.div()('prop id: ${props.id}');
/// },
-/// FunctionComponentConfig(
+/// UiFactoryConfig(
/// displayName: 'Foo',
/// ),
/// );
@@ -93,7 +93,7 @@ export 'component_type_checking.dart'
// TODO: right now only top level factory declarations will generate props configs.
UiFactory uiFunction(
dynamic Function(TProps props) functionComponent,
- FunctionComponentConfig config,
+ UiFactoryConfig config,
) {
ArgumentError.checkNotNull(config, 'config');
@@ -161,12 +161,12 @@ class GenericUiProps extends UiProps {
}
/// Helper class used to keep track of generated information for [uiFunction].
-class FunctionComponentConfig {
+class UiFactoryConfig {
@protected
final PropsFactory propsFactory;
final String displayName;
- FunctionComponentConfig({this.propsFactory, this.displayName});
+ UiFactoryConfig({this.propsFactory, this.displayName});
}
/// Helper class to keep track of props factories used by [uiFunction],
diff --git a/lib/src/util/memo.dart b/lib/src/util/memo.dart
index 93f208f0d..d348edd60 100644
--- a/lib/src/util/memo.dart
+++ b/lib/src/util/memo.dart
@@ -36,7 +36,7 @@ import 'package:over_react/component_base.dart';
/// (props) {
/// // render using props
/// },
-/// FunctionComponentConfig(),
+/// UiFactoryConfig(),
/// ));
/// ```
///
diff --git a/test/over_react/component/memo_test.dart b/test/over_react/component/memo_test.dart
index 83ef2a7ce..dc6886104 100644
--- a/test/over_react/component/memo_test.dart
+++ b/test/over_react/component/memo_test.dart
@@ -53,7 +53,7 @@ main() {
(props) {
return Dom.div()('prop id: ${props.id}');
},
- FunctionComponentConfig(),
+ UiFactoryConfig(),
);
UiFactory FunctionMemo = memo(FunctionTest);
diff --git a/test/over_react/component/memo_test.over_react.g.dart b/test/over_react/component/memo_test.over_react.g.dart
index 048ffe6c2..c86027a9f 100644
--- a/test/over_react/component/memo_test.over_react.g.dart
+++ b/test/over_react/component/memo_test.over_react.g.dart
@@ -202,8 +202,8 @@ const PropsMeta _$metaForFunctionCustomPropsProps = PropsMeta(
keys: $FunctionCustomPropsProps.$propKeys,
);
-final FunctionComponentConfig<_$$FunctionCustomPropsProps>
- $FunctionCustomPropsConfig = FunctionComponentConfig(
+final UiFactoryConfig<_$$FunctionCustomPropsProps> $FunctionCustomPropsConfig =
+ UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$FunctionCustomPropsProps(map),
jsMap: (map) => _$$FunctionCustomPropsProps$JsMap(map),
diff --git a/test/over_react/component/ref_util_test.over_react.g.dart b/test/over_react/component/ref_util_test.over_react.g.dart
index 6052baf77..853fcf916 100644
--- a/test/over_react/component/ref_util_test.over_react.g.dart
+++ b/test/over_react/component/ref_util_test.over_react.g.dart
@@ -191,8 +191,8 @@ const PropsMeta _$metaForBasicUiFunctionProps = PropsMeta(
keys: $BasicUiFunctionProps.$propKeys,
);
-final FunctionComponentConfig<_$$BasicUiFunctionProps> $BasicUiFunctionConfig =
- FunctionComponentConfig(
+final UiFactoryConfig<_$$BasicUiFunctionProps> $BasicUiFunctionConfig =
+ UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$BasicUiFunctionProps(map),
jsMap: (map) => _$$BasicUiFunctionProps$JsMap(map),
@@ -265,8 +265,8 @@ class _$$BasicUiFunctionProps$JsMap extends _$$BasicUiFunctionProps {
JsBackedMap _props;
}
-final FunctionComponentConfig<_$$SecondaryBasicUiFunctionProps>
- $TopLevelForwardUiRefFunctionConfig = FunctionComponentConfig(
+final UiFactoryConfig<_$$SecondaryBasicUiFunctionProps>
+ $TopLevelForwardUiRefFunctionConfig = UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$SecondaryBasicUiFunctionProps(map),
jsMap: (map) => _$$SecondaryBasicUiFunctionProps$JsMap(map),
diff --git a/test/over_react/component_declaration/builder_integration_tests/new_boilerplate/function_component_test.dart b/test/over_react/component_declaration/builder_integration_tests/new_boilerplate/function_component_test.dart
index d2fea0f61..58f780ddf 100644
--- a/test/over_react/component_declaration/builder_integration_tests/new_boilerplate/function_component_test.dart
+++ b/test/over_react/component_declaration/builder_integration_tests/new_boilerplate/function_component_test.dart
@@ -44,7 +44,7 @@ main() {
group('with UiProps', () {
UiFactory TestUiProps = uiFunction(
(props) => (Dom.div()..addTestId('testId3'))('id: ${props.id}'),
- FunctionComponentConfig(),
+ UiFactoryConfig(),
);
test(
@@ -100,7 +100,7 @@ main() {
expect(
() => uiFunction(
(props) => Dom.div()(),
- FunctionComponentConfig(displayName: 'Foo'),
+ UiFactoryConfig(displayName: 'Foo'),
),
throwsArgumentError);
});
@@ -213,7 +213,7 @@ UiFactory TestCustom = uiFunction(
..addProp('data-prop-custom-key-and-namespace-prop',
props.customKeyAndNamespaceProp))('rendered content');
},
- FunctionComponentConfig(
+ UiFactoryConfig(
propsFactory: PropsFactory.fromUiFactory(Test),
)
);
diff --git a/test/over_react/component_declaration/builder_integration_tests/new_boilerplate/function_component_test.over_react.g.dart b/test/over_react/component_declaration/builder_integration_tests/new_boilerplate/function_component_test.over_react.g.dart
index 7d501af18..33d4e536e 100644
--- a/test/over_react/component_declaration/builder_integration_tests/new_boilerplate/function_component_test.over_react.g.dart
+++ b/test/over_react/component_declaration/builder_integration_tests/new_boilerplate/function_component_test.over_react.g.dart
@@ -106,29 +106,26 @@ const PropsMeta _$metaForTestProps = PropsMeta(
keys: $TestProps.$propKeys,
);
-final FunctionComponentConfig<_$$TestProps> $TestConfig =
- FunctionComponentConfig(
- propsFactory: PropsFactory(
- map: (map) => _$$TestProps(map),
- jsMap: (map) => _$$TestProps$JsMap(map),
- ),
- displayName: 'Test');
-
-final FunctionComponentConfig<_$$TestProps> $NoLHSTestConfig =
- FunctionComponentConfig(
- propsFactory: PropsFactory(
- map: (map) => _$$TestProps(map),
- jsMap: (map) => _$$TestProps$JsMap(map),
- ),
- displayName: 'NoLHSTest');
-
-final FunctionComponentConfig<_$$TestProps> $_TestConfig =
- FunctionComponentConfig(
- propsFactory: PropsFactory(
- map: (map) => _$$TestProps(map),
- jsMap: (map) => _$$TestProps$JsMap(map),
- ),
- displayName: '_Test');
+final UiFactoryConfig<_$$TestProps> $TestConfig = UiFactoryConfig(
+ propsFactory: PropsFactory(
+ map: (map) => _$$TestProps(map),
+ jsMap: (map) => _$$TestProps$JsMap(map),
+ ),
+ displayName: 'Test');
+
+final UiFactoryConfig<_$$TestProps> $NoLHSTestConfig = UiFactoryConfig(
+ propsFactory: PropsFactory(
+ map: (map) => _$$TestProps(map),
+ jsMap: (map) => _$$TestProps$JsMap(map),
+ ),
+ displayName: 'NoLHSTest');
+
+final UiFactoryConfig<_$$TestProps> $_TestConfig = UiFactoryConfig(
+ propsFactory: PropsFactory(
+ map: (map) => _$$TestProps(map),
+ jsMap: (map) => _$$TestProps$JsMap(map),
+ ),
+ displayName: '_Test');
// Concrete props implementation.
//
diff --git a/test/vm_tests/builder/codegen_test.dart b/test/vm_tests/builder/codegen_test.dart
index cf6b1d5ce..fad51b903 100644
--- a/test/vm_tests/builder/codegen_test.dart
+++ b/test/vm_tests/builder/codegen_test.dart
@@ -658,8 +658,8 @@ main() {
group('and generates props config for function components', () {
String generatedConfig(String propsName, String factoryName) {
- return 'final FunctionComponentConfig<_\$\$$propsName> '
- '\$${factoryName}Config = FunctionComponentConfig(\n'
+ return 'final UiFactoryConfig<_\$\$$propsName> '
+ '\$${factoryName}Config = UiFactoryConfig(\n'
'propsFactory: PropsFactory(\n'
'map: (map) => _\$\$$propsName(map),\n'
'jsMap: (map) => _\$\$$propsName\$JsMap(map),),\n'
@@ -767,7 +767,7 @@ main() {
(props) {
return Dom.div()();
},
- FunctionComponentConfig(),
+ UiFactoryConfig(),
);
final Foo = uiFunction(
@@ -781,7 +781,7 @@ main() {
(props) {
return Dom.div()();
},
- FunctionComponentConfig(
+ UiFactoryConfig(
propsFactory: PropsFactory.fromUiFactory(Foo),
)
);
diff --git a/test/vm_tests/builder/declaration_parsing_test.dart b/test/vm_tests/builder/declaration_parsing_test.dart
index e12814d2b..8415f7f0d 100644
--- a/test/vm_tests/builder/declaration_parsing_test.dart
+++ b/test/vm_tests/builder/declaration_parsing_test.dart
@@ -1586,7 +1586,7 @@ main() {
(props) {
return Dom.div()();
},
- FunctionComponentConfig(
+ UiFactoryConfig(
propsFactory: PropsFactory.fromUiFactory(Foo),
),
);
@@ -1645,7 +1645,7 @@ main() {
(props) {
return Dom.div()();
},
- FunctionComponentConfig(),
+ UiFactoryConfig(),
);
''');
@@ -1672,7 +1672,7 @@ main() {
(props) {
return Dom.div()();
},
- FunctionComponentConfig(
+ UiFactoryConfig(
propsFactory: PropsFactory.uiFactory(Foo),
),
));
@@ -1681,7 +1681,7 @@ main() {
(props) {
return Dom.div()();
},
- FunctionComponentConfig(),
+ UiFactoryConfig(),
));
mixin FooPropsMixin on UiProps {}
diff --git a/test/vm_tests/builder/parsing/ast_util_test.dart b/test/vm_tests/builder/parsing/ast_util_test.dart
index b013cdc01..f897e61ac 100644
--- a/test/vm_tests/builder/parsing/ast_util_test.dart
+++ b/test/vm_tests/builder/parsing/ast_util_test.dart
@@ -82,7 +82,7 @@ main() {
expect(InitializerHelperTopLevel(parseAndGetSingleWithType('''
final Foo = uiFunction(
(props) => Dom.div()(),
- FunctionComponentConfig(),
+ UiFactoryConfig(),
);
''')).hasGeneratedConfigArg, false);
@@ -96,7 +96,7 @@ main() {
expect(InitializerHelperTopLevel(parseAndGetSingleWithType('''
final Foo = uiFunction(
(props) => Dom.div()(),
- FunctionComponentConfig(
+ UiFactoryConfig(
propsFactory: PropsFactory.fromUiFactory(Bar),
),
);
diff --git a/web/component2/src/demos/forward_ref.over_react.g.dart b/web/component2/src/demos/forward_ref.over_react.g.dart
index b6ee921af..60f4c252e 100644
--- a/web/component2/src/demos/forward_ref.over_react.g.dart
+++ b/web/component2/src/demos/forward_ref.over_react.g.dart
@@ -410,8 +410,8 @@ const PropsMeta _$metaForRefDemoHocProps = PropsMeta(
keys: $RefDemoHocProps.$propKeys,
);
-final FunctionComponentConfig<_$$UiForwardRefLogsFunctionComponentProps>
- $UiForwardRefLogsFunctionComponentConfig = FunctionComponentConfig(
+final UiFactoryConfig<_$$UiForwardRefLogsFunctionComponentProps>
+ $UiForwardRefLogsFunctionComponentConfig = UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$UiForwardRefLogsFunctionComponentProps(map),
jsMap: (map) => _$$UiForwardRefLogsFunctionComponentProps$JsMap(map),
@@ -486,10 +486,8 @@ class _$$UiForwardRefLogsFunctionComponentProps$JsMap
JsBackedMap _props;
}
-final FunctionComponentConfig<
- _$$UiForwardRefLogsPropsComplexFunctionComponentProps>
- $UiForwardRefLogsPropsComplexFunctionComponentConfig =
- FunctionComponentConfig(
+final UiFactoryConfig<_$$UiForwardRefLogsPropsComplexFunctionComponentProps>
+ $UiForwardRefLogsPropsComplexFunctionComponentConfig = UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) =>
_$$UiForwardRefLogsPropsComplexFunctionComponentProps(map),
@@ -574,8 +572,8 @@ class _$$UiForwardRefLogsPropsComplexFunctionComponentProps$JsMap
JsBackedMap _props;
}
-final FunctionComponentConfig<_$$UiForwardRefLogsPropsComplexComponentProps>
- $UiForwardRefLogsPropsComplexComponentConfig = FunctionComponentConfig(
+final UiFactoryConfig<_$$UiForwardRefLogsPropsComplexComponentProps>
+ $UiForwardRefLogsPropsComplexComponentConfig = UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$UiForwardRefLogsPropsComplexComponentProps(map),
jsMap: (map) =>
@@ -654,8 +652,8 @@ class _$$UiForwardRefLogsPropsComplexComponentProps$JsMap
JsBackedMap _props;
}
-final FunctionComponentConfig<_$$_LogsPropsFunctionComponentProps>
- $_LogsPropsFunctionComponentConfig = FunctionComponentConfig(
+final UiFactoryConfig<_$$_LogsPropsFunctionComponentProps>
+ $_LogsPropsFunctionComponentConfig = UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$_LogsPropsFunctionComponentProps(map),
jsMap: (map) => _$$_LogsPropsFunctionComponentProps$JsMap(map),
@@ -731,8 +729,8 @@ class _$$_LogsPropsFunctionComponentProps$JsMap
JsBackedMap _props;
}
-final FunctionComponentConfig<_$$RefDemoProps> $RefDemoContainerConfig =
- FunctionComponentConfig(
+final UiFactoryConfig<_$$RefDemoProps> $RefDemoContainerConfig =
+ UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$RefDemoProps(map),
jsMap: (map) => _$$RefDemoProps$JsMap(map),
@@ -805,8 +803,8 @@ class _$$RefDemoProps$JsMap extends _$$RefDemoProps {
JsBackedMap _props;
}
-final FunctionComponentConfig<_$$RefDemoSectionProps> $RefDemoSectionConfig =
- FunctionComponentConfig(
+final UiFactoryConfig<_$$RefDemoSectionProps> $RefDemoSectionConfig =
+ UiFactoryConfig(
propsFactory: PropsFactory(
map: (map) => _$$RefDemoSectionProps(map),
jsMap: (map) => _$$RefDemoSectionProps$JsMap(map),
@@ -879,13 +877,12 @@ class _$$RefDemoSectionProps$JsMap extends _$$RefDemoSectionProps {
JsBackedMap _props;
}
-final FunctionComponentConfig<_$$RefDemoHocProps> $RefDemoHocConfig =
- FunctionComponentConfig(
- propsFactory: PropsFactory(
- map: (map) => _$$RefDemoHocProps(map),
- jsMap: (map) => _$$RefDemoHocProps$JsMap(map),
- ),
- displayName: 'RefDemoHoc');
+final UiFactoryConfig<_$$RefDemoHocProps> $RefDemoHocConfig = UiFactoryConfig(
+ propsFactory: PropsFactory(
+ map: (map) => _$$RefDemoHocProps(map),
+ jsMap: (map) => _$$RefDemoHocProps$JsMap(map),
+ ),
+ displayName: 'RefDemoHoc');
// Concrete props implementation.
//
From ea10a41d2864c7ac4bd67697533f6bfaaf4bb345 Mon Sep 17 00:00:00 2001
From: Joe Bingham
Date: Mon, 3 Aug 2020 16:38:34 -0700
Subject: [PATCH 08/28] Check for generated config
---
lib/src/builder/parsing/ast_util.dart | 18 +++++++++++++-----
lib/src/builder/parsing/members_from_ast.dart | 5 +++--
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/lib/src/builder/parsing/ast_util.dart b/lib/src/builder/parsing/ast_util.dart
index 6bb09e36a..e2877e203 100644
--- a/lib/src/builder/parsing/ast_util.dart
+++ b/lib/src/builder/parsing/ast_util.dart
@@ -46,12 +46,15 @@ extension InitializerHelperTopLevel on TopLevelVariableDeclaration {
bool get hasGeneratedConfigArg {
return firstInitializer != null &&
anyDescendantIdentifiers(firstInitializer, (identifier) {
- if (identifier.isFunctionType) {
- final args =
- identifier.thisOrAncestorOfType()?.argumentList?.arguments;
+ final uiFactoryDeclaration = identifier.thisOrAncestorOfType();
+ final methodInvocation = identifier.thisOrAncestorOfType();
+ if (methodInvocation != null && uiFactoryDeclaration != null) {
+ final args = methodInvocation.argumentList?.arguments;
if (args == null || args.length < 2) return false;
- return args[1].toString().startsWith(RegExp(r'\$'));
+
+ return args[1].toString() == '\$${uiFactoryDeclaration.name.name}Config';
}
+
return false;
});
}
@@ -80,7 +83,12 @@ extension NameHelper on Identifier {
return self is PrefixedIdentifier ? self.identifier.name : self.name;
}
- bool get isFunctionType => ['uiFunction', 'uiForwardRef'].contains(this.name);
+ bool get isFunctionType => ['uiFunction', 'uiForwardRef', 'uiJsComponent'].contains(this.name);
+
+ bool get isAttachedToAGeneratedUiFactory {
+ final uiFactoryDeclaration = this.thisOrAncestorOfType();
+ return uiFactoryDeclaration?.hasGeneratedConfigArg;
+ }
}
/// Utilities related to detecting a super class on a [MixinDeclaration]
diff --git a/lib/src/builder/parsing/members_from_ast.dart b/lib/src/builder/parsing/members_from_ast.dart
index 01cb2999c..a44046782 100644
--- a/lib/src/builder/parsing/members_from_ast.dart
+++ b/lib/src/builder/parsing/members_from_ast.dart
@@ -170,11 +170,12 @@ class _BoilerplateMemberDetector {
final rightHandSide = node.variables.firstInitializer;
if (rightHandSide != null &&
- anyDescendantIdentifiers(rightHandSide, (identifier) => identifier.isFunctionType)) {
+ anyDescendantIdentifiers(
+ rightHandSide, (identifier) => identifier.isAttachedToAGeneratedUiFactory)) {
onFactory(BoilerplateFactory(
node,
VersionConfidences(
- v4_mixinBased: node.hasGeneratedConfigArg ? Confidence.likely : Confidence.neutral,
+ v4_mixinBased: Confidence.likely,
v3_legacyDart2Only: Confidence.none,
v2_legacyBackwardsCompat: Confidence.none,
)));
From d435a1f3f3d6669f22b9da6ddd359a7a1ffa0eb2 Mon Sep 17 00:00:00 2001
From: Joe Bingham
Date: Tue, 4 Aug 2020 13:59:04 -0700
Subject: [PATCH 09/28] Fix parsing
---
lib/src/builder/parsing/ast_util.dart | 13 ++++++++++++-
.../src/demos/{forward_ref.dart => ref.dart} | 0
2 files changed, 12 insertions(+), 1 deletion(-)
rename web/component2/src/demos/{forward_ref.dart => ref.dart} (100%)
diff --git a/lib/src/builder/parsing/ast_util.dart b/lib/src/builder/parsing/ast_util.dart
index e2877e203..e1d10934c 100644
--- a/lib/src/builder/parsing/ast_util.dart
+++ b/lib/src/builder/parsing/ast_util.dart
@@ -52,7 +52,18 @@ extension InitializerHelperTopLevel on TopLevelVariableDeclaration {
final args = methodInvocation.argumentList?.arguments;
if (args == null || args.length < 2) return false;
- return args[1].toString() == '\$${uiFactoryDeclaration.name.name}Config';
+ if (args[1] is SimpleIdentifier) {
+ return args[1].toString() == '\$${uiFactoryDeclaration.name.name}Config';
+ } else if (args[1] is PrefixedIdentifier) {
+ return args[1]
+ .childEntities
+ .where((child) {
+ return child is SimpleIdentifier &&
+ child.name == '\$${uiFactoryDeclaration.name.name}Config';
+ })
+ .toList()
+ .isNotEmpty;
+ }
}
return false;
diff --git a/web/component2/src/demos/forward_ref.dart b/web/component2/src/demos/ref.dart
similarity index 100%
rename from web/component2/src/demos/forward_ref.dart
rename to web/component2/src/demos/ref.dart
From d865b24acee13d258193a799f1ee99c5dccf52c0 Mon Sep 17 00:00:00 2001
From: Joe Bingham
Date: Wed, 5 Aug 2020 08:29:51 -0700
Subject: [PATCH 10/28] Fix up example
---
pubspec.yaml | 1 -
web/component2/src/demos.dart | 2 +-
web/component2/src/demos/ref.dart | 55 ++++++++++++-------
...ver_react.g.dart => ref.over_react.g.dart} | 47 +++++++++++-----
4 files changed, 67 insertions(+), 38 deletions(-)
rename web/component2/src/demos/{forward_ref.over_react.g.dart => ref.over_react.g.dart} (95%)
diff --git a/pubspec.yaml b/pubspec.yaml
index 4e5d33c7e..28b3740bc 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -48,7 +48,6 @@ dev_dependencies:
test: ^1.9.1
yaml: ^2.2.1
-
dependency_overrides:
react:
git:
diff --git a/web/component2/src/demos.dart b/web/component2/src/demos.dart
index da00f6dd6..b32b3c337 100644
--- a/web/component2/src/demos.dart
+++ b/web/component2/src/demos.dart
@@ -23,7 +23,7 @@ export 'demos/button/button-active.dart';
export 'demos/button/button-disabled.dart';
export 'demos/custom_error_boundary.dart';
-export 'demos/forward_ref.dart';
+export 'demos/ref.dart';
export '../src/demo_components/prop_validation_wrap.dart';
diff --git a/web/component2/src/demos/ref.dart b/web/component2/src/demos/ref.dart
index af88c0ca7..9c5597d97 100644
--- a/web/component2/src/demos/ref.dart
+++ b/web/component2/src/demos/ref.dart
@@ -3,11 +3,12 @@ import 'dart:html';
import 'package:over_react/over_react.dart';
// ignore: uri_has_not_been_generated
-part 'forward_ref.over_react.g.dart';
+part 'ref.over_react.g.dart';
// ------------ `uiForwardRef` with a function component (simple) ------------
mixin UiForwardRefLogsFunctionComponentProps on UiProps {
BuilderOnlyUiFactory builder;
+ Ref lastClickedButton;
}
final UiForwardRefLogsFunctionComponent = uiForwardRef(
@@ -16,8 +17,8 @@ final UiForwardRefLogsFunctionComponent = uiForwardRef(
@@ -108,7 +109,7 @@ mixin LogPropsProps on UiProps {
BuilderOnlyUiFactory builder;
// A simple prop to change in order to trigger the print.
- bool thisWasClickedLast;
+ Ref lastClickedButton;
// Private since we only use this to pass along the value of `ref` to
// the return value of forwardRef.
@@ -126,11 +127,9 @@ class LogPropsComponent extends UiComponent2 {
@override
render() {
- return Dom.div()(
- Dom.p()('This was the last button clicked: ${props.thisWasClickedLast}'),
- (props.builder()
- ..modifyProps(addUnconsumedDomProps)
- ..ref = props._forwardedRef)(props.children));
+ return Dom.div()((props.builder()
+ ..modifyProps(addUnconsumedDomProps)
+ ..ref = props._forwardedRef)(props.children));
}
}
@@ -149,8 +148,8 @@ final _LogsPropsFunctionComponent = uiFunction<_LogsPropsFunctionComponentProps>
useEffect(() {
if (prevPropsRef.current != null) {
- print(prevPropsRef.current);
- print(props);
+ print('old props: ${prevPropsRef.current}');
+ print('new props: $props');
}
prevPropsRef.current = props;
@@ -190,50 +189,58 @@ final RefDemoContainer = uiFunction(
final fancyButtonNodeRef = createRef();
final fancyFunctionalButtonNodeRef = createRef();
- final lastClickedRef = useState][(null);
+ final lastClickedRef = useState][>(buttonNodeRefForComplexComponent);
return ((Dom.div()..style = {'padding': 10})(
(RefDemoSection()..sectionTitle = 'uiForwardRef Demos')(
(RefDemoHoc()..demoTitle = '`uiForwardRef` with a function component (simple)')(
(UiForwardRefLogsFunctionComponent()
..builder = FancyButton
+ ..lastClickedButton = lastClickedRef.value
..id = 'uiForwardRef-function-component'
..className = 'btn btn-primary'
..ref = buttonNodeRefForSimpleFunctionComponent
..onClick = (_) {
- print(buttonNodeRefForSimpleFunctionComponent.current.outerHtml);
+ printButtonOuterHtml(buttonNodeRefForSimpleFunctionComponent);
+ lastClickedRef.set(buttonNodeRefForSimpleFunctionComponent);
})(),
),
(RefDemoHoc()..demoTitle = '`uiForwardRef` with a function component (complex)')(
(UiForwardRefLogsPropsComplexFunctionComponent()
..buttonDescription = 'A button that logs the innerHtml'
..builder = FancyButton
+ ..lastClickedButton = lastClickedRef.value
..id = 'uiForwardRef-function-complex-component'
..className = 'btn btn-success'
..ref = buttonNodeRefForComplexFunctionComponent
..onClick = (_) {
- print(buttonNodeRefForComplexFunctionComponent.current.outerHtml);
+ printButtonOuterHtml(buttonNodeRefForComplexFunctionComponent);
+ lastClickedRef.set(buttonNodeRefForComplexFunctionComponent);
})(),
),
(RefDemoHoc()..demoTitle = '`uiForwardRef` with a class component (simple)')(
(UiForwardRefLogsPropsComponent()
..builder = FancyButton
+ ..lastClickedButton = lastClickedRef.value
..id = 'uiForwardRef-component'
..className = 'btn btn-warning'
..ref = buttonNodeRefForSimpleComponent
..onClick = (_) {
- print(buttonNodeRefForSimpleComponent.current.outerHtml);
+ printButtonOuterHtml(buttonNodeRefForSimpleComponent);
+ lastClickedRef.set(buttonNodeRefForSimpleComponent);
})(),
),
(RefDemoHoc()..demoTitle = '`uiForwardRef` with a class component (complex)')(
(UiForwardRefLogsPropsComplexComponent()
..buttonDescription = 'A button that logs the innerHtml'
..builder = FancyButton
+ ..lastClickedButton = lastClickedRef.value
..id = 'uiForwardRef-complex-component'
..className = 'btn btn-danger'
..ref = buttonNodeRefForComplexComponent
..onClick = (_) {
- print(buttonNodeRefForComplexComponent.current.outerHtml);
+ printButtonOuterHtml(buttonNodeRefForComplexComponent);
+ lastClickedRef.set(buttonNodeRefForComplexComponent);
})(),
),
),
@@ -241,22 +248,24 @@ final RefDemoContainer = uiFunction(
(RefDemoHoc()..demoTitle = '`forwardRef` with class component')(
(LogProps()
..builder = FancyButton
+ ..lastClickedButton = lastClickedRef.value
..id = 'forwardRef-component'
..className = 'btn btn-primary'
..ref = fancyButtonNodeRef
..onClick = (_) {
- print(fancyButtonNodeRef.current.outerHtml);
+ printButtonOuterHtml(fancyButtonNodeRef);
lastClickedRef.set(fancyButtonNodeRef);
})(),
),
(RefDemoHoc()..demoTitle = '`uiForwardRef` with function component')(
(LogsPropsFunctionComponent()
..builder = FancyButton
+ ..lastClickedButton = lastClickedRef.value
..id = 'forwardRef-function-component'
..className = 'btn btn-success'
..ref = fancyFunctionalButtonNodeRef
..onClick = (_) {
- print(fancyFunctionalButtonNodeRef.current.outerHtml);
+ printButtonOuterHtml(fancyFunctionalButtonNodeRef);
lastClickedRef.set(fancyFunctionalButtonNodeRef);
})(),
),
@@ -266,6 +275,10 @@ final RefDemoContainer = uiFunction(
$RefDemoContainerConfig, // ignore: undefined_identifier
);
+void printButtonOuterHtml(Ref buttonRef) {
+ print('this button outerHTML: ${buttonRef.current.outerHtml}');
+}
+
mixin RefDemoSectionProps on UiProps {
String sectionTitle;
}
diff --git a/web/component2/src/demos/forward_ref.over_react.g.dart b/web/component2/src/demos/ref.over_react.g.dart
similarity index 95%
rename from web/component2/src/demos/forward_ref.over_react.g.dart
rename to web/component2/src/demos/ref.over_react.g.dart
index 60f4c252e..4b7083266 100644
--- a/web/component2/src/demos/forward_ref.over_react.g.dart
+++ b/web/component2/src/demos/ref.over_react.g.dart
@@ -1,7 +1,7 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: deprecated_member_use_from_same_package, unnecessary_null_in_if_null_operators, prefer_null_aware_operators
-part of 'forward_ref.dart';
+part of 'ref.dart';
// **************************************************************************
// OverReactBuilder (package:over_react/src/builder.dart)
@@ -159,18 +159,35 @@ mixin $UiForwardRefLogsFunctionComponentProps
@override
set builder(BuilderOnlyUiFactory value) =>
props[_$key__builder__UiForwardRefLogsFunctionComponentProps] = value;
+ @override
+ Ref get lastClickedButton =>
+ props[_$key__lastClickedButton__UiForwardRefLogsFunctionComponentProps] ??
+ null; // Add ` ?? null` to workaround DDC bug: ;
+ @override
+ set lastClickedButton(Ref value) =>
+ props[_$key__lastClickedButton__UiForwardRefLogsFunctionComponentProps] =
+ value;
/* GENERATED CONSTANTS */
static const PropDescriptor
_$prop__builder__UiForwardRefLogsFunctionComponentProps =
PropDescriptor(_$key__builder__UiForwardRefLogsFunctionComponentProps);
+ static const PropDescriptor
+ _$prop__lastClickedButton__UiForwardRefLogsFunctionComponentProps =
+ PropDescriptor(
+ _$key__lastClickedButton__UiForwardRefLogsFunctionComponentProps);
static const String _$key__builder__UiForwardRefLogsFunctionComponentProps =
'UiForwardRefLogsFunctionComponentProps.builder';
+ static const String
+ _$key__lastClickedButton__UiForwardRefLogsFunctionComponentProps =
+ 'UiForwardRefLogsFunctionComponentProps.lastClickedButton';
static const List $props = [
- _$prop__builder__UiForwardRefLogsFunctionComponentProps
+ _$prop__builder__UiForwardRefLogsFunctionComponentProps,
+ _$prop__lastClickedButton__UiForwardRefLogsFunctionComponentProps
];
static const List $propKeys = [
- _$key__builder__UiForwardRefLogsFunctionComponentProps
+ _$key__builder__UiForwardRefLogsFunctionComponentProps,
+ _$key__lastClickedButton__UiForwardRefLogsFunctionComponentProps
];
}
@@ -280,12 +297,12 @@ mixin $LogPropsProps on LogPropsProps {
set builder(BuilderOnlyUiFactory value) =>
props[_$key__builder__LogPropsProps] = value;
@override
- bool get thisWasClickedLast =>
- props[_$key__thisWasClickedLast__LogPropsProps] ??
+ Ref get lastClickedButton =>
+ props[_$key__lastClickedButton__LogPropsProps] ??
null; // Add ` ?? null` to workaround DDC bug: ;
@override
- set thisWasClickedLast(bool value) =>
- props[_$key__thisWasClickedLast__LogPropsProps] = value;
+ set lastClickedButton(Ref value) =>
+ props[_$key__lastClickedButton__LogPropsProps] = value;
@override
Ref get _forwardedRef =>
props[_$key___forwardedRef__LogPropsProps] ??
@@ -296,24 +313,24 @@ mixin $LogPropsProps on LogPropsProps {
/* GENERATED CONSTANTS */
static const PropDescriptor _$prop__builder__LogPropsProps =
PropDescriptor(_$key__builder__LogPropsProps);
- static const PropDescriptor _$prop__thisWasClickedLast__LogPropsProps =
- PropDescriptor(_$key__thisWasClickedLast__LogPropsProps);
+ static const PropDescriptor _$prop__lastClickedButton__LogPropsProps =
+ PropDescriptor(_$key__lastClickedButton__LogPropsProps);
static const PropDescriptor _$prop___forwardedRef__LogPropsProps =
PropDescriptor(_$key___forwardedRef__LogPropsProps);
static const String _$key__builder__LogPropsProps = 'LogPropsProps.builder';
- static const String _$key__thisWasClickedLast__LogPropsProps =
- 'LogPropsProps.thisWasClickedLast';
+ static const String _$key__lastClickedButton__LogPropsProps =
+ 'LogPropsProps.lastClickedButton';
static const String _$key___forwardedRef__LogPropsProps =
'LogPropsProps._forwardedRef';
static const List $props = [
_$prop__builder__LogPropsProps,
- _$prop__thisWasClickedLast__LogPropsProps,
+ _$prop__lastClickedButton__LogPropsProps,
_$prop___forwardedRef__LogPropsProps
];
static const List $propKeys = [
_$key__builder__LogPropsProps,
- _$key__thisWasClickedLast__LogPropsProps,
+ _$key__lastClickedButton__LogPropsProps,
_$key___forwardedRef__LogPropsProps
];
}
@@ -588,8 +605,8 @@ final UiFactoryConfig<_$$UiForwardRefLogsPropsComplexComponentProps>
' Do not reference it in your code, as it may change at any time.')
abstract class _$$UiForwardRefLogsPropsComplexComponentProps extends UiProps
with
- UiForwardRefLogsPropsComplexFunctionComponentPropsMixin,
- $UiForwardRefLogsPropsComplexFunctionComponentPropsMixin, // If this generated mixin is undefined, it's likely because UiForwardRefLogsPropsComplexFunctionComponentPropsMixin is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of UiForwardRefLogsPropsComplexFunctionComponentPropsMixin.
+ UiForwardRefLogsPropsComplexComponentPropsMixin,
+ $UiForwardRefLogsPropsComplexComponentPropsMixin, // If this generated mixin is undefined, it's likely because UiForwardRefLogsPropsComplexComponentPropsMixin is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of UiForwardRefLogsPropsComplexComponentPropsMixin.
LogPropsProps,
$LogPropsProps // If this generated mixin is undefined, it's likely because LogPropsProps is not a valid `mixin`-based props mixin, or because it is but the generated mixin was not exported. Check the declaration of LogPropsProps.
implements
From 378a58d34b261a401c7961f32542a5d44f52cf63 Mon Sep 17 00:00:00 2001
From: Joe Bingham
Date: Wed, 5 Aug 2020 08:54:18 -0700
Subject: [PATCH 11/28] Fix CI
---
lib/src/component/ref_util.dart | 37 ++++++++-----------
test/over_react/component/ref_util_test.dart | 8 ++--
test/vm_tests/builder/codegen_test.dart | 2 +-
.../builder/declaration_parsing_test.dart | 2 +-
4 files changed, 22 insertions(+), 27 deletions(-)
diff --git a/lib/src/component/ref_util.dart b/lib/src/component/ref_util.dart
index 6092e1170..6d22c268b 100644
--- a/lib/src/component/ref_util.dart
+++ b/lib/src/component/ref_util.dart
@@ -177,11 +177,11 @@ Ref createRef() {
///
/// Learn more: .
UiFactory Function(UiFactory) forwardRef(
- Function(TProps props, Ref ref) wrapperFunction, {String displayName}) {
-
+ Function(TProps props, Ref ref) wrapperFunction,
+ {String displayName}) {
UiFactory wrapWithForwardRef(UiFactory factory) {
enforceMinimumComponentVersionFor(factory().componentFactory);
-
+
if (displayName == null) {
final componentFactoryType = factory().componentFactory.type;
if (componentFactoryType is String) {
@@ -197,10 +197,11 @@ UiFactory Function(UiFactory]