diff --git a/lib/react_dom.dart b/lib/react_dom.dart index 7b319546f..b2e85173e 100644 --- a/lib/react_dom.dart +++ b/lib/react_dom.dart @@ -44,7 +44,7 @@ import 'package:react/react_dom.dart' as react_dom show render, unmountComponent /// Use [unmountComponentAtNode] to unmount the instance. /// /// > Proxies [react_dom.render]. -dynamic render(/*ReactNode*/ dynamic element, Element mountNode) { +dynamic render(ReactNode element, Element mountNode) { return react_dom.render(element, mountNode); } diff --git a/lib/src/component/_deprecated/error_boundary_mixins.dart b/lib/src/component/_deprecated/error_boundary_mixins.dart index f245e7be9..966dd1777 100644 --- a/lib/src/component/_deprecated/error_boundary_mixins.dart +++ b/lib/src/component/_deprecated/error_boundary_mixins.dart @@ -102,7 +102,7 @@ abstract class _$ErrorBoundaryPropsMixin implements UiProps { /// component tree that crashed. /// /// > Related: [onComponentIsUnrecoverable], [onComponentDidCatch] - ReactElement Function(/*Error||Exception*/dynamic error, ReactErrorInfo? info)? fallbackUIRenderer; + ReactNode Function(/*Error||Exception*/dynamic error, ReactErrorInfo? info)? fallbackUIRenderer; /// The amount of time that is "acceptable" between consecutive identical errors thrown from a component /// within the tree wrapped by this [ErrorBoundary]. @@ -361,7 +361,7 @@ mixin ErrorBoundaryMixin @override - ReactElement Function(dynamic error, ReactErrorInfo? info)? + ReactNode Function(dynamic error, ReactErrorInfo? info)? get fallbackUIRenderer => (props[_$key__fallbackUIRenderer___$ErrorBoundaryPropsMixin] ?? null) - as ReactElement Function(dynamic error, ReactErrorInfo? info)?; + as ReactNode Function(dynamic error, ReactErrorInfo? info)?; /// A renderer that will be used to render "fallback" UI instead of the child /// component tree that crashed. @@ -148,7 +148,7 @@ abstract class ErrorBoundaryPropsMixin implements _$ErrorBoundaryPropsMixin { /// @override set fallbackUIRenderer( - ReactElement Function(dynamic error, ReactErrorInfo? info)? value) => + ReactNode Function(dynamic error, ReactErrorInfo? info)? value) => props[_$key__fallbackUIRenderer___$ErrorBoundaryPropsMixin] = value; /// The amount of time that is "acceptable" between consecutive identical errors thrown from a component diff --git a/lib/src/component/error_boundary.dart b/lib/src/component/error_boundary.dart index f0763b6f7..054033b76 100644 --- a/lib/src/component/error_boundary.dart +++ b/lib/src/component/error_boundary.dart @@ -73,7 +73,7 @@ mixin ErrorBoundaryProps on UiProps { /// component tree that crashed. /// /// > Related: [onComponentIsUnrecoverable], [onComponentDidCatch] - ReactElement? Function(/*Error||Exception*/dynamic error, ReactErrorInfo? info)? fallbackUIRenderer; + ReactNode Function(/*Error||Exception*/dynamic error, ReactErrorInfo? info)? fallbackUIRenderer; /// The amount of time that is "acceptable" between consecutive identical errors thrown from a component /// within the tree wrapped by this [ErrorBoundary]. diff --git a/lib/src/component/error_boundary.over_react.g.dart b/lib/src/component/error_boundary.over_react.g.dart index eaa0b84b2..239f9820e 100644 --- a/lib/src/component/error_boundary.over_react.g.dart +++ b/lib/src/component/error_boundary.over_react.g.dart @@ -280,13 +280,13 @@ mixin $ErrorBoundaryProps on ErrorBoundaryProps { Function(dynamic error, ReactErrorInfo info)? value) => props[_$key__onComponentIsUnrecoverable__ErrorBoundaryProps] = value; @override - ReactElement? Function(dynamic error, ReactErrorInfo? info)? + ReactNode Function(dynamic error, ReactErrorInfo? info)? get fallbackUIRenderer => (props[_$key__fallbackUIRenderer__ErrorBoundaryProps] ?? null) - as ReactElement? Function(dynamic error, ReactErrorInfo? info)?; + as ReactNode Function(dynamic error, ReactErrorInfo? info)?; @override set fallbackUIRenderer( - ReactElement? Function(dynamic error, ReactErrorInfo? info)? value) => + ReactNode Function(dynamic error, ReactErrorInfo? info)? value) => props[_$key__fallbackUIRenderer__ErrorBoundaryProps] = value; @override Duration? get identicalErrorFrequencyTolerance => diff --git a/lib/src/component/error_boundary_recoverable.dart b/lib/src/component/error_boundary_recoverable.dart index a7ea02c5c..b354b9a5b 100644 --- a/lib/src/component/error_boundary_recoverable.dart +++ b/lib/src/component/error_boundary_recoverable.dart @@ -189,7 +189,7 @@ class RecoverableErrorBoundaryComponent? get children { + List? get children { final value = _raw$ReactProps$children; // Most common case; Dart components should all have List children @@ -68,7 +68,7 @@ abstract class _$ReactPropsMixin { return [value]; } - set children(List? value) => _raw$ReactProps$children = value; + set children(List? value) => _raw$ReactProps$children = value; /// A String that differentiates a component from its siblings. /// diff --git a/lib/src/component/prop_mixins.over_react.g.dart b/lib/src/component/prop_mixins.over_react.g.dart index 11b10b033..cce80be3e 100644 --- a/lib/src/component/prop_mixins.over_react.g.dart +++ b/lib/src/component/prop_mixins.over_react.g.dart @@ -13,7 +13,7 @@ abstract class ReactPropsMixin implements _$ReactPropsMixin { static const PropsMeta meta = _$metaForReactPropsMixin; @override - List? get children { + List? get children { final value = _raw$ReactProps$children; if (value is List) return value; if (value == null) { @@ -23,7 +23,7 @@ abstract class ReactPropsMixin implements _$ReactPropsMixin { } @override - set children(List? value) => _raw$ReactProps$children = value; + set children(List? value) => _raw$ReactProps$children = value; @override String? get key => props['key'] as String?; @override @@ -33,14 +33,14 @@ abstract class ReactPropsMixin implements _$ReactPropsMixin { /// @override @Accessor(key: 'children') - dynamic get _raw$ReactProps$children => + ReactNode get _raw$ReactProps$children => (props[_$key___raw$ReactProps$children___$ReactPropsMixin] ?? null) - as dynamic; + as ReactNode; /// @override @Accessor(key: 'children') - set _raw$ReactProps$children(dynamic value) => + set _raw$ReactProps$children(ReactNode value) => props[_$key___raw$ReactProps$children___$ReactPropsMixin] = value; /// Either a String used to retrieve the element at a later time via [react.Component.ref], diff --git a/lib/src/component/ref_util.dart b/lib/src/component/ref_util.dart index c8368ba91..5c4a1f632 100644 --- a/lib/src/component/ref_util.dart +++ b/lib/src/component/ref_util.dart @@ -212,7 +212,7 @@ Ref createRef() => react_interop.createRef(); /// _$Foo2Config, // ignore: undefined_identifier /// ); UiFactory uiForwardRef( - dynamic Function(TProps props, dynamic ref) functionComponent, dynamic _config) { + ReactNode Function(TProps props, dynamic ref) functionComponent, dynamic _config) { ArgumentError.checkNotNull(_config, '_config'); if (_config is! UiFactoryConfig) { @@ -231,7 +231,7 @@ UiFactory uiForwardRef( // this will be an empty string. final displayName = config.displayName ?? getFunctionName(functionComponent); - dynamic _uiFunctionWrapper(JsBackedMap props, dynamic ref) { + ReactNode _uiFunctionWrapper(JsBackedMap props, dynamic ref) { return functionComponent(propsFactory!.jsMap(props), ref); } diff --git a/lib/src/component/suspense_component.dart b/lib/src/component/suspense_component.dart index 08819958a..04b8eed42 100644 --- a/lib/src/component/suspense_component.dart +++ b/lib/src/component/suspense_component.dart @@ -67,11 +67,11 @@ mixin SuspensePropsMixin on UiProps { /// The actual UI you intend to render. If children suspends while rendering, the Suspense boundary will /// switch to rendering fallback. @override - /*ReactNode*/ List? get children; + List? get children; /// An alternate UI to render in place of the actual UI if it has not finished loading. Any valid React node is /// accepted, though in practice, a fallback is a lightweight placeholder view, such as a loading spinner or skeleton. /// Suspense will automatically switch to fallback when children suspends, and back to children when the data is ready. /// If fallback suspends while rendering, it will activate the closest parent Suspense boundary. - /*ReactNode*/ dynamic fallback; + ReactNode fallback; } diff --git a/lib/src/component/suspense_component.over_react.g.dart b/lib/src/component/suspense_component.over_react.g.dart index f84f72d45..a870e3998 100644 --- a/lib/src/component/suspense_component.over_react.g.dart +++ b/lib/src/component/suspense_component.over_react.g.dart @@ -14,10 +14,10 @@ part of 'suspense_component.dart'; mixin $SuspensePropsMixin on SuspensePropsMixin { static const PropsMeta meta = _$metaForSuspensePropsMixin; @override - dynamic get fallback => - (props[_$key__fallback__SuspensePropsMixin] ?? null) as dynamic; + ReactNode get fallback => + (props[_$key__fallback__SuspensePropsMixin] ?? null) as ReactNode; @override - set fallback(dynamic value) => + set fallback(ReactNode value) => props[_$key__fallback__SuspensePropsMixin] = value; /* GENERATED CONSTANTS */ static const PropDescriptor _$prop__fallback__SuspensePropsMixin = diff --git a/lib/src/component/with_transition.dart b/lib/src/component/with_transition.dart index d24e43236..ab5cc8269 100644 --- a/lib/src/component/with_transition.dart +++ b/lib/src/component/with_transition.dart @@ -264,6 +264,8 @@ class WithTransitionComponent extends UiStatefulComponent2. // TODO: right now only top level factory declarations will generate props configs. UiFactory uiFunction( - dynamic Function(TProps props) functionComponent, + ReactNode Function(TProps props) functionComponent, dynamic _config, ) { ArgumentError.checkNotNull(_config, '_config'); diff --git a/lib/src/over_react_redux/redux_multi_provider.dart b/lib/src/over_react_redux/redux_multi_provider.dart index f3b7c7e0c..cdd4f3a7a 100644 --- a/lib/src/over_react_redux/redux_multi_provider.dart +++ b/lib/src/over_react_redux/redux_multi_provider.dart @@ -77,7 +77,7 @@ class ReduxMultiProviderComponent @override render() { - dynamic content = props.children; + ReactNode content = props.children; props.storesByContext.forEach((context, store) { content = (ReduxProvider() ..store = store diff --git a/lib/src/util/context.dart b/lib/src/util/context.dart index 4f5e37c34..d3af597c2 100644 --- a/lib/src/util/context.dart +++ b/lib/src/util/context.dart @@ -13,6 +13,7 @@ // limitations under the License. import 'package:meta/meta.dart'; +import 'package:over_react/over_react.dart'; import 'package:over_react/src/component_declaration/builder_helpers.dart'; import 'package:over_react/src/util/prop_key_util.dart'; diff --git a/lib/src/util/react_util.dart b/lib/src/util/react_util.dart index 46d9d2c97..de85cf0ef 100644 --- a/lib/src/util/react_util.dart +++ b/lib/src/util/react_util.dart @@ -105,7 +105,7 @@ abstract class UiPropsMapView extends UiProps { Map get componentDefaultProps => throw UnimplementedError('@PropsMixin instances do not implement defaultProps'); @override - ReactElement build([dynamic children]) => + ReactElement build([ReactNode children]) => throw UnimplementedError('@PropsMixin instances do not implement build'); @override diff --git a/lib/src/util/react_wrappers.dart b/lib/src/util/react_wrappers.dart index 1c7dbad85..705ba23ba 100644 --- a/lib/src/util/react_wrappers.dart +++ b/lib/src/util/react_wrappers.dart @@ -195,7 +195,7 @@ Map getProps(dynamic/* ReactElement|ReactComponent */ instance, {bool traverseWr /// /// This method simply wraps react.findDOMNode with strong typing for the return value /// (and for the function itself, which is declared using `var` in react-dart). -Element? findDomNode(dynamic instance) => react_dom.findDOMNode(instance) as Element?; +Element? findDomNode(ReactNode instance) => react_dom.findDOMNode(instance) as Element?; /// Returns a portal that renders [children] into a [container]. /// @@ -204,7 +204,7 @@ Element? findDomNode(dynamic instance) => react_dom.findDOMNode(instance) as Ele /// [children] can be any renderable React child, such as a [ReactElement], [String], or fragment. /// /// See: -ReactPortal createPortal(dynamic children, Element container) => ReactDom.createPortal(children, container); +ReactPortal createPortal(ReactNode children, Element container) => ReactDom.createPortal(children, container); /// Dart wrapper for React.isValidElement. /// @@ -223,7 +223,7 @@ bool isDomElement(dynamic instance) { /// Returns whether [instance] is a composite [ReactComponent]. /// /// __Not for external use.__ -bool _isCompositeComponent(Object? instance) { +bool _isCompositeComponent(ReactNode instance) { return instance != null && getProperty(instance, 'isReactComponent') != null; } @@ -240,7 +240,7 @@ bool _isCompositeComponent(Object? instance) { /// * Children are likewise copied and potentially overwritten with [newChildren] as expected. /// * For JS components, a JS copy of [newProps] is returned, since React will merge the props without any special handling. /// If these values might contain event handlers -dynamic preparePropsChangeset(ReactElement element, Map? newProps, [Iterable? newChildren]) { +dynamic preparePropsChangeset(ReactElement element, Map? newProps, [ReactNode newChildren]) { final type = element.type; final dartComponentVersion = ReactDartComponentVersion.fromType(type); // ignore: invalid_use_of_protected_member @@ -294,7 +294,7 @@ external ReactElement _cloneElement(element, [props, children]); /// > Unlike React.addons.cloneWithProps, key and ref from the original element will be preserved. /// > There is no special behavior for merging any props (unlike cloneWithProps). /// > See the [v0.13 RC2 blog post](https://facebook.github.io/react/blog/2015/03/03/react-v0.13-rc2.html) for additional details. -ReactElement cloneElement(ReactElement element, [Map? props, Iterable? children]) { +ReactElement cloneElement(ReactElement element, [Map? props, ReactNode children]) { ArgumentError.checkNotNull(element, 'element'); var propsChangeset = preparePropsChangeset(element, props, children); diff --git a/test/mockito.mocks.dart b/test/mockito.mocks.dart index abff00e9d..d839bdb20 100644 --- a/test/mockito.mocks.dart +++ b/test/mockito.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.4.0 from annotations +// Mocks generated by Mockito 5.4.2 from annotations // in over_react/test/mockito.dart. // Do not manually edit this file. @@ -42,16 +42,19 @@ class MockLogger extends _i1.Mock implements _i3.Logger { Invocation.getter(#name), returnValue: '', ) as String); + @override Map get children => (super.noSuchMethod( Invocation.getter(#children), returnValue: {}, ) as Map); + @override String get fullName => (super.noSuchMethod( Invocation.getter(#fullName), returnValue: '', ) as String); + @override _i2.Level get level => (super.noSuchMethod( Invocation.getter(#level), @@ -60,6 +63,7 @@ class MockLogger extends _i1.Mock implements _i3.Logger { Invocation.getter(#level), ), ) as _i2.Level); + @override set level(_i2.Level? value) => super.noSuchMethod( Invocation.setter( @@ -68,11 +72,19 @@ class MockLogger extends _i1.Mock implements _i3.Logger { ), returnValueForMissingStub: null, ); + + @override + _i4.Stream<_i2.Level?> get onLevelChanged => (super.noSuchMethod( + Invocation.getter(#onLevelChanged), + returnValue: _i4.Stream<_i2.Level?>.empty(), + ) as _i4.Stream<_i2.Level?>); + @override _i4.Stream<_i5.LogRecord> get onRecord => (super.noSuchMethod( Invocation.getter(#onRecord), returnValue: _i4.Stream<_i5.LogRecord>.empty(), ) as _i4.Stream<_i5.LogRecord>); + @override void clearListeners() => super.noSuchMethod( Invocation.method( @@ -81,6 +93,7 @@ class MockLogger extends _i1.Mock implements _i3.Logger { ), returnValueForMissingStub: null, ); + @override bool isLoggable(_i2.Level? value) => (super.noSuchMethod( Invocation.method( @@ -89,6 +102,7 @@ class MockLogger extends _i1.Mock implements _i3.Logger { ), returnValue: false, ) as bool); + @override void log( _i2.Level? logLevel, @@ -110,6 +124,7 @@ class MockLogger extends _i1.Mock implements _i3.Logger { ), returnValueForMissingStub: null, ); + @override void finest( Object? message, [ @@ -127,6 +142,7 @@ class MockLogger extends _i1.Mock implements _i3.Logger { ), returnValueForMissingStub: null, ); + @override void finer( Object? message, [ @@ -144,6 +160,7 @@ class MockLogger extends _i1.Mock implements _i3.Logger { ), returnValueForMissingStub: null, ); + @override void fine( Object? message, [ @@ -161,6 +178,7 @@ class MockLogger extends _i1.Mock implements _i3.Logger { ), returnValueForMissingStub: null, ); + @override void config( Object? message, [ @@ -178,6 +196,7 @@ class MockLogger extends _i1.Mock implements _i3.Logger { ), returnValueForMissingStub: null, ); + @override void info( Object? message, [ @@ -195,6 +214,7 @@ class MockLogger extends _i1.Mock implements _i3.Logger { ), returnValueForMissingStub: null, ); + @override void warning( Object? message, [ @@ -212,6 +232,7 @@ class MockLogger extends _i1.Mock implements _i3.Logger { ), returnValueForMissingStub: null, ); + @override void severe( Object? message, [ @@ -229,6 +250,7 @@ class MockLogger extends _i1.Mock implements _i3.Logger { ), returnValueForMissingStub: null, ); + @override void shout( Object? message, [ @@ -257,31 +279,37 @@ class MockMap extends _i1.Mock implements Map { Invocation.getter(#entries), returnValue: >[], ) as Iterable>); + @override Iterable get keys => (super.noSuchMethod( Invocation.getter(#keys), returnValue: [], ) as Iterable); + @override Iterable get values => (super.noSuchMethod( Invocation.getter(#values), returnValue: [], ) as Iterable); + @override int get length => (super.noSuchMethod( Invocation.getter(#length), returnValue: 0, ) as int); + @override bool get isEmpty => (super.noSuchMethod( Invocation.getter(#isEmpty), returnValue: false, ) as bool); + @override bool get isNotEmpty => (super.noSuchMethod( Invocation.getter(#isNotEmpty), returnValue: false, ) as bool); + @override Map cast() => (super.noSuchMethod( Invocation.method( @@ -290,6 +318,7 @@ class MockMap extends _i1.Mock implements Map { ), returnValue: {}, ) as Map); + @override bool containsValue(Object? value) => (super.noSuchMethod( Invocation.method( @@ -298,6 +327,7 @@ class MockMap extends _i1.Mock implements Map { ), returnValue: false, ) as bool); + @override bool containsKey(Object? key) => (super.noSuchMethod( Invocation.method( @@ -306,6 +336,7 @@ class MockMap extends _i1.Mock implements Map { ), returnValue: false, ) as bool); + @override void operator []=( K? key, @@ -321,13 +352,13 @@ class MockMap extends _i1.Mock implements Map { ), returnValueForMissingStub: null, ); + @override Map map( MapEntry Function( - K, - V, - )? - convert) => + K, + V, + )? convert) => (super.noSuchMethod( Invocation.method( #map, @@ -335,6 +366,7 @@ class MockMap extends _i1.Mock implements Map { ), returnValue: {}, ) as Map); + @override void addEntries(Iterable>? newEntries) => super.noSuchMethod( Invocation.method( @@ -343,6 +375,7 @@ class MockMap extends _i1.Mock implements Map { ), returnValueForMissingStub: null, ); + @override V update( K? key, @@ -364,13 +397,13 @@ class MockMap extends _i1.Mock implements Map { ifAbsent: ifAbsent, ), ) as V); + @override void updateAll( V Function( - K, - V, - )? - update) => + K, + V, + )? update) => super.noSuchMethod( Invocation.method( #updateAll, @@ -378,13 +411,13 @@ class MockMap extends _i1.Mock implements Map { ), returnValueForMissingStub: null, ); + @override void removeWhere( bool Function( - K, - V, - )? - test) => + K, + V, + )? test) => super.noSuchMethod( Invocation.method( #removeWhere, @@ -392,6 +425,7 @@ class MockMap extends _i1.Mock implements Map { ), returnValueForMissingStub: null, ); + @override V putIfAbsent( K? key, @@ -410,6 +444,7 @@ class MockMap extends _i1.Mock implements Map { ifAbsent, ), ) as V); + @override void addAll(Map? other) => super.noSuchMethod( Invocation.method( @@ -418,6 +453,7 @@ class MockMap extends _i1.Mock implements Map { ), returnValueForMissingStub: null, ); + @override void clear() => super.noSuchMethod( Invocation.method( @@ -426,13 +462,13 @@ class MockMap extends _i1.Mock implements Map { ), returnValueForMissingStub: null, ); + @override void forEach( void Function( - K, - V, - )? - action) => + K, + V, + )? action) => super.noSuchMethod( Invocation.method( #forEach, diff --git a/test/over_react/component_declaration/non_null_safe_builder_integration_tests/new_boilerplate/function_component_test.dart b/test/over_react/component_declaration/non_null_safe_builder_integration_tests/new_boilerplate/function_component_test.dart index fb6f4594b..dea52eda9 100644 --- a/test/over_react/component_declaration/non_null_safe_builder_integration_tests/new_boilerplate/function_component_test.dart +++ b/test/over_react/component_declaration/non_null_safe_builder_integration_tests/new_boilerplate/function_component_test.dart @@ -143,7 +143,7 @@ main() { GenericUiProps props; setUp(() { - final genericFactory = uiFunction((_) {}, UiFactoryConfig()); + final genericFactory = uiFunction((_) { return null; }, UiFactoryConfig()); final factoryProps = genericFactory(); expect(factoryProps, isA(), reason: 'test setup check'); props = factoryProps as GenericUiProps; diff --git a/test/over_react/util/react_wrappers_test.dart b/test/over_react/util/react_wrappers_test.dart index b7e9e4842..71931811f 100644 --- a/test/over_react/util/react_wrappers_test.dart +++ b/test/over_react/util/react_wrappers_test.dart @@ -641,7 +641,7 @@ main() { var renderedInstance = react_dom.render(testJsComponentFactoryProxy({ 'jsProp': 'js', 'style': testStyle, - }, testChildren), mountNode) as ReactComponent; + }, testChildren), mountNode) as ReactComponent?; expect(getProps(renderedInstance), { 'jsProp': 'js', @@ -652,7 +652,7 @@ main() { renderedInstance = react_dom.render(testJsComponentFactoryProxy({ 'jsProp': 'other js', 'style': testStyle, - }, testChildren), mountNode) as ReactComponent; + }, testChildren), mountNode) as ReactComponent?; expect(getProps(renderedInstance), { 'jsProp': 'other js', @@ -833,7 +833,7 @@ main() { 'jsProp': 'js', 'style': testStyle, }, testChildren) - ), mountNode) as ReactComponent; + ), mountNode) as ReactComponent?; expect(getProps(renderedInstance, traverseWrappers: true), { 'jsProp': 'js', @@ -846,7 +846,7 @@ main() { 'jsProp': 'other js', 'style': testStyle, }, testChildren) - ), mountNode) as ReactComponent; + ), mountNode) as ReactComponent?; expect(getProps(renderedInstance, traverseWrappers: true), { 'jsProp': 'other js',