From e452d16854dc9f285be9b8c2f04a777ac9e82a44 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 14:58:30 -0700 Subject: [PATCH 01/31] Upgrade lints to workiva_analysis_options v2.recommended --- analysis_options.yaml | 21 ++++++++++++++------- pubspec.yaml | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 6da2c16d..b53d84ad 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,12 +1,19 @@ +include: package:workiva_analysis_options/v2.recommended.yaml + analyzer: strong-mode: + # TODO change to false as part of the null safety major, which avoids us having to add a lot more casts implicit-casts: true - implicit-dynamic: true + errors: + must_call_super: error + comment_references: info + # This is too noisy since it warns for all lifecycle methods. + always_declare_return_types: ignore + # The following are ignored to avoid merge conflicts with null safety branch + directives_ordering: ignore + prefer_typing_uninitialized_variables: ignore linter: rules: - - avoid_private_typedef_functions - - await_only_futures - - cancel_subscriptions - - close_sinks - - unawaited_futures - - avoid_init_to_null + prefer_if_elements_to_conditional_expressions: false + overridden_fields: false + type_annotate_public_apis: false diff --git a/pubspec.yaml b/pubspec.yaml index 311d15ef..c62f298f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,3 +16,4 @@ dev_dependencies: matcher: ^0.12.11 mockito: ^5.3.1 test: ^1.17.12 + workiva_analysis_options: ^1.3.0 From 1446d0bfb4bf0bd09a872780b650645f14d1d009 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 15:04:22 -0700 Subject: [PATCH 02/31] dart fix --apply --code=unnecessary_new --- example/geocodes/geocodes.dart | 16 ++--- example/js_components/js_components.dart | 24 +++---- example/test/call_and_nosuchmethod_test.dart | 2 +- example/test/false_and_null_test.dart | 2 +- example/test/get_dom_node_test.dart | 4 +- example/test/order_test.dart | 4 +- example/test/react_test_components.dart | 48 ++++++------- example/test/ref_test.dart | 4 +- example/test/speed_test.dart | 10 +-- example/test/unmount_test.dart | 2 +- lib/react.dart | 18 ++--- lib/react_client/bridge.dart | 6 +- lib/react_client/component_factory.dart | 14 ++-- lib/react_client/js_backed_map.dart | 8 +-- lib/react_client/js_interop_helpers.dart | 2 +- lib/react_client/react_interop.dart | 2 +- lib/src/context.dart | 4 +- lib/src/ddc_emulated_function_name_bug.dart | 2 +- .../react_client/component_registration.dart | 14 ++-- .../react_client/dart_interop_statics.dart | 28 ++++---- lib/src/react_client/private_utils.dart | 10 +-- .../react_client/synthetic_data_transfer.dart | 2 +- test/factory/common_factory_tests.dart | 16 ++--- test/factory/dart_factory_test.dart | 4 +- test/factory/js_factory_test.dart | 4 +- test/js_builds/shared_tests.dart | 2 +- test/lifecycle_test.dart | 72 +++++++++---------- test/lifecycle_test/component.dart | 28 ++++---- test/lifecycle_test/component2.dart | 42 +++++------ test/lifecycle_test/util.dart | 4 +- test/react_client/bridge_test.dart | 8 +-- test/react_client/js_backed_map_test.dart | 8 +-- .../react_client/js_interop_helpers_test.dart | 2 +- test/react_client/react_interop_test.dart | 6 +- test/react_client_test.dart | 8 +-- test/react_component_test.dart | 2 +- test/react_context_test.dart | 10 +-- test/react_fragment_test.dart | 6 +- test/react_strictmode_test.dart | 2 +- test/react_suspense_test.dart | 6 +- test/shared_type_tester.dart | 18 ++--- test/test_components.dart | 6 +- test/test_components2.dart | 6 +- test/util.dart | 6 +- test/util_test.dart | 4 +- tool/run_consumer_tests.dart | 2 +- 46 files changed, 249 insertions(+), 249 deletions(-) diff --git a/example/geocodes/geocodes.dart b/example/geocodes/geocodes.dart index c035e485..60f4126d 100644 --- a/example/geocodes/geocodes.dart +++ b/example/geocodes/geocodes.dart @@ -48,7 +48,7 @@ class _GeocodesResultItem extends react.Component { /// shortly. /// /// This is the only correct way to create a [Component]. Do not use the constructor! -var geocodesResultItem = react.registerComponent(() => new _GeocodesResultItem()); +var geocodesResultItem = react.registerComponent(() => _GeocodesResultItem()); /// In this component we'll build an HTML `` element full of the `` elements generated by /// [_GeocodesResultItem] @@ -95,7 +95,7 @@ class _GeocodesResultList extends react.Component { } } -var geocodesResultList = react.registerComponent(() => new _GeocodesResultList()); +var geocodesResultList = react.registerComponent(() => _GeocodesResultList()); /// In this [Component] we'll build a search form. /// @@ -167,7 +167,7 @@ class _GeocodesForm extends react.Component { } } -var geocodesForm = react.registerComponent(() => new _GeocodesForm()); +var geocodesForm = react.registerComponent(() => _GeocodesForm()); /// Renders an HTML `
  • ` to be used as a child within the [_GeocodesHistoryList]. class _GeocodesHistoryItem extends react.Component { @@ -189,7 +189,7 @@ class _GeocodesHistoryItem extends react.Component { } } -var geocodesHistoryItem = react.registerComponent(() => new _GeocodesHistoryItem()); +var geocodesHistoryItem = react.registerComponent(() => _GeocodesHistoryItem()); /// Renders the "history list" /// @@ -203,7 +203,7 @@ class _GeocodesHistoryList extends react.Component { { 'key': 'list', }, - new List.from(props['data'].keys.map((key) => geocodesHistoryItem({ + List.from(props['data'].keys.map((key) => geocodesHistoryItem({ 'key': key, 'query': props['data'][key]['query'], 'status': props['data'][key]['status'], @@ -214,7 +214,7 @@ class _GeocodesHistoryList extends react.Component { } } -var geocodesHistoryList = react.registerComponent(() => new _GeocodesHistoryList()); +var geocodesHistoryList = react.registerComponent(() => _GeocodesHistoryList()); /// The root [Component] of our application. /// @@ -257,7 +257,7 @@ class _GeocodesApp extends react.Component { // Send the request var raw = await HttpRequest.getString(path); // Delay the answer 2 more seconds, for test purposes - await new Future.delayed(new Duration(seconds: 2)); + await Future.delayed(Duration(seconds: 2)); // Is this the answer to the last request? if (id == last_id) { // If yes, query was `OK` and `shown_addresses` are replaced @@ -324,7 +324,7 @@ class _GeocodesApp extends react.Component { } } -var geocodesApp = react.registerComponent(() => new _GeocodesApp()); +var geocodesApp = react.registerComponent(() => _GeocodesApp()); /// And finally, a few magic commands to wire it all up! /// diff --git a/example/js_components/js_components.dart b/example/js_components/js_components.dart index b66e760b..03c9ba9e 100644 --- a/example/js_components/js_components.dart +++ b/example/js_components/js_components.dart @@ -15,7 +15,7 @@ main() { react_dom.render(content, querySelector('#content')); } -var IndexComponent = react.registerComponent2(() => new _IndexComponent()); +var IndexComponent = react.registerComponent2(() => _IndexComponent()); class _IndexComponent extends react.Component2 { SimpleCustomComponent simpleRef; @@ -98,7 +98,7 @@ external ReactClass get _SimpleCustomComponent; /// /// This converts the Dart props [Map] passed into it in the /// the same way props are converted for DOM components. -final SimpleCustom = new ReactJsComponentFactoryProxy(_SimpleCustomComponent); +final SimpleCustom = ReactJsComponentFactoryProxy(_SimpleCustomComponent); /// JS interop wrapper class for the component, /// allowing us to interact with component instances @@ -131,13 +131,13 @@ class MaterialUI { external Map get theme; // All the Material UI components converted to dart Components -final Button = new ReactJsComponentFactoryProxy(MaterialUI.Button); -final CssBaseline = new ReactJsComponentFactoryProxy(MaterialUI.CssBaseline); -final Dialog = new ReactJsComponentFactoryProxy(MaterialUI.Dialog); -final DialogActions = new ReactJsComponentFactoryProxy(MaterialUI.DialogActions); -final DialogContent = new ReactJsComponentFactoryProxy(MaterialUI.DialogContent); -final DialogContentText = new ReactJsComponentFactoryProxy(MaterialUI.DialogContentText); -final DialogTitle = new ReactJsComponentFactoryProxy(MaterialUI.DialogTitle); -final Icon = new ReactJsComponentFactoryProxy(MaterialUI.Icon); -final MuiThemeProvider = new ReactJsComponentFactoryProxy(MaterialUI.MuiThemeProvider); -final Typography = new ReactJsComponentFactoryProxy(MaterialUI.Typography); +final Button = ReactJsComponentFactoryProxy(MaterialUI.Button); +final CssBaseline = ReactJsComponentFactoryProxy(MaterialUI.CssBaseline); +final Dialog = ReactJsComponentFactoryProxy(MaterialUI.Dialog); +final DialogActions = ReactJsComponentFactoryProxy(MaterialUI.DialogActions); +final DialogContent = ReactJsComponentFactoryProxy(MaterialUI.DialogContent); +final DialogContentText = ReactJsComponentFactoryProxy(MaterialUI.DialogContentText); +final DialogTitle = ReactJsComponentFactoryProxy(MaterialUI.DialogTitle); +final Icon = ReactJsComponentFactoryProxy(MaterialUI.Icon); +final MuiThemeProvider = ReactJsComponentFactoryProxy(MaterialUI.MuiThemeProvider); +final Typography = ReactJsComponentFactoryProxy(MaterialUI.Typography); diff --git a/example/test/call_and_nosuchmethod_test.dart b/example/test/call_and_nosuchmethod_test.dart index 0dcf43af..67d021e9 100644 --- a/example/test/call_and_nosuchmethod_test.dart +++ b/example/test/call_and_nosuchmethod_test.dart @@ -10,7 +10,7 @@ class _CustomComponent extends react.Component { } } -var customComponent = react.registerComponent(() => new _CustomComponent()); +var customComponent = react.registerComponent(() => _CustomComponent()); void main() { react_dom.render( diff --git a/example/test/false_and_null_test.dart b/example/test/false_and_null_test.dart index a73a365d..5aaafd3c 100644 --- a/example/test/false_and_null_test.dart +++ b/example/test/false_and_null_test.dart @@ -14,7 +14,7 @@ class _Component extends react.Component { } } -var component = react.registerComponent(() => new _Component()); +var component = react.registerComponent(() => _Component()); void main() { var content = react.div({}, [ diff --git a/example/test/get_dom_node_test.dart b/example/test/get_dom_node_test.dart index 08f1b587..00030f18 100644 --- a/example/test/get_dom_node_test.dart +++ b/example/test/get_dom_node_test.dart @@ -11,7 +11,7 @@ customAssert(text, condition) { throw (text); } -var ChildComponent = react.registerComponent(() => new _ChildComponent()); +var ChildComponent = react.registerComponent(() => _ChildComponent()); class _ChildComponent extends react.Component { var counter = 0; @@ -31,7 +31,7 @@ class _ChildComponent extends react.Component { ]); } -var simpleComponent = react.registerComponent(() => new SimpleComponent()); +var simpleComponent = react.registerComponent(() => SimpleComponent()); class SimpleComponent extends react.Component { var refToSpan; diff --git a/example/test/order_test.dart b/example/test/order_test.dart index a932e552..bdd8bfab 100644 --- a/example/test/order_test.dart +++ b/example/test/order_test.dart @@ -19,7 +19,7 @@ class _Item extends react.Component { } } -var item = react.registerComponent(() => new _Item()); +var item = react.registerComponent(() => _Item()); class _List extends react.Component { var items = ['item1', 'item2', 'item3']; @@ -34,7 +34,7 @@ class _List extends react.Component { } } -var list = react.registerComponent(() => new _List()); +var list = react.registerComponent(() => _List()); void main() { react_dom.render(list({}), querySelector('#content')); diff --git a/example/test/react_test_components.dart b/example/test/react_test_components.dart index 38de31e2..aade6745 100644 --- a/example/test/react_test_components.dart +++ b/example/test/react_test_components.dart @@ -21,7 +21,7 @@ class _HelloComponent extends react.Component2 { } } -var helloComponent = react.registerComponent(() => new _HelloComponent()); +var helloComponent = react.registerComponent(() => _HelloComponent()); class _HelloGreeter extends react.Component { var myInput; @@ -47,7 +47,7 @@ class _HelloGreeter extends react.Component { } } -var helloGreeter = react.registerComponent(() => new _HelloGreeter()); +var helloGreeter = react.registerComponent(() => _HelloGreeter()); class _CheckBoxComponent extends react.Component { getInitialState() => {"checked": false}; @@ -77,7 +77,7 @@ class _CheckBoxComponent extends react.Component { } } -var checkBoxComponent = react.registerComponent(() => new _CheckBoxComponent()); +var checkBoxComponent = react.registerComponent(() => _CheckBoxComponent()); class _ClockComponent extends react.Component { Timer timer; @@ -87,7 +87,7 @@ class _ClockComponent extends react.Component { Map getDefaultProps() => {'refreshRate': 1000}; void componentWillMount() { - timer = new Timer.periodic(new Duration(milliseconds: this.props["refreshRate"]), this.tick); + timer = Timer.periodic(Duration(milliseconds: this.props["refreshRate"]), this.tick); } void componentWillUnmount() { @@ -120,12 +120,12 @@ class _ClockComponent extends react.Component { } } -var clockComponent = react.registerComponent(() => new _ClockComponent()); +var clockComponent = react.registerComponent(() => _ClockComponent()); class _ListComponent extends react.Component { Map getInitialState() { return { - "items": new List.from([0, 1, 2, 3]) + "items": List.from([0, 1, 2, 3]) }; } @@ -144,7 +144,7 @@ class _ListComponent extends react.Component { int iterator = 3; void addItem(event) { - List items = new List.from(state["items"]); + List items = List.from(state["items"]); items.add(++iterator); setState({"items": items}); } @@ -167,7 +167,7 @@ class _ListComponent extends react.Component { } } -var listComponent = react.registerComponent(() => new _ListComponent()); +var listComponent = react.registerComponent(() => _ListComponent()); class _MainComponent extends react.Component { render() { @@ -175,7 +175,7 @@ class _MainComponent extends react.Component { } } -var mainComponent = react.registerComponent(() => new _MainComponent()); +var mainComponent = react.registerComponent(() => _MainComponent()); ///// // REACT OLD CONTEXT COMPONENTS @@ -210,7 +210,7 @@ class _LegacyContextComponent extends react.Component { } } -var legacyContextComponent = react.registerComponent(() => new _LegacyContextComponent()); +var legacyContextComponent = react.registerComponent(() => _LegacyContextComponent()); class _LegacyContextConsumerComponent extends react.Component { @override @@ -229,7 +229,7 @@ class _LegacyContextConsumerComponent extends react.Component { } } -var legacyContextConsumerComponent = react.registerComponent(() => new _LegacyContextConsumerComponent()); +var legacyContextConsumerComponent = react.registerComponent(() => _LegacyContextConsumerComponent()); class _GrandchildLegacyContextConsumerComponent extends react.Component { @override @@ -246,7 +246,7 @@ class _GrandchildLegacyContextConsumerComponent extends react.Component { } var grandchildLegacyContextConsumerComponent = - react.registerComponent(() => new _GrandchildLegacyContextConsumerComponent()); + react.registerComponent(() => _GrandchildLegacyContextConsumerComponent()); //// // REACT NEW CONTEXT COMPONENTS @@ -261,7 +261,7 @@ class _NewContextRefComponent extends react.Component2 { } } -var newContextRefComponent = react.registerComponent(() => new _NewContextRefComponent()); +var newContextRefComponent = react.registerComponent(() => _NewContextRefComponent()); int calculateChangedBits(currentValue, nextValue) { int result = 1 << 1; @@ -342,7 +342,7 @@ class _NewContextProviderComponent extends react.Component2 { } } -var newContextProviderComponent = react.registerComponent(() => new _NewContextProviderComponent()); +var newContextProviderComponent = react.registerComponent(() => _NewContextProviderComponent()); class _NewContextConsumerComponent extends react.Component2 { render() { @@ -359,7 +359,7 @@ class _NewContextConsumerComponent extends react.Component2 { } } -var newContextConsumerComponent = react.registerComponent(() => new _NewContextConsumerComponent()); +var newContextConsumerComponent = react.registerComponent(() => _NewContextConsumerComponent()); class _NewContextConsumerObservedBitsComponent extends react.Component2 { render() { @@ -377,7 +377,7 @@ class _NewContextConsumerObservedBitsComponent extends react.Component2 { } var newContextConsumerObservedBitsComponent = - react.registerComponent(() => new _NewContextConsumerObservedBitsComponent()); + react.registerComponent(() => _NewContextConsumerObservedBitsComponent()); class _NewContextTypeConsumerComponent extends react.Component2 { @override @@ -402,7 +402,7 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot final prevItems = prevState['items']; if (prevItems.isEmpty || prevItems[0] != 3) { return ({ - 'items': new List.from([3, 1, 2, 0]) + 'items': List.from([3, 1, 2, 0]) }); } return null; @@ -425,13 +425,13 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot } void removeItem(event) { - List items = new List.from(state["items"]); + List items = List.from(state["items"]); items.removeAt(items.length - 1); setState({"items": items}); } void addItem(event) { - List items = new List.from(state["items"]); + List items = List.from(state["items"]); items.add(items.length); setState({"items": items}); } @@ -463,13 +463,13 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot } } -var newContextTypeConsumerComponentComponent = react.registerComponent(() => new _NewContextTypeConsumerComponent()); -var component2TestComponent = react.registerComponent(() => new _Component2TestComponent()); +var newContextTypeConsumerComponentComponent = react.registerComponent(() => _NewContextTypeConsumerComponent()); +var component2TestComponent = react.registerComponent(() => _Component2TestComponent()); class _ErrorComponent extends react.Component2 { void componentDidMount() { if (!props["errored"]) { - throw new _CustomException("It broke!", 2); + throw _CustomException("It broke!", 2); } } @@ -481,7 +481,7 @@ class _ErrorComponent extends react.Component2 { } } -var ErrorComponent = react.registerComponent(() => new _ErrorComponent()); +var ErrorComponent = react.registerComponent(() => _ErrorComponent()); class _CustomException implements Exception { int code; @@ -563,4 +563,4 @@ class _Component2ErrorTestComponent extends react.Component2 { } } -var component2ErrorTestComponent = react.registerComponent(() => new _Component2ErrorTestComponent(), ['render']); +var component2ErrorTestComponent = react.registerComponent(() => _Component2ErrorTestComponent(), ['render']); diff --git a/example/test/ref_test.dart b/example/test/ref_test.dart index 690c0832..cf1319be 100644 --- a/example/test/ref_test.dart +++ b/example/test/ref_test.dart @@ -5,7 +5,7 @@ import "package:react/react.dart" as react; import "package:react/react_dom.dart" as react_dom; import "package:react/react_client.dart"; -var ChildComponent = react.registerComponent(() => new _ChildComponent()); +var ChildComponent = react.registerComponent(() => _ChildComponent()); class _ChildComponent extends react.Component { int somevalue = 10; @@ -66,7 +66,7 @@ var ChildComponentForm = react.forwardRef2((props, ref) { ]); }, displayName: 'ChildComponentForm'); -var ParentComponent = react.registerComponent(() => new _ParentComponent()); +var ParentComponent = react.registerComponent(() => _ParentComponent()); class _ParentComponent extends react.Component { // String refs diff --git a/example/test/speed_test.dart b/example/test/speed_test.dart index d887c484..5b41fe1d 100644 --- a/example/test/speed_test.dart +++ b/example/test/speed_test.dart @@ -5,7 +5,7 @@ import "dart:async"; import "package:react/react.dart" as react; import "package:react/react_dom.dart" as react_dom; -Stopwatch stopwatch = new Stopwatch()..start(); +Stopwatch stopwatch = Stopwatch()..start(); timeprint(message) { print("$message ${stopwatch.elapsedMilliseconds}"); stopwatch.reset(); @@ -21,7 +21,7 @@ class _Div extends react.Component { } } -var Div = react.registerComponent(() => new _Div()); +var Div = react.registerComponent(() => _Div()); class _Span extends react.Component { shouldComponentUpdate(nProps, nState) { @@ -33,11 +33,11 @@ class _Span extends react.Component { } } -var Span = react.registerComponent(() => new _Span()); +var Span = react.registerComponent(() => _Span()); class _Hello extends react.Component { componentWillMount() { - new Future.delayed(new Duration(seconds: 5), () { + Future.delayed(Duration(seconds: 5), () { stopwatch.reset(); timeprint('before redraw call'); redraw(); @@ -72,7 +72,7 @@ class _Hello extends react.Component { } } -var Hello = react.registerComponent(() => new _Hello()); +var Hello = react.registerComponent(() => _Hello()); void main() { var data = []; diff --git a/example/test/unmount_test.dart b/example/test/unmount_test.dart index 1cb4b1d5..596891cf 100644 --- a/example/test/unmount_test.dart +++ b/example/test/unmount_test.dart @@ -4,7 +4,7 @@ import "dart:html"; import "package:react/react.dart" as react; import "package:react/react_dom.dart" as react_dom; -var simpleComponent = react.registerComponent(() => new SimpleComponent()); +var simpleComponent = react.registerComponent(() => SimpleComponent()); class SimpleComponent extends react.Component { componentWillMount() => print("mount"); diff --git a/lib/react.dart b/lib/react.dart index 60b1889f..0119cb74 100644 --- a/lib/react.dart +++ b/lib/react.dart @@ -226,21 +226,21 @@ abstract class Component { /// [context]s typing was loosened from Map to dynamic to support the new context API in [Component2] /// which extends from [Component]. Only "legacy" context APIs are supported in [Component] - which means /// it will still be expected to be a Map. - this.context = new Map.from(context ?? const {}); + this.context = Map.from(context ?? const {}); /// [nextContext]s typing was loosened from Map to dynamic to support the new context API in [Component2] /// which extends from [Component]. Only "legacy" context APIs are supported in [Component] - which means /// it will still be expected to be a Map. - this.nextContext = new Map.from(this.context ?? const {}); + this.nextContext = Map.from(this.context ?? const {}); } _initProps(props) { - this.props = new Map.from(props); + this.props = Map.from(props); this.nextProps = this.props; } initStateInternal() { - this.state = new Map.from(getInitialState()); + this.state = Map.from(getInitialState()); // Call `transferComponentState` to get state also to `_prevState` transferComponentState(); @@ -312,7 +312,7 @@ abstract class Component { if (_nextState != null) { state = _nextState; } - _nextState = new Map.from(state); + _nextState = Map.from(state); } /// Force a call to [render] by calling [setState], which effectively "redraws" the `Component`. @@ -335,7 +335,7 @@ abstract class Component { } else if (newState is StateUpdaterCallback) { _transactionalSetStateCallbacks.add(newState); } else if (newState != null) { - throw new ArgumentError( + throw ArgumentError( 'setState expects its first parameter to either be a Map or a `TransactionalSetStateCallback`.'); } @@ -355,7 +355,7 @@ abstract class Component { /// > Use [setState] instead. @Deprecated('7.0.0') void replaceState(Map newState, [callback()]) { - Map nextState = newState == null ? {} : new Map.from(newState); + Map nextState = newState == null ? {} : Map.from(newState); _nextState = nextState; if (callback != null) _setStateCallbacks.add(callback); @@ -961,7 +961,7 @@ abstract class Component2 implements Component { // ****************************************************************************************************************** UnsupportedError _unsupportedLifecycleError(String memberName) => - new UnsupportedError('Component2 drops support for the lifecycle method $memberName.' + UnsupportedError('Component2 drops support for the lifecycle method $memberName.' ' See doc comment on Component2.$memberName for migration instructions.'); /// Invoked once before the `Component` is mounted. The return value will be used as the initial value of [state]. @@ -1146,7 +1146,7 @@ abstract class Component2 implements Component { // ****************************************************************************************************************** UnsupportedError _unsupportedError(String memberName) => - new UnsupportedError('Component2 drops support for $memberName'); + UnsupportedError('Component2 drops support for $memberName'); /// Do not use. /// diff --git a/lib/react_client/bridge.dart b/lib/react_client/bridge.dart index d434f598..8b626e88 100644 --- a/lib/react_client/bridge.dart +++ b/lib/react_client/bridge.dart @@ -33,7 +33,7 @@ abstract class Component2Bridge { /// /// Protected; use [forComponent] instead. @protected - static final Expando bridgeForComponent = new Expando(); + static final Expando bridgeForComponent = Expando(); const Component2Bridge(); @@ -94,8 +94,8 @@ class Component2BridgeImpl extends Component2Bridge { void setStateWithUpdater(Component2 component, StateUpdaterCallback stateUpdater, SetStateCallback callback) { final firstArg = allowInterop((JsMap jsPrevState, JsMap jsProps, [_]) { final value = stateUpdater( - new JsBackedMap.backedBy(jsPrevState), - new JsBackedMap.backedBy(jsProps), + JsBackedMap.backedBy(jsPrevState), + JsBackedMap.backedBy(jsProps), ); if (value == null) return null; return jsBackingMapOrJsCopy(value); diff --git a/lib/react_client/component_factory.dart b/lib/react_client/component_factory.dart index 584d9700..86572777 100644 --- a/lib/react_client/component_factory.dart +++ b/lib/react_client/component_factory.dart @@ -51,7 +51,7 @@ Map unconvertJsProps(/* ReactElement|ReactComponent */ instance) { // it is a Dart Component. // ignore: deprecated_member_use_from_same_package if (props['internal'] is ReactDartComponentInternal || (props['style'] != null && props['style'] is Map)) { - throw new ArgumentError('A Dart Component cannot be passed into unconvertJsProps.'); + throw ArgumentError('A Dart Component cannot be passed into unconvertJsProps.'); } // Convert the nested style map so it can be read by Dart code. @@ -116,7 +116,7 @@ class ReactDartComponentFactoryProxy extends React // 3. Remove "reserved" props that should not be visible to the rendered component. // [1] - Map extendedProps = (defaultProps != null ? new Map.from(defaultProps) : {}) + Map extendedProps = (defaultProps != null ? Map.from(defaultProps) : {}) // [2] ..addAll(props) ..['children'] = children @@ -124,9 +124,9 @@ class ReactDartComponentFactoryProxy extends React ..remove('key') ..remove('ref'); - var internal = new ReactDartComponentInternal()..props = extendedProps; + var internal = ReactDartComponentInternal()..props = extendedProps; - var interopProps = new InteropProps(internal: internal); + var interopProps = InteropProps(internal: internal); // Don't pass a key into InteropProps if one isn't defined, so that the value will // be `undefined` in the JS, which is ignored by React, whereas `null` isn't. @@ -181,7 +181,7 @@ class ReactDartComponentFactoryProxy2 extends Rea ReactDartComponentFactoryProxy2(ReactClass reactClass) : this.reactClass = reactClass, - this.defaultProps = new JsBackedMap.fromJs(reactClass.defaultProps); + this.defaultProps = JsBackedMap.fromJs(reactClass.defaultProps); @override ReactClass get type => reactClass; @@ -229,7 +229,7 @@ class ReactJsContextComponentFactoryProxy extends ReactJsComponentFactoryProxy { /// Returns a JavaScript version of the specified [props], preprocessed for consumption by ReactJS and prepared for /// consumption by the `react` library internals. JsMap generateExtendedJsProps(Map props) { - JsBackedMap propsForJs = new JsBackedMap.from(props); + JsBackedMap propsForJs = JsBackedMap.from(props); if (isProvider) { propsForJs['value'] = ContextHelpers.jsifyNewContext(propsForJs['value']); @@ -267,7 +267,7 @@ class ReactJsComponentFactoryProxy extends ReactComponentFactoryProxy { }) : this.type = jsClass, this._additionalRefPropKeys = additionalRefPropKeys { if (jsClass == null) { - throw new ArgumentError('`jsClass` must not be null. ' + throw ArgumentError('`jsClass` must not be null. ' 'Ensure that the JS component class you\'re referencing is available and being accessed correctly.'); } } diff --git a/lib/react_client/js_backed_map.dart b/lib/react_client/js_backed_map.dart index 8dd20b22..ff3fbf27 100644 --- a/lib/react_client/js_backed_map.dart +++ b/lib/react_client/js_backed_map.dart @@ -26,16 +26,16 @@ class JsBackedMap extends MapBase { final JsMap jsObject; /// Creates a JsBackedMap instance backed by a new [jsObject]. - JsBackedMap() : jsObject = new JsMap(); + JsBackedMap() : jsObject = JsMap(); /// Creates a JsBackedMap instance backed by [jsObject]. JsBackedMap.backedBy(this.jsObject); /// Creates a JsBackedMap instance that contains all key/value pairs of [other]. - factory JsBackedMap.from(Map other) => new JsBackedMap()..addAll(other); + factory JsBackedMap.from(Map other) => JsBackedMap()..addAll(other); /// Creates a JsBackedMap instance that contains all key/value pairs of the JS object [jsOther]. - factory JsBackedMap.fromJs(JsMap jsOther) => new JsBackedMap()..addAllFromJs(jsOther); + factory JsBackedMap.fromJs(JsMap jsOther) => JsBackedMap()..addAllFromJs(jsOther); // Private helpers with narrower typing than we want to expose, for use in other methods List get _keys => _Object.keys(jsObject); @@ -150,7 +150,7 @@ JsMap jsBackingMapOrJsCopy(Map map) { if (map is JsBackedMap) { return map.jsObject; } else { - return new JsBackedMap.from(map).jsObject; + return JsBackedMap.from(map).jsObject; } } diff --git a/lib/react_client/js_interop_helpers.dart b/lib/react_client/js_interop_helpers.dart index c76d4412..4989c6ca 100644 --- a/lib/react_client/js_interop_helpers.dart +++ b/lib/react_client/js_interop_helpers.dart @@ -83,7 +83,7 @@ int _anonymousJsObjectOrFrozenObjectHashCode(Object _) => 0; /// JavaScript type, and all other objects are proxied. dynamic jsifyAndAllowInterop(object) { if (object is! Map && object is! Iterable) { - throw new ArgumentError.value(object, 'object', 'must be a Map or Iterable'); + throw ArgumentError.value(object, 'object', 'must be a Map or Iterable'); } return _convertDataTree(object); } diff --git a/lib/react_client/react_interop.dart b/lib/react_client/react_interop.dart index 8463749d..4fe6fb69 100644 --- a/lib/react_client/react_interop.dart +++ b/lib/react_client/react_interop.dart @@ -88,7 +88,7 @@ abstract class React { /// /// Learn more: . Ref createRef() { - return new Ref(); + return Ref(); } /// When this is provided as the ref prop, a reference to the rendered component diff --git a/lib/src/context.dart b/lib/src/context.dart index f23102a1..c89fb58d 100644 --- a/lib/src/context.dart +++ b/lib/src/context.dart @@ -114,8 +114,8 @@ Context createContext([ var JSContext = React.createContext(ContextHelpers.jsifyNewContext(defaultValue), calculateChangedBits != null ? allowInterop(jsifyCalculateChangedBitsArgs) : null); return Context( - new ReactJsContextComponentFactoryProxy(JSContext.Provider, isProvider: true), - new ReactJsContextComponentFactoryProxy(JSContext.Consumer, isConsumer: true), + ReactJsContextComponentFactoryProxy(JSContext.Provider, isProvider: true), + ReactJsContextComponentFactoryProxy(JSContext.Consumer, isConsumer: true), JSContext, ); } diff --git a/lib/src/ddc_emulated_function_name_bug.dart b/lib/src/ddc_emulated_function_name_bug.dart index 7b8e1192..ba4df865 100644 --- a/lib/src/ddc_emulated_function_name_bug.dart +++ b/lib/src/ddc_emulated_function_name_bug.dart @@ -29,7 +29,7 @@ class _NsmEmulatedFunctionWithNameProperty implements Function { final bool isBugPresent = (() { const testValue = 'test value'; - var testObject = new _NsmEmulatedFunctionWithNameProperty(); + var testObject = _NsmEmulatedFunctionWithNameProperty(); try { // In the DDC, this throws: diff --git a/lib/src/react_client/component_registration.dart b/lib/src/react_client/component_registration.dart index 498962ac..3e1b9ea4 100644 --- a/lib/src/react_client/component_registration.dart +++ b/lib/src/react_client/component_registration.dart @@ -62,9 +62,9 @@ ReactDartComponentFactoryProxy registerComponent( return registerComponent2(componentFactory, skipMethods: skipMethods); } - var componentStatics = new ComponentStatics(componentFactory); + var componentStatics = ComponentStatics(componentFactory); - var jsConfig = new JsComponentConfig( + var jsConfig = JsComponentConfig( childContextKeys: componentInstance.childContextKeys, contextKeys: componentInstance.contextKeys, ); @@ -86,10 +86,10 @@ ReactDartComponentFactoryProxy registerComponent( // Cache default props and store them on the ReactClass so they can be used // by ReactDartComponentFactoryProxy and externally. - final Map defaultProps = new Map.unmodifiable(componentInstance.getDefaultProps()); + final Map defaultProps = Map.unmodifiable(componentInstance.getDefaultProps()); reactComponentClass.dartDefaultProps = defaultProps; - return new ReactDartComponentFactoryProxy(reactComponentClass); + return ReactDartComponentFactoryProxy(reactComponentClass); } catch (e, stack) { print('Error when registering Component: $e\n$stack'); rethrow; @@ -108,7 +108,7 @@ ReactDartComponentFactoryProxy2 registerComponent2( bridgeFactory ??= Component2BridgeImpl.bridgeFactory; final componentInstance = componentFactory(); - final componentStatics = new ComponentStatics2( + final componentStatics = ComponentStatics2( componentFactory: componentFactory, instanceForStaticMethods: componentInstance, bridgeFactory: bridgeFactory, @@ -139,7 +139,7 @@ ReactDartComponentFactoryProxy2 registerComponent2( rethrow; } - var jsConfig2 = new JsComponentConfig2( + var jsConfig2 = JsComponentConfig2( defaultProps: defaultProps.jsObject, contextType: componentInstance.contextType?.jsThis, skipMethods: filteredSkipMethods, @@ -163,7 +163,7 @@ ReactDartComponentFactoryProxy2 registerComponent2( // ignore: invalid_use_of_protected_member reactComponentClass.dartComponentVersion = ReactDartComponentVersion.component2; - return new ReactDartComponentFactoryProxy2(reactComponentClass); + return ReactDartComponentFactoryProxy2(reactComponentClass); } catch (e, stack) { if (!errorPrinted) print('Error when registering Component2: $e\n$stack'); rethrow; diff --git a/lib/src/react_client/dart_interop_statics.dart b/lib/src/react_client/dart_interop_statics.dart index 0416a2bc..0d68e079 100644 --- a/lib/src/react_client/dart_interop_statics.dart +++ b/lib/src/react_client/dart_interop_statics.dart @@ -65,7 +65,7 @@ final ReactDartInteropStatics dartInteropStatics = (() { Map _getNextProps(Component component, ReactDartComponentInternal nextInternal) { var newProps = nextInternal.props; - return newProps != null ? new Map.from(newProps) : {}; + return newProps != null ? Map.from(newProps) : {}; } /// 1. Update [Component.props] using the value stored to [Component.nextProps] @@ -95,7 +95,7 @@ final ReactDartInteropStatics dartInteropStatics = (() { void _callSetStateTransactionalCallbacks(Component component) { var nextState = component.nextState; - var props = new UnmodifiableMapView(component.props); + var props = UnmodifiableMapView(component.props); component.transactionalSetStateCallbacks.forEach((callback) { final stateUpdates = callback(nextState, props); @@ -181,7 +181,7 @@ final ReactDartInteropStatics dartInteropStatics = (() { return component.render(); }); - return new ReactDartInteropStatics( + return ReactDartInteropStatics( initComponent: allowInterop(initComponent), handleGetChildContext: allowInterop(handleGetChildContext), handleComponentWillMount: allowInterop(handleComponentWillMount), @@ -197,8 +197,8 @@ final ReactDartInteropStatics dartInteropStatics = (() { abstract class ReactDartInteropStatics2 { static void _updatePropsAndStateWithJs(Component2 component, JsMap props, JsMap state) { component - ..props = new JsBackedMap.backedBy(props) - ..state = new JsBackedMap.backedBy(state); + ..props = JsBackedMap.backedBy(props) + ..state = JsBackedMap.backedBy(state); } static void _updateContextWithJs(Component2 component, dynamic jsContext) { @@ -213,12 +213,12 @@ abstract class ReactDartInteropStatics2 { component ..jsThis = jsThis - ..props = new JsBackedMap.backedBy(jsThis.props) + ..props = JsBackedMap.backedBy(jsThis.props) ..context = ContextHelpers.unjsifyNewContext(jsThis.context); jsThis.state = jsBackingMapOrJsCopy(component.initialState); - component.state = new JsBackedMap.backedBy(jsThis.state); + component.state = JsBackedMap.backedBy(jsThis.state); // ignore: invalid_use_of_protected_member Component2Bridge.bridgeForComponent[component] = componentStatics.bridgeFactory(component); @@ -233,8 +233,8 @@ abstract class ReactDartInteropStatics2 { static bool handleShouldComponentUpdate(Component2 component, JsMap jsNextProps, JsMap jsNextState) => // dartfmt componentZone.run(() { final value = component.shouldComponentUpdate( - new JsBackedMap.backedBy(jsNextProps), - new JsBackedMap.backedBy(jsNextState), + JsBackedMap.backedBy(jsNextProps), + JsBackedMap.backedBy(jsNextState), ); if (!value) { @@ -248,7 +248,7 @@ abstract class ReactDartInteropStatics2 { ComponentStatics2 componentStatics, JsMap jsNextProps, JsMap jsPrevState) => // dartfmt componentZone.run(() { var derivedState = componentStatics.instanceForStaticMethods - .getDerivedStateFromProps(new JsBackedMap.backedBy(jsNextProps), new JsBackedMap.backedBy(jsPrevState)); + .getDerivedStateFromProps(JsBackedMap.backedBy(jsNextProps), JsBackedMap.backedBy(jsPrevState)); if (derivedState != null) { return jsBackingMapOrJsCopy(derivedState); } @@ -258,8 +258,8 @@ abstract class ReactDartInteropStatics2 { static dynamic handleGetSnapshotBeforeUpdate(Component2 component, JsMap jsPrevProps, JsMap jsPrevState) => // dartfmt componentZone.run(() { final snapshotValue = component.getSnapshotBeforeUpdate( - new JsBackedMap.backedBy(jsPrevProps), - new JsBackedMap.backedBy(jsPrevState), + JsBackedMap.backedBy(jsPrevProps), + JsBackedMap.backedBy(jsPrevState), ); return snapshotValue; @@ -270,8 +270,8 @@ abstract class ReactDartInteropStatics2 { [dynamic snapshot]) => // dartfmt componentZone.run(() { component.componentDidUpdate( - new JsBackedMap.backedBy(jsPrevProps), - new JsBackedMap.backedBy(jsPrevState), + JsBackedMap.backedBy(jsPrevProps), + JsBackedMap.backedBy(jsPrevState), snapshot, ); }); diff --git a/lib/src/react_client/private_utils.dart b/lib/src/react_client/private_utils.dart index f70e6be6..cc563f26 100644 --- a/lib/src/react_client/private_utils.dart +++ b/lib/src/react_client/private_utils.dart @@ -14,10 +14,10 @@ bool _isJsApiValid = false; @Deprecated('7.0.0') InteropContextValue jsifyContext(Map context) { - var interopContext = new InteropContextValue(); + var interopContext = InteropContextValue(); context.forEach((key, value) { // ignore: argument_type_not_assignable - setProperty(interopContext, key, new ReactDartContextInternal(value)); + setProperty(interopContext, key, ReactDartContextInternal(value)); }); return interopContext; @@ -32,7 +32,7 @@ T validateJsApiThenReturn(T Function() computeReturn) { @Deprecated('7.0.0') Map unjsifyContext(InteropContextValue interopContext) { // TODO consider using `contextKeys` for this if perf of objectKeys is bad. - return new Map.fromIterable(objectKeys(interopContext), value: (key) { + return Map.fromIterable(objectKeys(interopContext), value: (key) { // ignore: argument_type_not_assignable ReactDartContextInternal internal = getProperty(interopContext, key); return internal?.value; @@ -54,9 +54,9 @@ void validateJsApi() { createReactDartComponentClass2(null, null, null); _isJsApiValid = true; } on NoSuchMethodError catch (_) { - throw new Exception('react.js and react_dom.js must be loaded.'); + throw Exception('react.js and react_dom.js must be loaded.'); } catch (_) { - throw new Exception('Loaded react.js must include react-dart JS interop helpers.'); + throw Exception('Loaded react.js must include react-dart JS interop helpers.'); } } diff --git a/lib/src/react_client/synthetic_data_transfer.dart b/lib/src/react_client/synthetic_data_transfer.dart index f2698abc..a0fad614 100644 --- a/lib/src/react_client/synthetic_data_transfer.dart +++ b/lib/src/react_client/synthetic_data_transfer.dart @@ -107,5 +107,5 @@ SyntheticDataTransfer syntheticDataTransferFactory(Object dt) { final files = [...?rawFiles]; final types = [...?rawTypes]; - return new SyntheticDataTransfer(dropEffect, effectAllowed, files, types); + return SyntheticDataTransfer(dropEffect, effectAllowed, files, types); } diff --git a/test/factory/common_factory_tests.dart b/test/factory/common_factory_tests.dart index 68d2b80c..c6b2135d 100644 --- a/test/factory/common_factory_tests.dart +++ b/test/factory/common_factory_tests.dart @@ -66,7 +66,7 @@ void commonFactoryTests(ReactComponentFactoryProxy factory, final childrenCount = i; test('$childrenCount', () { - final expectedChildren = new List.generate(childrenCount, (i) => i + 1); + final expectedChildren = List.generate(childrenCount, (i) => i + 1); final arguments = [props, ...expectedChildren]; final instance = Function.apply(factory, arguments); expect(getChildren(instance), expectedChildren); @@ -77,7 +77,7 @@ void commonFactoryTests(ReactComponentFactoryProxy factory, final instance = factory(props, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40); // Generate these instead of hard coding them to ensure the arguments passed into this test match maxSupportedVariadicChildCount - final expectedChildren = new List.generate(maxSupportedVariadicChildCount, (i) => i + 1); + final expectedChildren = List.generate(maxSupportedVariadicChildCount, (i) => i + 1); expect(getChildren(instance), equals(expectedChildren)); }, tags: 'dart-2-7-dart2js-variadic-issues'); }); @@ -96,12 +96,12 @@ void commonFactoryTests(ReactComponentFactoryProxy factory, }); test('an Iterable', () { - var instance = factory(props, new Iterable.generate(3, (int i) => '$i')); + var instance = factory(props, Iterable.generate(3, (int i) => '$i')); expect(getChildren(instance), equals(['0', '1', '2'])); }); test('an empty Iterable', () { - var instance = factory(props, new Iterable.empty()); + var instance = factory(props, Iterable.empty()); expect(getChildren(instance), equals([])); }); } @@ -352,7 +352,7 @@ void domEventHandlerWrappingTests(ReactComponentFactoryProxy factory) { })); }); - nodeWithClickHandler.dispatchEvent(new MouseEvent('click')); + nodeWithClickHandler.dispatchEvent(MouseEvent('click')); }); }); } @@ -555,7 +555,7 @@ void _childKeyWarningTests(Function factory, {Function(ReactElement Function()) consoleErrorMessage = null; originalConsoleError = context['console']['error']; - context['console']['error'] = new JsFunction.withThis((self, message, arg1, arg2, arg3) { + context['console']['error'] = JsFunction.withThis((self, message, arg1, arg2, arg3) { consoleErrorCalled = true; consoleErrorMessage = message; @@ -603,7 +603,7 @@ class _StringRefOwnerOwnerHelperComponent extends react.Component { /// for string ref tests. ReactComponent _renderWithStringRefSupportingOwner(ReactElement render()) { final factory = - react.registerComponent(() => new _StringRefOwnerOwnerHelperComponent()) as ReactDartComponentFactoryProxy; + react.registerComponent(() => _StringRefOwnerOwnerHelperComponent()) as ReactDartComponentFactoryProxy; return rtu.renderIntoDocument(factory({'render': render})); } @@ -614,7 +614,7 @@ int _nextFactoryId = 0; /// /// This prevents React JS from not printing key warnings it deems as "duplicates". void _renderWithUniqueOwnerName(ReactElement render()) { - final factory = react.registerComponent2(() => new _UniqueOwnerHelperComponent()); + final factory = react.registerComponent2(() => _UniqueOwnerHelperComponent()); factory.reactClass.displayName = 'OwnerHelperComponent_$_nextFactoryId'; _nextFactoryId++; diff --git a/test/factory/dart_factory_test.dart b/test/factory/dart_factory_test.dart index 7cd5d536..ff2707f2 100644 --- a/test/factory/dart_factory_test.dart +++ b/test/factory/dart_factory_test.dart @@ -57,7 +57,7 @@ main() { }); } -final Foo = react.registerComponent(() => new _Foo()) as ReactDartComponentFactoryProxy; +final Foo = react.registerComponent(() => _Foo()) as ReactDartComponentFactoryProxy; class _Foo extends react.Component { @override @@ -67,7 +67,7 @@ class _Foo extends react.Component { } } -final Foo2 = react.registerComponent2(() => new _Foo2()); +final Foo2 = react.registerComponent2(() => _Foo2()); class _Foo2 extends react.Component2 { @override diff --git a/test/factory/js_factory_test.dart b/test/factory/js_factory_test.dart index 1f364a98..76f8eb55 100644 --- a/test/factory/js_factory_test.dart +++ b/test/factory/js_factory_test.dart @@ -66,11 +66,11 @@ main() { @JS() external ReactClass get _JsFoo; -final JsFoo = new ReactJsComponentFactoryProxy(_JsFoo); +final JsFoo = ReactJsComponentFactoryProxy(_JsFoo); @JS() external ReactClass get _JsFooFunction; -final JsFooFunction = new ReactJsComponentFactoryProxy(_JsFooFunction); +final JsFooFunction = ReactJsComponentFactoryProxy(_JsFooFunction); @JS() external bool Function(ReactElement) get hasUndefinedChildren; diff --git a/test/js_builds/shared_tests.dart b/test/js_builds/shared_tests.dart index 4d51e254..d0c2df41 100644 --- a/test/js_builds/shared_tests.dart +++ b/test/js_builds/shared_tests.dart @@ -17,7 +17,7 @@ void verifyJsFileLoaded(String filename) { return Uri.parse((script as ScriptElement).src).pathSegments.last == filename; }); - if (!isLoaded) throw new Exception('$filename is not loaded'); + if (!isLoaded) throw Exception('$filename is not loaded'); } void sharedJsFunctionTests() { diff --git a/test/lifecycle_test.dart b/test/lifecycle_test.dart index 86a0dd9a..53230923 100644 --- a/test/lifecycle_test.dart +++ b/test/lifecycle_test.dart @@ -43,11 +43,11 @@ main() { test('throws when setState is called with something other than a Map or Function that accepts two parameters', () { - var mountNode = new DivElement(); + var mountNode = DivElement(); var renderedInstance = react_dom.render(components.SetStateTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); - expect(() => component.setState(new Map()), returnsNormally); + expect(() => component.setState(Map()), returnsNormally); expect( () => component.setState((_, __) { return {}; @@ -140,10 +140,10 @@ main() { setUp(() { consoleErrorCalled = false; consoleErrorMessage = null; - mountNode = new DivElement(); + mountNode = DivElement(); react_interop.PropTypes.resetWarningCache(); originalConsoleError = context['console']['error']; - context['console']['error'] = new JsFunction.withThis((self, message) { + context['console']['error'] = JsFunction.withThis((self, message) { consoleErrorCalled = true; consoleErrorMessage = message; @@ -187,7 +187,7 @@ main() { contains(expectedWarningPrefix), reason: 'Did the warning message change? This test will break if the format cannot be converted to json.', ); - RegExp regExp = new RegExp(r'.*?({.*}).*', multiLine: true); + RegExp regExp = RegExp(r'.*?({.*}).*', multiLine: true); var matches = regExp.allMatches(consoleErrorMessage); expect(matches, hasLength(1), reason: 'Should have found a json structure in the error.'); var match = matches.elementAt(0); // => extract the first (and only) match @@ -270,7 +270,7 @@ main() { 'children': [] }); - var mountNode = new DivElement(); + var mountNode = DivElement(); var instance = react_dom.render(components2.LifecycleTest(initialProps), mountNode); LifecycleTestHelper component = getDartComponent(instance); @@ -312,7 +312,7 @@ main() { final Map expectedProps = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); - var mountNode = new DivElement(); + var mountNode = DivElement(); var instance = react_dom.render(components2.LifecycleTest(initialProps), mountNode); LifecycleTestHelper component = getDartComponent(instance); @@ -333,7 +333,7 @@ main() { }); test('triggers error lifecycle events when an error is thrown', () { - var mountNode = new DivElement(); + var mountNode = DivElement(); var renderedInstance = react_dom.render(components2.SetStateTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); LifecycleTestHelper.staticLifecycleCalls.clear(); @@ -441,7 +441,7 @@ main() { }); test('error lifecycle methods get passed Dartified Error/Exception when an error is thrown', () { - var mountNode = new DivElement(); + var mountNode = DivElement(); var renderedInstance = react_dom.render(components2.SetStateTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); LifecycleTestHelper.staticLifecycleCalls.clear(); @@ -459,7 +459,7 @@ main() { }); test('can skip methods passed into _registerComponent2', () { - var mountNode = new DivElement(); + var mountNode = DivElement(); var renderedInstance = react_dom.render(components2.SkipMethodsTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); LifecycleTestHelper.staticLifecycleCalls.clear(); @@ -486,7 +486,7 @@ main() { }); test('passes the correct error/info to lifecycle methods when an error is thrown', () { - var mountNode = new DivElement(); + var mountNode = DivElement(); var renderedInstance = react_dom.render(components2.SetStateTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); Element renderedNode = react_dom.findDOMNode(renderedInstance); @@ -505,7 +505,7 @@ main() { }); test('defaults toward not being an error boundary', () { - var mountNode = new DivElement(); + var mountNode = DivElement(); expect(() { var renderedInstance = react_dom.render(components2.DefaultSkipMethodsTest({}), mountNode); @@ -665,7 +665,7 @@ void sharedLifecycleTests({ }); test('receives correct lifecycle calls on component unmount order', () { - var mountNode = new DivElement(); + var mountNode = DivElement(); var instance = react_dom.render(LifecycleTest({}), mountNode); LifecycleTestHelper component = getDartComponent(instance); @@ -682,7 +682,7 @@ void sharedLifecycleTests({ if (!isComponent2) { test('does not call getChildContext when childContextKeys is empty', () { - var mountNode = new DivElement(); + var mountNode = DivElement(); var instance = react_dom.render(ContextWrapperWithoutKeys({'foo': false}, LifecycleTestWithContext({})), mountNode); LifecycleTestHelper component = getDartComponent(instance); @@ -698,7 +698,7 @@ void sharedLifecycleTests({ }); test('calls getChildContext when childContextKeys exist', () { - var mountNode = new DivElement(); + var mountNode = DivElement(); var instance = react_dom.render(ContextWrapper({'foo': false}, LifecycleTestWithContext({})), mountNode); LifecycleTestHelper component = getDartComponent(instance); @@ -741,11 +741,11 @@ void sharedLifecycleTests({ }; // Add the 'ref' prop separately so it isn't an expected prop since React removes it internally - var initialPropsWithRef = new Map.from(initialProps)..addAll(refMap); - var newPropsWithRef = new Map.from(newPropsWithDefaults)..addAll(refMap); + var initialPropsWithRef = Map.from(initialProps)..addAll(refMap); + var newPropsWithRef = Map.from(newPropsWithDefaults)..addAll(refMap); // Render the initial instance - var mountNode = new DivElement(); + var mountNode = DivElement(); react_dom.render(ContextWrapper({'foo': false}, LifecycleTestWithContext(initialPropsWithRef)), mountNode); // Verify initial context/setup @@ -811,12 +811,12 @@ void sharedLifecycleTests({ 'ref': ((ref) => component = ref), }; - var initialProps = new Map.from(defaultProps)..addAll({'children': const []}); + var initialProps = Map.from(defaultProps)..addAll({'children': const []}); // Add the 'ref' prop separately so it isn't an expected prop since React removes it internally - var initialPropsWithRef = new Map.from(initialProps)..addAll(refMap); + var initialPropsWithRef = Map.from(initialProps)..addAll(refMap); // Render the initial instance - var mountNode = new DivElement(); + var mountNode = DivElement(); react_dom.render( ContextWrapper( {'foo': false}, @@ -875,15 +875,15 @@ void sharedLifecycleTests({ 'ref': ((ref) => component = ref), }; - var initialProps = new Map.from(defaultProps) + var initialProps = Map.from(defaultProps) ..addAll(initialContext) ..addAll({'children': const []}); // Add the 'ref' prop separately so it isn't an expected prop since React removes it internally - var initialPropsWithRef = new Map.from(initialProps)..addAll(refMap); + var initialPropsWithRef = Map.from(initialProps)..addAll(refMap); - var expectedProps = new Map.from(initialProps)..addAll(expectedContext); + var expectedProps = Map.from(initialProps)..addAll(expectedContext); // Render the initial instance - var mountNode = new DivElement(); + var mountNode = DivElement(); react_dom.render( ContextWrapper( initialContext, @@ -952,7 +952,7 @@ void sharedLifecycleTests({ final dynamic expectedContext = isComponent2 ? null : const {}; const Null expectedSnapshot = null; - var mountNode = new DivElement(); + var mountNode = DivElement(); var instance = react_dom.render(LifecycleTest(initialProps), mountNode); LifecycleTestHelper component = getDartComponent(instance); @@ -1089,8 +1089,8 @@ void sharedLifecycleTests({ Map stateUpdater(Map prevState, Map props) { calls.add({ 'name': 'stateUpdater', - 'prevState': new Map.from(prevState), - 'props': new Map.from(props), + 'prevState': Map.from(prevState), + 'props': Map.from(props), }); return stateDelta; } @@ -1122,8 +1122,8 @@ void sharedLifecycleTests({ Map stateUpdater(Map prevState, Map props) { calls.add({ 'name': 'stateUpdater', - 'prevState': new Map.from(prevState), - 'props': new Map.from(props), + 'prevState': Map.from(prevState), + 'props': Map.from(props), }); return null; } @@ -1290,7 +1290,7 @@ void sharedLifecycleTests({ final Map initialPropsWithDefaults = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); final Map newPropsWithDefaults = unmodifiableMap(defaultProps, newProps, emptyChildrenProps); - var mountNode = new DivElement(); + var mountNode = DivElement(); var instance = react_dom.render(LifecycleTest(initialProps), mountNode); LifecycleTestHelper component = getDartComponent(instance); @@ -1347,7 +1347,7 @@ void sharedLifecycleTests({ const Map expectedState = const {}; - var mountNode = new DivElement(); + var mountNode = DivElement(); var instance = react_dom.render(LifecycleTest(initialProps), mountNode); LifecycleTestHelper component = getDartComponent(instance); @@ -1460,7 +1460,7 @@ void sharedLifecycleTests({ final Map expectedContext = const {}; - var mountNode = new DivElement(); + var mountNode = DivElement(); var instance = react_dom.render(LifecycleTest(initialProps), mountNode); LifecycleTestHelper component = getDartComponent(instance); @@ -1511,7 +1511,7 @@ void sharedLifecycleTests({ LifecycleTestHelper component; setUp(() { - var mountNode = new DivElement(); + var mountNode = DivElement(); var renderedInstance = react_dom.render(SetStateTest({}), mountNode); component = getDartComponent(renderedInstance); component.lifecycleCalls.clear(); @@ -1540,7 +1540,7 @@ void sharedLifecycleTests({ group('calls the setState callback, and transactional setState callback in the correct order', () { test('when shouldComponentUpdate returns false', () { - var mountNode = new DivElement(); + var mountNode = DivElement(); var renderedInstance = react_dom.render(SetStateTest({'shouldUpdate': false}), mountNode); Element renderedNode = react_dom.findDOMNode(renderedInstance); LifecycleTestHelper component = getDartComponent(renderedInstance); @@ -1563,7 +1563,7 @@ void sharedLifecycleTests({ }); test('when shouldComponentUpdate returns true', () { - var mountNode = new DivElement(); + var mountNode = DivElement(); var renderedInstance = react_dom.render(SetStateTest({}), mountNode); Element renderedNode = react_dom.findDOMNode(renderedInstance); LifecycleTestHelper component = getDartComponent(renderedInstance); diff --git a/test/lifecycle_test/component.dart b/test/lifecycle_test/component.dart index 6f56342d..eac23854 100644 --- a/test/lifecycle_test/component.dart +++ b/test/lifecycle_test/component.dart @@ -8,7 +8,7 @@ import 'package:react/react_client.dart'; import 'util.dart'; -ReactDartComponentFactoryProxy SetStateTest = react.registerComponent(() => new _SetStateTest()); +ReactDartComponentFactoryProxy SetStateTest = react.registerComponent(() => _SetStateTest()); class _SetStateTest extends react.Component with LifecycleTestHelper { @override @@ -80,7 +80,7 @@ class _SetStateTest extends react.Component with LifecycleTestHelper { } } -_DefaultPropsCachingTest defaultPropsCachingTestComponentFactory() => new _DefaultPropsCachingTest(); +_DefaultPropsCachingTest defaultPropsCachingTestComponentFactory() => _DefaultPropsCachingTest(); class _DefaultPropsCachingTest extends react.Component implements DefaultPropsCachingTestHelper { static int getDefaultPropsCallCount = 0; @@ -98,7 +98,7 @@ class _DefaultPropsCachingTest extends react.Component implements DefaultPropsCa render() => false; } -ReactDartComponentFactoryProxy DefaultPropsTest = react.registerComponent(() => new _DefaultPropsTest()); +ReactDartComponentFactoryProxy DefaultPropsTest = react.registerComponent(() => _DefaultPropsTest()); class _DefaultPropsTest extends react.Component { static int getDefaultPropsCallCount = 0; @@ -113,7 +113,7 @@ class _DefaultPropsTest extends react.Component { } ReactDartComponentFactoryProxy ContextWrapperWithoutKeys = - react.registerComponent(() => new _ContextWrapperWithoutKeys()); + react.registerComponent(() => _ContextWrapperWithoutKeys()); class _ContextWrapperWithoutKeys extends react.Component with LifecycleTestHelper { @override @@ -131,7 +131,7 @@ class _ContextWrapperWithoutKeys extends react.Component with LifecycleTestHelpe dynamic render() => react.div({}, props['children']); } -ReactDartComponentFactoryProxy ContextWrapper = react.registerComponent(() => new _ContextWrapper()); +ReactDartComponentFactoryProxy ContextWrapper = react.registerComponent(() => _ContextWrapper()); class _ContextWrapper extends react.Component with LifecycleTestHelper { @override @@ -150,14 +150,14 @@ class _ContextWrapper extends react.Component with LifecycleTestHelper { } ReactDartComponentFactoryProxy LifecycleTestWithContext = - react.registerComponent(() => new _LifecycleTestWithContext()); + react.registerComponent(() => _LifecycleTestWithContext()); class _LifecycleTestWithContext extends _LifecycleTest { @override Iterable get contextKeys => const ['foo']; // only listening to one context key } -ReactDartComponentFactoryProxy LifecycleTest = react.registerComponent(() => new _LifecycleTest()); +ReactDartComponentFactoryProxy LifecycleTest = react.registerComponent(() => _LifecycleTest()); class _LifecycleTest extends react.Component with LifecycleTestHelper { void componentWillMount() => lifecycleCall('componentWillMount'); @@ -165,28 +165,28 @@ class _LifecycleTest extends react.Component with LifecycleTestHelper { void componentWillUnmount() => lifecycleCall('componentWillUnmount'); void componentWillReceiveProps(newProps) => - lifecycleCall('componentWillReceiveProps', arguments: [new Map.from(newProps)]); + lifecycleCall('componentWillReceiveProps', arguments: [Map.from(newProps)]); void componentWillReceivePropsWithContext(newProps, newContext) => lifecycleCall('componentWillReceivePropsWithContext', - arguments: [new Map.from(newProps), new Map.from(newContext)]); + arguments: [Map.from(newProps), Map.from(newContext)]); void componentWillUpdate(nextProps, nextState) => - lifecycleCall('componentWillUpdate', arguments: [new Map.from(nextProps), new Map.from(nextState)]); + lifecycleCall('componentWillUpdate', arguments: [Map.from(nextProps), Map.from(nextState)]); void componentWillUpdateWithContext(nextProps, nextState, nextContext) => lifecycleCall('componentWillUpdateWithContext', - arguments: [new Map.from(nextProps), new Map.from(nextState), new Map.from(nextContext)]); + arguments: [Map.from(nextProps), Map.from(nextState), Map.from(nextContext)]); void componentDidUpdate(prevProps, prevState) => - lifecycleCall('componentDidUpdate', arguments: [new Map.from(prevProps), new Map.from(prevState)]); + lifecycleCall('componentDidUpdate', arguments: [Map.from(prevProps), Map.from(prevState)]); bool shouldComponentUpdate(nextProps, nextState) => lifecycleCall('shouldComponentUpdate', - arguments: [new Map.from(nextProps), new Map.from(nextState)], defaultReturnValue: () => true); + arguments: [Map.from(nextProps), Map.from(nextState)], defaultReturnValue: () => true); bool shouldComponentUpdateWithContext(nextProps, nextState, nextContext) => lifecycleCall('shouldComponentUpdateWithContext', - arguments: [new Map.from(nextProps), new Map.from(nextState), new Map.from(nextContext)], + arguments: [Map.from(nextProps), Map.from(nextState), Map.from(nextContext)], defaultReturnValue: () => true); dynamic render() => lifecycleCall('render', defaultReturnValue: () => react.div({})); diff --git a/test/lifecycle_test/component2.dart b/test/lifecycle_test/component2.dart index 8531db05..583c313b 100644 --- a/test/lifecycle_test/component2.dart +++ b/test/lifecycle_test/component2.dart @@ -8,9 +8,9 @@ import 'package:react/react_client/react_interop.dart'; import 'util.dart'; -final SetStateTest = react.registerComponent2(() => new _SetStateTest(), skipMethods: [null]); -final DefaultSkipMethodsTest = react.registerComponent2(() => new _SetStateTest()); -final SkipMethodsTest = react.registerComponent2(() => new _SetStateTest(), skipMethods: ['getSnapshotBeforeUpdate']); +final SetStateTest = react.registerComponent2(() => _SetStateTest(), skipMethods: [null]); +final DefaultSkipMethodsTest = react.registerComponent2(() => _SetStateTest()); +final SkipMethodsTest = react.registerComponent2(() => _SetStateTest(), skipMethods: ['getSnapshotBeforeUpdate']); class _SetStateTest extends react.Component2 with LifecycleTestHelper { @override @@ -117,7 +117,7 @@ class _SetStateTest extends react.Component2 with LifecycleTestHelper { } } -_DefaultPropsCachingTest defaultPropsCachingTestComponentFactory() => new _DefaultPropsCachingTest(); +_DefaultPropsCachingTest defaultPropsCachingTestComponentFactory() => _DefaultPropsCachingTest(); class _DefaultPropsCachingTest extends react.Component2 implements DefaultPropsCachingTestHelper { static int getDefaultPropsCallCount = 0; @@ -135,7 +135,7 @@ class _DefaultPropsCachingTest extends react.Component2 implements DefaultPropsC render() => false; } -final DefaultPropsTest = react.registerComponent2(() => new _DefaultPropsTest()); +final DefaultPropsTest = react.registerComponent2(() => _DefaultPropsTest()); class _DefaultPropsTest extends react.Component2 { Map get defaultProps => {'defaultProp': 'default'}; @@ -143,7 +143,7 @@ class _DefaultPropsTest extends react.Component2 { render() => false; } -final PropTypesTest = react.registerComponent2(() => new PropTypesTestComponent()); +final PropTypesTest = react.registerComponent2(() => PropTypesTestComponent()); class PropTypesTestComponent extends react.Component2 { get propTypes => { @@ -162,7 +162,7 @@ class PropTypesTestComponent extends react.Component2 { react.Context LifecycleTestContext = react.createContext(); -final ContextConsumerWrapper = react.registerComponent2(() => new _ContextConsumerWrapper()); +final ContextConsumerWrapper = react.registerComponent2(() => _ContextConsumerWrapper()); class _ContextConsumerWrapper extends react.Component2 with LifecycleTestHelper { dynamic render() { @@ -170,7 +170,7 @@ class _ContextConsumerWrapper extends react.Component2 with LifecycleTestHelper } } -final ContextWrapper = react.registerComponent2(() => new _ContextWrapper()); +final ContextWrapper = react.registerComponent2(() => _ContextWrapper()); class _ContextWrapper extends react.Component2 with LifecycleTestHelper { dynamic render() { @@ -183,14 +183,14 @@ class _ContextWrapper extends react.Component2 with LifecycleTestHelper { } } -final LifecycleTestWithContext = react.registerComponent2(() => new _LifecycleTestWithContext()); +final LifecycleTestWithContext = react.registerComponent2(() => _LifecycleTestWithContext()); class _LifecycleTestWithContext extends _LifecycleTest { @override get contextType => LifecycleTestContext; } -final ErrorComponent = react.registerComponent2(() => new _ErrorComponent()); +final ErrorComponent = react.registerComponent2(() => _ErrorComponent()); class TestDartException implements Exception { int code; @@ -214,28 +214,28 @@ class _ErrorComponent extends react.Component2 { } } -final ErrorLifecycleTest = react.registerComponent2(() => new _LifecycleTest(), skipMethods: []); -final LifecycleTest = react.registerComponent2(() => new _LifecycleTest()); +final ErrorLifecycleTest = react.registerComponent2(() => _LifecycleTest(), skipMethods: []); +final LifecycleTest = react.registerComponent2(() => _LifecycleTest()); class _LifecycleTest extends react.Component2 with LifecycleTestHelper { void componentDidMount() => lifecycleCall('componentDidMount'); void componentWillUnmount() => lifecycleCall('componentWillUnmount'); Map getDerivedStateFromProps(nextProps, prevState) => lifecycleCall('getDerivedStateFromProps', - arguments: [new Map.from(nextProps), new Map.from(prevState)], staticProps: nextProps); + arguments: [Map.from(nextProps), Map.from(prevState)], staticProps: nextProps); dynamic getSnapshotBeforeUpdate(prevProps, prevState) => - lifecycleCall('getSnapshotBeforeUpdate', arguments: [new Map.from(prevProps), new Map.from(prevState)]); + lifecycleCall('getSnapshotBeforeUpdate', arguments: [Map.from(prevProps), Map.from(prevState)]); void componentDidUpdate(prevProps, prevState, [snapshot]) => - lifecycleCall('componentDidUpdate', arguments: [new Map.from(prevProps), new Map.from(prevState), snapshot]); + lifecycleCall('componentDidUpdate', arguments: [Map.from(prevProps), Map.from(prevState), snapshot]); void componentDidCatch(error, info) => lifecycleCall('componentDidCatch', arguments: [error, info]); Map getDerivedStateFromError(error) => lifecycleCall('getDerivedStateFromError', arguments: [error]); bool shouldComponentUpdate(nextProps, nextState) => lifecycleCall('shouldComponentUpdate', - arguments: [new Map.from(nextProps), new Map.from(nextState)], defaultReturnValue: () => true); + arguments: [Map.from(nextProps), Map.from(nextState)], defaultReturnValue: () => true); dynamic render() => lifecycleCall('render', defaultReturnValue: () => react.div({})); @@ -245,25 +245,25 @@ class _LifecycleTest extends react.Component2 with LifecycleTestHelper { } final NoGetDerivedStateFromErrorLifecycleTest = - react.registerComponent2(() => new _NoGetDerivedStateFromErrorLifecycleTest(), skipMethods: []); + react.registerComponent2(() => _NoGetDerivedStateFromErrorLifecycleTest(), skipMethods: []); class _NoGetDerivedStateFromErrorLifecycleTest extends react.Component2 with LifecycleTestHelper { void componentDidMount() => lifecycleCall('componentDidMount'); void componentWillUnmount() => lifecycleCall('componentWillUnmount'); Map getDerivedStateFromProps(nextProps, prevState) => lifecycleCall('getDerivedStateFromProps', - arguments: [new Map.from(nextProps), new Map.from(prevState)], staticProps: nextProps); + arguments: [Map.from(nextProps), Map.from(prevState)], staticProps: nextProps); dynamic getSnapshotBeforeUpdate(prevProps, prevState) => - lifecycleCall('getSnapshotBeforeUpdate', arguments: [new Map.from(prevProps), new Map.from(prevState)]); + lifecycleCall('getSnapshotBeforeUpdate', arguments: [Map.from(prevProps), Map.from(prevState)]); void componentDidUpdate(prevProps, prevState, [snapshot]) => - lifecycleCall('componentDidUpdate', arguments: [new Map.from(prevProps), new Map.from(prevState), snapshot]); + lifecycleCall('componentDidUpdate', arguments: [Map.from(prevProps), Map.from(prevState), snapshot]); void componentDidCatch(error, info) => lifecycleCall('componentDidCatch', arguments: [error, info]); bool shouldComponentUpdate(nextProps, nextState) => lifecycleCall('shouldComponentUpdate', - arguments: [new Map.from(nextProps), new Map.from(nextState)], defaultReturnValue: () => true); + arguments: [Map.from(nextProps), Map.from(nextState)], defaultReturnValue: () => true); dynamic render() => lifecycleCall('render', defaultReturnValue: () => react.div({})); diff --git a/test/lifecycle_test/util.dart b/test/lifecycle_test/util.dart index d6d3d47d..6cd9d0ee 100644 --- a/test/lifecycle_test/util.dart +++ b/test/lifecycle_test/util.dart @@ -35,8 +35,8 @@ mixin LifecycleTestHelper on Component { lifecycleCalls.add({ 'memberName': memberName, 'arguments': arguments, - 'props': props == null ? null : new Map.from(props), - 'state': state == null ? null : new Map.from(state), + 'props': props == null ? null : Map.from(props), + 'state': state == null ? null : Map.from(state), 'context': context, }); diff --git a/test/react_client/bridge_test.dart b/test/react_client/bridge_test.dart index ca048b63..ce2945d0 100644 --- a/test/react_client/bridge_test.dart +++ b/test/react_client/bridge_test.dart @@ -38,13 +38,13 @@ main() { group('- Component2BridgeImpl', () { test('.bridgeFactory returns a const instance of Component2BridgeImpl', () { - expect(Component2BridgeImpl.bridgeFactory(new _Foo()), same(const Component2BridgeImpl())); + expect(Component2BridgeImpl.bridgeFactory(_Foo()), same(const Component2BridgeImpl())); }); }); }); } -final Foo = react.registerComponent2(() => new _Foo()); +final Foo = react.registerComponent2(() => _Foo()); class _Foo extends react.Component2 { @override @@ -53,8 +53,8 @@ class _Foo extends react.Component2 { List customBridgeCalls; -final BridgeTest = react.registerComponent2(() => new _BridgeTest(), bridgeFactory: (component) { - final returnedBridge = new CustomComponent2Bridge(); +final BridgeTest = react.registerComponent2(() => _BridgeTest(), bridgeFactory: (component) { + final returnedBridge = CustomComponent2Bridge(); customBridgeCalls?.add({ 'component': component, 'returnedBridge': returnedBridge, diff --git a/test/react_client/js_backed_map_test.dart b/test/react_client/js_backed_map_test.dart index 094469ad..e078bafc 100644 --- a/test/react_client/js_backed_map_test.dart +++ b/test/react_client/js_backed_map_test.dart @@ -13,7 +13,7 @@ main() { group('JsBackedMap', () { group('sets and retrieves values without JS interop interfering with them:', () { void testTypeValue(dynamic testValue) { - final jsBackedMap = new JsBackedMap(); + final jsBackedMap = JsBackedMap(); jsBackedMap['testValue'] = testValue; expect(jsBackedMap['testValue'], same(testValue)); } @@ -58,7 +58,7 @@ main() { }); test('addAllFromJs adds all properties from another JS object', () { - final jsMap = new JsBackedMap.from({ + final jsMap = JsBackedMap.from({ 'foo': 1, 'bar': 2, }); @@ -112,7 +112,7 @@ main() { JsBackedMap testMap; setUp(() { - testMap = new JsBackedMap.from({ + testMap = JsBackedMap.from({ 'foo': 1, 'bar': 2, }); @@ -140,7 +140,7 @@ main() { }); test('with a JSBackedMap (special case)', () { - testMap.addAll(new JsBackedMap.from({ + testMap.addAll(JsBackedMap.from({ 'foo': 'overwritten', 'baz': 3, })); diff --git a/test/react_client/js_interop_helpers_test.dart b/test/react_client/js_interop_helpers_test.dart index dafe4248..ec9f1718 100644 --- a/test/react_client/js_interop_helpers_test.dart +++ b/test/react_client/js_interop_helpers_test.dart @@ -67,7 +67,7 @@ main() { }); test('converts an Iterable', () { - final set = new Set.from([1, 2, 3, 4, 5, 6, 7, 8]); + final set = Set.from([1, 2, 3, 4, 5, 6, 7, 8]); final array = jsifyAndAllowInterop(set); expect(array is List, isTrue); expect(array.length, equals(set.length)); diff --git a/test/react_client/react_interop_test.dart b/test/react_client/react_interop_test.dart index c918840d..bdecc2d7 100644 --- a/test/react_client/react_interop_test.dart +++ b/test/react_client/react_interop_test.dart @@ -13,7 +13,7 @@ main() { Element mountNode; setUp(() { - mountNode = new DivElement(); + mountNode = DivElement(); }); tearDown(() { @@ -21,7 +21,7 @@ main() { }); test('with simple children', () { - final portalTargetNode = new Element.div(); + final portalTargetNode = Element.div(); final portal = ReactDom.createPortal('foo', portalTargetNode); react_dom.render(portal, mountNode); @@ -29,7 +29,7 @@ main() { }); test('with nested list children', () { - final portalTargetNode = new Element.div(); + final portalTargetNode = Element.div(); final portal = ReactDom.createPortal([ ['foo'], [ diff --git a/test/react_client_test.dart b/test/react_client_test.dart index e2bd3041..ab929288 100644 --- a/test/react_client_test.dart +++ b/test/react_client_test.dart @@ -58,7 +58,7 @@ main() { }); test('returns props for a composite JS ReactComponent', () { - var mountNode = new DivElement(); + var mountNode = DivElement(); ReactComponent renderedInstance = react_dom.render( testJsComponentFactory({ 'jsProp': 'js', @@ -77,7 +77,7 @@ main() { }); test('returns props for a composite JS ReactComponent, even when the props change', () { - var mountNode = new DivElement(); + var mountNode = DivElement(); ReactComponent renderedInstance = react_dom.render( testJsComponentFactory({ 'jsProp': 'js', @@ -250,7 +250,7 @@ class DartComponent2Component extends Component2 { } } -final DartComponent2 = react.registerComponent2(() => new DartComponent2Component()); +final DartComponent2 = react.registerComponent2(() => DartComponent2Component()); class DartComponentComponent extends Component { @override @@ -259,4 +259,4 @@ class DartComponentComponent extends Component { } } -ReactDartComponentFactoryProxy DartComponent = react.registerComponent(() => new DartComponentComponent()); +ReactDartComponentFactoryProxy DartComponent = react.registerComponent(() => DartComponentComponent()); diff --git a/test/react_component_test.dart b/test/react_component_test.dart index 50fa7549..aee6d197 100644 --- a/test/react_component_test.dart +++ b/test/react_component_test.dart @@ -9,7 +9,7 @@ main() { Component2 component; setUpAll(() { - component = new MyComponent(); + component = MyComponent(); }); group('throws when unsupported lifecycle methods are called (e.g., via super-calls)', () { diff --git a/test/react_context_test.dart b/test/react_context_test.dart index 858d984d..2b1a86e7 100644 --- a/test/react_context_test.dart +++ b/test/react_context_test.dart @@ -14,7 +14,7 @@ import 'shared_type_tester.dart'; main() { void testTypeValue(dynamic typeToTest) { - var mountNode = new html.DivElement(); + var mountNode = html.DivElement(); var contextTypeRef; var consumerRef; react_dom.render( @@ -45,7 +45,7 @@ main() { }); group('calculateChangeBits argument functions correctly', () { - var mountNode = new html.DivElement(); + var mountNode = html.DivElement(); _ContextProviderWrapper providerRef; _ContextConsumerWrapper consumerEvenRef; _ContextConsumerWrapper consumerOddRef; @@ -116,7 +116,7 @@ var TestCalculateChangedBitsContext = react.createContext(1, calculateChangedBit var TestContext = react.createContext(); -final ContextProviderWrapper = react.registerComponent2(() => new _ContextProviderWrapper()); +final ContextProviderWrapper = react.registerComponent2(() => _ContextProviderWrapper()); class _ContextProviderWrapper extends react.Component2 { get initialState { @@ -135,7 +135,7 @@ class _ContextProviderWrapper extends react.Component2 { } } -final ContextConsumerWrapper = react.registerComponent2(() => new _ContextConsumerWrapper()); +final ContextConsumerWrapper = react.registerComponent2(() => _ContextConsumerWrapper()); class _ContextConsumerWrapper extends react.Component2 { dynamic latestValue; @@ -147,7 +147,7 @@ class _ContextConsumerWrapper extends react.Component2 { } } -final ContextTypeComponent = react.registerComponent2(() => new _ContextTypeComponent()); +final ContextTypeComponent = react.registerComponent2(() => _ContextTypeComponent()); class _ContextTypeComponent extends react.Component2 { var contextType = TestContext; diff --git a/test/react_fragment_test.dart b/test/react_fragment_test.dart index 537dd849..fe5534ee 100644 --- a/test/react_fragment_test.dart +++ b/test/react_fragment_test.dart @@ -27,7 +27,7 @@ main() { react.div({}), ]) ]), - new Element.div(), + Element.div(), ); expect(wrappingDivRef.children, hasLength(4)); @@ -36,7 +36,7 @@ main() { test('passes the key properly onto the fragment', () { var callCount = 0; - var mountElement = new Element.div(); + var mountElement = Element.div(); react_dom.render( react.Fragment({ @@ -80,4 +80,4 @@ class _FragmentTestDummy extends react.Component2 { } } -final FragmentTestDummy = react.registerComponent2(() => new _FragmentTestDummy()); +final FragmentTestDummy = react.registerComponent2(() => _FragmentTestDummy()); diff --git a/test/react_strictmode_test.dart b/test/react_strictmode_test.dart index 39b5dae4..320ceec8 100644 --- a/test/react_strictmode_test.dart +++ b/test/react_strictmode_test.dart @@ -27,7 +27,7 @@ main() { react.div({}), ]) ]), - new Element.div(), + Element.div(), ); expect(wrappingDivRef.children, hasLength(4)); diff --git a/test/react_suspense_test.dart b/test/react_suspense_test.dart index a546461c..4245ffd4 100644 --- a/test/react_suspense_test.dart +++ b/test/react_suspense_test.dart @@ -44,7 +44,7 @@ main() { return simple.SimpleFunctionComponent; }); var wrappingDivRef; - var mountElement = new Element.div(); + var mountElement = Element.div(); react_dom.render( react.div({ 'ref': (ref) { @@ -78,8 +78,8 @@ main() { }); var wrappingDivRef; var wrappingDivRef2; - var mountElement = new Element.div(); - var mountElement2 = new Element.div(); + var mountElement = Element.div(); + var mountElement2 = Element.div(); react_dom.render( react.div({ diff --git a/test/shared_type_tester.dart b/test/shared_type_tester.dart index bd83326e..f6ed3582 100644 --- a/test/shared_type_tester.dart +++ b/test/shared_type_tester.dart @@ -24,8 +24,8 @@ void sharedTypeTests( }) { if (!skipNormalDartObjects) { test('normal Dart objects', () { - final object = new Foo('f'); - final iterable = new Iterable.generate(2); + final object = Foo('f'); + final iterable = Iterable.generate(2); testTypeValue(object); testTypeValue(iterable); }); @@ -68,7 +68,7 @@ void sharedTypeTests( _functionLocalMethod() {} final functionLocalMethod = _functionLocalMethod; final functionExpression = () {}; - final functionTearOff = new Object().toString; + final functionTearOff = Object().toString; final functionAllowInterop = allowInterop(() {}); testTypeValue(functionLocalMethod); @@ -80,8 +80,8 @@ void sharedTypeTests( if (!skipBrowserObjects) { test('browser objects', () { - final element = new html.DivElement(); - final customEvent = new html.CustomEvent('foo'); + final element = html.DivElement(); + final customEvent = html.CustomEvent('foo'); final window = html.window; testTypeValue(element); @@ -102,7 +102,7 @@ void sharedTypeTests( if (!skipDatetimes) { test('datetimes', () { - final dateTime = new DateTime.utc(2018); + final dateTime = DateTime.utc(2018); testTypeValue(dateTime); }); @@ -110,7 +110,7 @@ void sharedTypeTests( if (!skipFutures) { test('futures', () { - final future = new Future(() {}); + final future = Future(() {}); testTypeValue(future); }); @@ -118,7 +118,7 @@ void sharedTypeTests( if (!skipJsAnonInteropTypes) { test('JS anonymous interop types', () { - final jsAnonymous = new JsTypeAnonymous(); + final jsAnonymous = JsTypeAnonymous(); testTypeValue(jsAnonymous); }); @@ -126,7 +126,7 @@ void sharedTypeTests( if (!skipJsInteropTypes) { test('JS interop types', () { - final jsType = new JsType(); + final jsType = JsType(); testTypeValue(jsType); }); diff --git a/test/test_components.dart b/test/test_components.dart index 08b5656c..e818eb3c 100644 --- a/test/test_components.dart +++ b/test/test_components.dart @@ -73,8 +73,8 @@ class WrapperComponent extends Component { render() => div(props, props['children']); } -final eventComponent = registerComponent(() => new EventComponent()); +final eventComponent = registerComponent(() => EventComponent()); -final sampleComponent = registerComponent(() => new SampleComponent()); +final sampleComponent = registerComponent(() => SampleComponent()); -final wrapperComponent = registerComponent(() => new WrapperComponent()); +final wrapperComponent = registerComponent(() => WrapperComponent()); diff --git a/test/test_components2.dart b/test/test_components2.dart index 5ee47c72..00b1e91c 100644 --- a/test/test_components2.dart +++ b/test/test_components2.dart @@ -73,8 +73,8 @@ class WrapperComponent2 extends Component2 { render() => div(props, props['children']); } -final eventComponent = registerComponent(() => new EventComponent2()); +final eventComponent = registerComponent(() => EventComponent2()); -final sampleComponent = registerComponent(() => new SampleComponent2()); +final sampleComponent = registerComponent(() => SampleComponent2()); -final wrapperComponent = registerComponent(() => new WrapperComponent2()); +final wrapperComponent = registerComponent(() => WrapperComponent2()); diff --git a/test/util.dart b/test/util.dart index df5a90a3..80c2da38 100644 --- a/test/util.dart +++ b/test/util.dart @@ -17,7 +17,7 @@ import 'package:test/test.dart'; Map getProps(dynamic elementOrComponent) { var props = elementOrComponent.props; - return new Map.fromIterable(objectKeys(props), value: (key) => getProperty(props, key)); + return Map.fromIterable(objectKeys(props), value: (key) => getProperty(props, key)); } bool isDartComponent1(ReactElement element) => @@ -37,7 +37,7 @@ Map getDartComponentProps(ReactComponent dartComponent) { } Map getDartElementProps(ReactElement dartElement) { - return isDartComponent2(dartElement) ? new JsBackedMap.fromJs(dartElement.props) : dartElement.props.internal.props; + return isDartComponent2(dartElement) ? JsBackedMap.fromJs(dartElement.props) : dartElement.props.internal.props; } ReactComponent render(ReactElement reactElement) { @@ -51,7 +51,7 @@ Map unmodifiableMap([Map map1, Map map2, Map map3, Map map4]) { if (map2 != null) merged.addAll(map2); if (map3 != null) merged.addAll(map3); if (map4 != null) merged.addAll(map4); - return new Map.unmodifiable(merged); + return Map.unmodifiable(merged); } bool assertsEnabled() { diff --git a/test/util_test.dart b/test/util_test.dart index 4b4bb9b4..42ff6246 100644 --- a/test/util_test.dart +++ b/test/util_test.dart @@ -53,14 +53,14 @@ _FunctionFoo(Map props) { return react.div({}); } -final Foo = react.registerComponent(() => new _Foo()); +final Foo = react.registerComponent(() => _Foo()); class _Foo extends react.Component { @override render() => react.div({}); } -final Foo2 = react.registerComponent2(() => new _Foo2()); +final Foo2 = react.registerComponent2(() => _Foo2()); class _Foo2 extends react.Component2 { @override diff --git a/tool/run_consumer_tests.dart b/tool/run_consumer_tests.dart index 0fbbe09b..faa2e4b4 100644 --- a/tool/run_consumer_tests.dart +++ b/tool/run_consumer_tests.dart @@ -3,7 +3,7 @@ import 'dart:io'; import 'package:args/args.dart'; Future main(List args) async { - final parser = new ArgParser() + final parser = ArgParser() ..addOption('repoName') ..addOption('orgName') ..addOption('testCmd') From 1e322c2b65ba6e7ad7aca8f89def07ab3aed9001 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 15:10:30 -0700 Subject: [PATCH 03/31] dart fix --apply --code=unnecessary_const --- lib/react.dart | 2 +- test/lifecycle_test.dart | 66 +++++++++++++++++------------------ test/lifecycle_test/util.dart | 4 +-- test/react_client_test.dart | 4 +-- 4 files changed, 38 insertions(+), 38 deletions(-) diff --git a/lib/react.dart b/lib/react.dart index 0119cb74..e518ef1b 100644 --- a/lib/react.dart +++ b/lib/react.dart @@ -1463,7 +1463,7 @@ abstract class ReactComponentFactoryProxy implements Function { } } -const _notSpecified = const NotSpecified(); +const _notSpecified = NotSpecified(); class NotSpecified { const NotSpecified(); diff --git a/test/lifecycle_test.dart b/test/lifecycle_test.dart index 53230923..19de3ed8 100644 --- a/test/lifecycle_test.dart +++ b/test/lifecycle_test.dart @@ -61,7 +61,7 @@ main() { group('prevents concurrent modification of `_setStateCallbacks`', () { LifecycleTestHelper component; - const Map initialState = const { + const Map initialState = { 'initialState': 'initial', }; int firstStateUpdateCalls; @@ -204,7 +204,7 @@ main() { }); test('updates with correct lifecycle calls when `forceUpdate` is called', () { - const Map initialState = const { + const Map initialState = { 'initialState': 'initial', }; @@ -250,11 +250,11 @@ main() { group('getDerivedStateFromProps returns', () { test('derived state, resulting in an updated instance state value', () { - const Map initialDerivedState = const { + const Map initialDerivedState = { 'initialDerivedState': 'initial', }; - const Map updatedDerivedState = const { + const Map updatedDerivedState = { 'initialDerivedState': 'updated', }; @@ -301,7 +301,7 @@ main() { }); test('null, leaving the existing instance state value intact', () { - const Map initialState = const { + const Map initialState = { 'foo': 'sudo', }; final Map initialProps = unmodifiableMap({ @@ -730,11 +730,11 @@ void sharedLifecycleTests({ ..addAll(defaultProps) ..addAll(newProps)); - const Map expectedState = const {}; + const Map expectedState = {}; - const Map initialContext = const {'foo': false}; + const Map initialContext = {'foo': false}; - const Map expectedContext = const {'foo': true}; + const Map expectedContext = {'foo': true}; Map refMap = { 'ref': ((ref) => component = ref), @@ -801,11 +801,11 @@ void sharedLifecycleTests({ test('receives updated context with correct lifecycle calls', () { LifecycleTestHelper component; - const Map expectedState = const {}; + const Map expectedState = {}; - const Map initialContext = const {'foo': false}; + const Map initialContext = {'foo': false}; - const Map expectedContext = const {'foo': true}; + const Map expectedContext = {'foo': true}; Map refMap = { 'ref': ((ref) => component = ref), @@ -865,7 +865,7 @@ void sharedLifecycleTests({ test('receives updated context with correct lifecycle calls when wrapped with a consumer', () { LifecycleTestHelper component; - const Map expectedState = const {}; + const Map expectedState = {}; Map initialContext = {'foo': false}; @@ -938,8 +938,8 @@ void sharedLifecycleTests({ } test('receives updated props with correct lifecycle calls and defaults properly merged in', () { - const Map initialProps = const {'initialProp': 'initial', 'children': const []}; - const Map newProps = const {'newProp': 'new', 'children': const []}; + const Map initialProps = {'initialProp': 'initial', 'children': []}; + const Map newProps = {'newProp': 'new', 'children': []}; final Map initialPropsWithDefaults = unmodifiableMap({} ..addAll(defaultProps) @@ -948,7 +948,7 @@ void sharedLifecycleTests({ ..addAll(defaultProps) ..addAll(newProps)); - const Map expectedState = const {}; + const Map expectedState = {}; final dynamic expectedContext = isComponent2 ? null : const {}; const Null expectedSnapshot = null; @@ -999,7 +999,7 @@ void sharedLifecycleTests({ if (isComponent2) { test('initializes state with the value set by `initialState`', () { - const Map initialState = const { + const Map initialState = { 'initialState': 'initial', }; @@ -1020,14 +1020,14 @@ void sharedLifecycleTests({ } group('updates state with correct lifecycle calls', () { - const Map initialState = const { + const Map initialState = { 'initialState': 'initial', }; - const Map newState = const { + const Map newState = { 'initialState': 'initial', 'newState': 'new', }; - const Map stateDelta = const { + const Map stateDelta = { 'newState': 'new', }; @@ -1151,7 +1151,7 @@ void sharedLifecycleTests({ }); test('updates state with correct lifecycle calls when `redraw` is called', () { - const Map initialState = const { + const Map initialState = { 'initialState': 'initial', }; @@ -1198,7 +1198,7 @@ void sharedLifecycleTests({ group('prevents concurrent modification of `_setStateCallbacks`', () { LifecycleTestHelper component; - const Map initialState = const { + const Map initialState = { 'initialState': 'initial', }; int firstStateUpdateCalls; @@ -1266,17 +1266,17 @@ void sharedLifecycleTests({ if (!isComponent2) { test('properly handles a call to setState within componentWillReceiveProps', () { - const Map initialState = const { + const Map initialState = { 'initialState': 'initial', }; - const Map newState = const { + const Map newState = { 'initialState': 'initial', 'newState': 'new', }; - const Map stateDelta = const { + const Map stateDelta = { 'newState': 'new', }; - const Map expectedContext = const {}; + const Map expectedContext = {}; final Map lifecycleTestProps = unmodifiableMap({ 'getInitialState': (_) => initialState, @@ -1340,12 +1340,12 @@ void sharedLifecycleTests({ 'initialProp': 'initial', 'children': const [] }); - const Map newProps = const {'newProp': 'new', 'children': const []}; + const Map newProps = {'newProp': 'new', 'children': []}; final Map initialPropsWithDefaults = unmodifiableMap(defaultProps, initialProps); final Map newPropsWithDefaults = unmodifiableMap(defaultProps, newProps); - const Map expectedState = const {}; + const Map expectedState = {}; var mountNode = DivElement(); var instance = react_dom.render(LifecycleTest(initialProps), mountNode); @@ -1384,14 +1384,14 @@ void sharedLifecycleTests({ test('updates state with correct lifecycle calls and does not rerender', () { final dynamic expectedContext = isComponent2 ? null : const {}; - const Map initialState = const { + const Map initialState = { 'initialState': 'initial', }; - const Map newState = const { + const Map newState = { 'initialState': 'initial', 'newState': 'new', }; - const Map stateDelta = const { + const Map stateDelta = { 'newState': 'new', }; @@ -1433,14 +1433,14 @@ void sharedLifecycleTests({ if (!isComponent2) { test('properly handles a call to setState within componentWillReceiveProps and does not rerender', () { - const Map initialState = const { + const Map initialState = { 'initialState': 'initial', }; - const Map newState = const { + const Map newState = { 'initialState': 'initial', 'newState': 'new', }; - const Map stateDelta = const { + const Map stateDelta = { 'newState': 'new', }; diff --git a/test/lifecycle_test/util.dart b/test/lifecycle_test/util.dart index 6cd9d0ee..c646de3d 100644 --- a/test/lifecycle_test/util.dart +++ b/test/lifecycle_test/util.dart @@ -2,8 +2,8 @@ import 'package:matcher/matcher.dart'; import 'package:react/react.dart'; -const Map defaultProps = const {'defaultProp': 'default'}; -const Map emptyChildrenProps = const {'children': const []}; +const Map defaultProps = {'defaultProp': 'default'}; +const Map emptyChildrenProps = {'children': []}; Map matchCall(String memberName, {args: anything, props: anything, state: anything, context: anything}) { return { diff --git a/test/react_client_test.dart b/test/react_client_test.dart index ab929288..8474d4ad 100644 --- a/test/react_client_test.dart +++ b/test/react_client_test.dart @@ -19,8 +19,8 @@ import 'package:react/src/react_client/event_prop_key_to_event_factory.dart'; main() { group('unconvertJsProps', () { - const List testChildren = const ['child1', 'child2']; - const Map testStyle = const {'background': 'white'}; + const List testChildren = ['child1', 'child2']; + const Map testStyle = {'background': 'white'}; test('returns props for a composite JS component ReactElement', () { ReactElement instance = testJsComponentFactory({ From acc03f1e9218f4347088b3821d0a2ff5971bd863 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 15:09:37 -0700 Subject: [PATCH 04/31] dart fix --apply --code=prefer_single_quotes --- example/js_components/js_components.dart | 10 +- example/test/call_and_nosuchmethod_test.dart | 6 +- example/test/get_dom_node_test.dart | 26 ++--- example/test/order_test.dart | 8 +- example/test/react_test.dart | 6 +- example/test/react_test_components.dart | 98 +++++++++---------- example/test/ref_test.dart | 38 +++---- example/test/speed_test.dart | 22 ++--- example/test/unmount_test.dart | 14 +-- lib/react_client/js_interop_helpers.dart | 4 +- .../react_client/component_registration.dart | 8 +- test/hooks_test.dart | 2 +- test/js_builds/shared_tests.dart | 2 +- test/lifecycle_test.dart | 20 ++-- test/lifecycle_test/component.dart | 4 +- test/lifecycle_test/component2.dart | 10 +- test/react_test_utils_test.dart | 2 +- 17 files changed, 140 insertions(+), 140 deletions(-) diff --git a/example/js_components/js_components.dart b/example/js_components/js_components.dart index 03c9ba9e..af3d2281 100644 --- a/example/js_components/js_components.dart +++ b/example/js_components/js_components.dart @@ -62,21 +62,21 @@ class _IndexComponent extends react.Component2 { DialogActions( {}, Button({ - 'color': "primary", + 'color': 'primary', 'onClick': handleClose, }, 'OK'), )), Typography({ - 'variant': "h4", + 'variant': 'h4', 'gutterBottom': true, }, 'Material-UI'), Typography({ - 'variant': "subtitle1", + 'variant': 'subtitle1', 'gutterBottom': true, }, 'example project'), Button({ - 'variant': "contained", - 'color': "secondary", + 'variant': 'contained', + 'color': 'secondary', 'onClick': handleClick, }, Icon({}, 'fingerprint'), 'Super Secret Password'), ); diff --git a/example/test/call_and_nosuchmethod_test.dart b/example/test/call_and_nosuchmethod_test.dart index 67d021e9..8fa34262 100644 --- a/example/test/call_and_nosuchmethod_test.dart +++ b/example/test/call_and_nosuchmethod_test.dart @@ -1,8 +1,8 @@ // ignore_for_file: deprecated_member_use_from_same_package -import "dart:html"; +import 'dart:html'; -import "package:react/react_dom.dart" as react_dom; -import "package:react/react.dart" as react; +import 'package:react/react_dom.dart' as react_dom; +import 'package:react/react.dart' as react; class _CustomComponent extends react.Component { render() { diff --git a/example/test/get_dom_node_test.dart b/example/test/get_dom_node_test.dart index 00030f18..4d2e405d 100644 --- a/example/test/get_dom_node_test.dart +++ b/example/test/get_dom_node_test.dart @@ -1,12 +1,12 @@ // ignore_for_file: deprecated_member_use_from_same_package -import "dart:html"; +import 'dart:html'; -import "package:react/react.dart" as react; -import "package:react/react_dom.dart" as react_dom; +import 'package:react/react.dart' as react; +import 'package:react/react_dom.dart' as react_dom; customAssert(text, condition) { if (condition) - print("${text} passed"); + print('${text} passed'); else throw (text); } @@ -17,7 +17,7 @@ class _ChildComponent extends react.Component { var counter = 0; render() => react.div({}, [ - "Test element", + 'Test element', counter.toString(), react.button({ 'type': 'button', @@ -37,14 +37,14 @@ class SimpleComponent extends react.Component { var refToSpan; var refToElement; - componentWillMount() => print("mount"); + componentWillMount() => print('mount'); - componentWillUnmount() => print("unmount"); + componentWillUnmount() => print('unmount'); componentDidMount() { - customAssert("ref to span return span ", refToSpan.text == "Test"); - customAssert("findDOMNode works on this", react_dom.findDOMNode(this) != null); - customAssert("random ref resolves to null", this.ref("someRandomRef") == null); + customAssert('ref to span return span ', refToSpan.text == 'Test'); + customAssert('findDOMNode works on this', react_dom.findDOMNode(this) != null); + customAssert('random ref resolves to null', this.ref('someRandomRef') == null); } var counter = 0; @@ -52,10 +52,10 @@ class SimpleComponent extends react.Component { render() => react.div({}, [ react.span({ 'key': 'span1', - "ref": (ref) { + 'ref': (ref) { refToSpan = ref; } - }, "Test"), + }, 'Test'), react.span({'key': 'span2'}, counter), react.button({ 'type': 'button', @@ -66,7 +66,7 @@ class SimpleComponent extends react.Component { react.br({'key': 'br'}), ChildComponent({ 'key': 'child', - "ref": (ref) { + 'ref': (ref) { refToElement = ref; } }), diff --git a/example/test/order_test.dart b/example/test/order_test.dart index bdd8bfab..e06596e0 100644 --- a/example/test/order_test.dart +++ b/example/test/order_test.dart @@ -1,13 +1,13 @@ // ignore_for_file: deprecated_member_use_from_same_package import 'dart:html'; -import "package:react/react.dart" as react; -import "package:react/react_dom.dart" as react_dom; +import 'package:react/react.dart' as react; +import 'package:react/react_dom.dart' as react_dom; class _Item extends react.Component { componentWillReceiveProps(newProps) { - print("Old props: $props"); - print("New props: $newProps"); + print('Old props: $props'); + print('New props: $newProps'); } shouldComponentUpdate(nextProps, nextState) { diff --git a/example/test/react_test.dart b/example/test/react_test.dart index 122d917f..021303e4 100644 --- a/example/test/react_test.dart +++ b/example/test/react_test.dart @@ -1,8 +1,8 @@ -import "dart:html"; +import 'dart:html'; -import "package:react/react_dom.dart" as react_dom; +import 'package:react/react_dom.dart' as react_dom; -import "react_test_components.dart"; +import 'react_test_components.dart'; void main() { react_dom.render( diff --git a/example/test/react_test_components.dart b/example/test/react_test_components.dart index aade6745..88932891 100644 --- a/example/test/react_test_components.dart +++ b/example/test/react_test_components.dart @@ -1,8 +1,8 @@ // ignore_for_file: deprecated_member_use_from_same_package -import "dart:async"; +import 'dart:async'; -import "package:react/react.dart" as react; -import "package:react/react_dom.dart" as react_dom; +import 'package:react/react.dart' as react; +import 'package:react/react_dom.dart' as react_dom; class _HelloComponent extends react.Component2 { @override @@ -25,7 +25,7 @@ var helloComponent = react.registerComponent(() => _HelloComponent()); class _HelloGreeter extends react.Component { var myInput; - getInitialState() => {"name": "World"}; + getInitialState() => {'name': 'World'}; onInputChange(e) { var input = react_dom.findDOMNode(myInput); @@ -50,7 +50,7 @@ class _HelloGreeter extends react.Component { var helloGreeter = react.registerComponent(() => _HelloGreeter()); class _CheckBoxComponent extends react.Component { - getInitialState() => {"checked": false}; + getInitialState() => {'checked': false}; _handleChange(e) { this.setState({'checked': e.target.checked}); @@ -87,7 +87,7 @@ class _ClockComponent extends react.Component { Map getDefaultProps() => {'refreshRate': 1000}; void componentWillMount() { - timer = Timer.periodic(Duration(milliseconds: this.props["refreshRate"]), this.tick); + timer = Timer.periodic(Duration(milliseconds: this.props['refreshRate']), this.tick); } void componentWillUnmount() { @@ -96,7 +96,7 @@ class _ClockComponent extends react.Component { void componentDidMount() { var rootNode = react_dom.findDOMNode(this); - rootNode.style.backgroundColor = "#FFAAAA"; + rootNode.style.backgroundColor = '#FFAAAA'; } bool shouldComponentUpdate(nextProps, nextState) { @@ -106,7 +106,7 @@ class _ClockComponent extends react.Component { } void componentWillReceiveProps(nextProps) { - print("Received props: $nextProps"); + print('Received props: $nextProps'); } tick(Timer timer) { @@ -114,9 +114,9 @@ class _ClockComponent extends react.Component { } render() { - return react.span({'onClick': (event) => print("Hello World!")}, + return react.span({'onClick': (event) => print('Hello World!')}, // { 'onClick': (event, [domid = null]) => print("Hello World!") }, - ["Seconds elapsed: ", "${state['secondsElapsed']}"]); + ['Seconds elapsed: ', "${state['secondsElapsed']}"]); } } @@ -125,34 +125,34 @@ var clockComponent = react.registerComponent(() => _ClockComponent()); class _ListComponent extends react.Component { Map getInitialState() { return { - "items": List.from([0, 1, 2, 3]) + 'items': List.from([0, 1, 2, 3]) }; } void componentWillUpdate(nextProps, nextState) { - if (nextState["items"].length > state["items"].length) { - print("Adding " + nextState["items"].last.toString()); + if (nextState['items'].length > state['items'].length) { + print('Adding ' + nextState['items'].last.toString()); } } void componentDidUpdate(prevProps, prevState) { - if (prevState["items"].length > state["items"].length) { - print("Removed " + prevState["items"].first.toString()); + if (prevState['items'].length > state['items'].length) { + print('Removed ' + prevState['items'].first.toString()); } } int iterator = 3; void addItem(event) { - List items = List.from(state["items"]); + List items = List.from(state['items']); items.add(++iterator); - setState({"items": items}); + setState({'items': items}); } dynamic render() { List items = []; for (var item in state['items']) { - items.add(react.li({"key": item}, "$item")); + items.add(react.li({'key': item}, '$item')); } return react.div({}, [ @@ -409,10 +409,10 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot } String getSnapshotBeforeUpdate(nextProps, prevState) { - if (prevState["items"].length > state["items"].length) { - return "removed " + prevState["items"].last.toString(); + if (prevState['items'].length > state['items'].length) { + return 'removed ' + prevState['items'].last.toString(); } else { - return "added " + state["items"].last.toString(); + return 'added ' + state['items'].last.toString(); } } @@ -421,19 +421,19 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot print('Updated DOM and ' + snapshot); return null; } - print("No Snapshot"); + print('No Snapshot'); } void removeItem(event) { - List items = List.from(state["items"]); + List items = List.from(state['items']); items.removeAt(items.length - 1); - setState({"items": items}); + setState({'items': items}); } void addItem(event) { - List items = List.from(state["items"]); + List items = List.from(state['items']); items.add(items.length); - setState({"items": items}); + setState({'items': items}); } dynamic render() { @@ -442,7 +442,7 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot final items = []; for (var item in state['items']) { final count = itemCounts[item] = (itemCounts[item] ?? 0) + 1; - items.add(react.li({'key': 'c2-$item-$count'}, "$item")); + items.add(react.li({'key': 'c2-$item-$count'}, '$item')); } return react.div({}, [ @@ -468,8 +468,8 @@ var component2TestComponent = react.registerComponent(() => _Component2TestCompo class _ErrorComponent extends react.Component2 { void componentDidMount() { - if (!props["errored"]) { - throw _CustomException("It broke!", 2); + if (!props['errored']) { + throw _CustomException('It broke!', 2); } } @@ -477,7 +477,7 @@ class _ErrorComponent extends react.Component2 { return react.div( {'key': 'eb-d1-e'}, "Oh no, I'm an error! Check your " - "console."); + 'console.'); } } @@ -491,58 +491,58 @@ class _CustomException implements Exception { _CustomException(this.message, this.code) { switch (code) { case 1: - randomMessage = "The code is a 1"; + randomMessage = 'The code is a 1'; break; case 2: - randomMessage = "The Code is a 2"; + randomMessage = 'The Code is a 2'; break; default: - randomMessage = "Default Error Code"; + randomMessage = 'Default Error Code'; } } } class _Component2ErrorTestComponent extends react.Component2 { Map get initialState => { - "clicked": false, - "errored": false, - "error": null, + 'clicked': false, + 'errored': false, + 'error': null, }; void componentDidCatch(error, info) { if (error is _CustomException) { print(info.dartStackTrace); - setState({"error": error.randomMessage}); + setState({'error': error.randomMessage}); } else { setState({ - "error": "We can capture the error, store it in state and " - "display it here." + 'error': 'We can capture the error, store it in state and ' + 'display it here.' }); } } Map getDerivedStateFromError(error) { - return {"errored": true}; + return {'errored': true}; } void error(event) { - setState({"clicked": true}); + setState({'clicked': true}); } void clearError(event) { - setState({"clicked": false, "error": null, "errored": false}); + setState({'clicked': false, 'error': null, 'errored': false}); } dynamic render() { - dynamic errorMessage = state["error"] ?? "No error yet"; + dynamic errorMessage = state['error'] ?? 'No error yet'; return react.div({ - "key": "e-cont" + 'key': 'e-cont' }, [ - react.h3({"key": "e-header"}, "Error Boundary Test"), - state["clicked"] ? ErrorComponent({'key': 'ec-1', 'errored': state['errored']}) : null, + react.h3({'key': 'e-header'}, 'Error Boundary Test'), + state['clicked'] ? ErrorComponent({'key': 'ec-1', 'errored': state['errored']}) : null, errorMessage != null ? react.div({'key': 'ec-m-1'}, '$errorMessage') : null, - !state["errored"] + !state['errored'] ? react.button({ 'type': 'button', 'key': 'c3-r-button', @@ -550,7 +550,7 @@ class _Component2ErrorTestComponent extends react.Component2 { 'onClick': error, }, 'Trigger Error') : null, - state["errored"] + state['errored'] ? react.button({ 'type': 'button', 'key': 'c3-c-button', @@ -558,7 +558,7 @@ class _Component2ErrorTestComponent extends react.Component2 { 'onClick': clearError, }, 'Clear Error') : null, - react.hr({"key": "e-hr"}), + react.hr({'key': 'e-hr'}), ]); } } diff --git a/example/test/ref_test.dart b/example/test/ref_test.dart index cf1319be..22b478e2 100644 --- a/example/test/ref_test.dart +++ b/example/test/ref_test.dart @@ -1,9 +1,9 @@ // ignore_for_file: deprecated_member_use_from_same_package -import "dart:html"; +import 'dart:html'; -import "package:react/react.dart" as react; -import "package:react/react_dom.dart" as react_dom; -import "package:react/react_client.dart"; +import 'package:react/react.dart' as react; +import 'package:react/react_dom.dart' as react_dom; +import 'package:react/react_client.dart'; var ChildComponent = react.registerComponent(() => _ChildComponent()); @@ -14,7 +14,7 @@ class _ChildComponent extends react.Component { redraw(); } - render() => react.span({}, "Child element with value ${somevalue}"); + render() => react.span({}, 'Child element with value ${somevalue}'); } var InputComponentForm = react.forwardRef2((props, ref) { @@ -39,14 +39,14 @@ var InputComponentForm = react.forwardRef2((props, ref) { var ChildComponentForm = react.forwardRef2((props, ref) { return react.Fragment({}, [ - react.h4({'key': 'create-child-h4'}, "ChildComponent"), + react.h4({'key': 'create-child-h4'}, 'ChildComponent'), react.form({ 'key': 'childComponentForm', 'className': 'form-inline' }, [ ChildComponent({ 'key': 'create-child', - "ref": ref, + 'ref': ref, }), '\u00a0', react.button({ @@ -76,11 +76,11 @@ class _ParentComponent extends react.Component { } showChildValue(_) { - print(ref("childRef").somevalue); + print(ref('childRef').somevalue); } incrementChildValue(_) { - ref("childRef").incrementValue(); + ref('childRef').incrementValue(); } // Callback refs @@ -121,8 +121,8 @@ class _ParentComponent extends react.Component { react.div({ 'key': 'string-refs' }, [ - react.h2({'key': 'string-h2'}, "String refs"), - react.h4({'key': 'string-h4'}, ""), + react.h2({'key': 'string-h2'}, 'String refs'), + react.h4({'key': 'string-h4'}, ''), react.form({ 'key': 'stringRefInputForm', 'className': 'form-inline' @@ -140,12 +140,12 @@ class _ParentComponent extends react.Component { 'onClick': showInputValue, }, 'Print input element value'), ]), - react.h4({'key': 'string-h4-child'}, "ChildComponent"), + react.h4({'key': 'string-h4-child'}, 'ChildComponent'), react.form({ 'key': 'stringRefChildComponentForm', 'className': 'form-inline' }, [ - ChildComponent({'key': 'string-child', "ref": "childRef"}), + ChildComponent({'key': 'string-child', 'ref': 'childRef'}), '\u00a0', react.button({ 'type': 'button', @@ -165,8 +165,8 @@ class _ParentComponent extends react.Component { react.div({ 'key': 'callback-refs' }, [ - react.h2({'key': 'h2-callback'}, "Callback refs"), - react.h4({'key': 'h4-callback-input'}, ""), + react.h2({'key': 'h2-callback'}, 'Callback refs'), + react.h4({'key': 'h4-callback-input'}, ''), react.form({ 'key': 'inputForm', 'className': 'form-inline' @@ -184,14 +184,14 @@ class _ParentComponent extends react.Component { 'onClick': showInputCallbackRefValue, }, 'Print input element value'), ]), - react.h4({'key': 'callback-child-h4'}, "ChildComponent"), + react.h4({'key': 'callback-child-h4'}, 'ChildComponent'), react.form({ 'key': 'childComponentForm', 'className': 'form-inline' }, [ ChildComponent({ 'key': 'callback-child', - "ref": (instance) => _childCallbackRef = instance, + 'ref': (instance) => _childCallbackRef = instance, }), '\u00a0', react.button({ @@ -212,8 +212,8 @@ class _ParentComponent extends react.Component { react.div({ 'key': 'forward-refs' }, [ - react.h2({'key': 'h2-forward'}, "Create / Forward refs"), - react.h4({'key': 'h4-forward-input'}, ""), + react.h2({'key': 'h2-forward'}, 'Create / Forward refs'), + react.h4({'key': 'h4-forward-input'}, ''), InputComponentForm({ 'ref': _inputCreateRef, 'showInputForwardRefValue': showInputCreateRefValue, diff --git a/example/test/speed_test.dart b/example/test/speed_test.dart index 5b41fe1d..c4e528eb 100644 --- a/example/test/speed_test.dart +++ b/example/test/speed_test.dart @@ -1,13 +1,13 @@ // ignore_for_file: deprecated_member_use_from_same_package -import "dart:html"; -import "dart:async"; +import 'dart:html'; +import 'dart:async'; -import "package:react/react.dart" as react; -import "package:react/react_dom.dart" as react_dom; +import 'package:react/react.dart' as react; +import 'package:react/react_dom.dart' as react_dom; Stopwatch stopwatch = Stopwatch()..start(); timeprint(message) { - print("$message ${stopwatch.elapsedMilliseconds}"); + print('$message ${stopwatch.elapsedMilliseconds}'); stopwatch.reset(); } @@ -46,7 +46,7 @@ class _Hello extends react.Component { } render() { - timeprint("rendering start"); + timeprint('rendering start'); var data = props['data']; var children = []; for (var elem in data) { @@ -54,7 +54,7 @@ class _Hello extends react.Component { 'key': elem[0] }, [ react.span({'key': 'span1'}, elem[0]), - " ", + ' ', react.span({'key': 'span2'}, elem[1]) ])); } @@ -65,9 +65,9 @@ class _Hello extends react.Component { // react.span({}, elem[1]) // ])) // ); - timeprint("rendering almost ends"); + timeprint('rendering almost ends'); var res = react.div({}, children); - timeprint("rendering ends"); + timeprint('rendering ends'); return res; } } @@ -77,7 +77,7 @@ var Hello = react.registerComponent(() => _Hello()); void main() { var data = []; for (num i = 0; i < 1000; i++) { - data.add(["name_$i", "value_$i"]); + data.add(['name_$i', 'value_$i']); } - react_dom.render(Hello({"data": data}, []), querySelector('#content')); + react_dom.render(Hello({'data': data}, []), querySelector('#content')); } diff --git a/example/test/unmount_test.dart b/example/test/unmount_test.dart index 596891cf..9d4d7266 100644 --- a/example/test/unmount_test.dart +++ b/example/test/unmount_test.dart @@ -1,23 +1,23 @@ // ignore_for_file: deprecated_member_use_from_same_package -import "dart:html"; +import 'dart:html'; -import "package:react/react.dart" as react; -import "package:react/react_dom.dart" as react_dom; +import 'package:react/react.dart' as react; +import 'package:react/react_dom.dart' as react_dom; var simpleComponent = react.registerComponent(() => SimpleComponent()); class SimpleComponent extends react.Component { - componentWillMount() => print("mount"); + componentWillMount() => print('mount'); - componentWillUnmount() => print("unmount"); + componentWillUnmount() => print('unmount'); render() => react.div({}, [ - "Simple component", + 'Simple component', ]); } void main() { - print("What"); + print('What'); var mountedNode = querySelector('#content'); querySelector('#mount').onClick.listen((_) => react_dom.render(simpleComponent({}), mountedNode)); diff --git a/lib/react_client/js_interop_helpers.dart b/lib/react_client/js_interop_helpers.dart index 4989c6ca..7eeb438c 100644 --- a/lib/react_client/js_interop_helpers.dart +++ b/lib/react_client/js_interop_helpers.dart @@ -4,9 +4,9 @@ library react_client.js_interop_helpers; import 'dart:collection'; -import "dart:js_util"; +import 'dart:js_util'; -import "package:js/js.dart"; +import 'package:js/js.dart'; import 'js_backed_map.dart'; diff --git a/lib/src/react_client/component_registration.dart b/lib/src/react_client/component_registration.dart index 3e1b9ea4..75204b49 100644 --- a/lib/src/react_client/component_registration.dart +++ b/lib/src/react_client/component_registration.dart @@ -39,10 +39,10 @@ List _filterSkipMethods(Iterable methods) { } if (shouldWarn) { - window.console.warn("WARNING: Crucial lifecycle methods passed into " - "skipMethods. shouldComponentUpdate, componentDidUpdate, and render " - "cannot be skipped and will still be added to the new component. Please " - "remove them from skipMethods."); + window.console.warn('WARNING: Crucial lifecycle methods passed into ' + 'skipMethods. shouldComponentUpdate, componentDidUpdate, and render ' + 'cannot be skipped and will still be added to the new component. Please ' + 'remove them from skipMethods.'); } return finalList; diff --git a/test/hooks_test.dart b/test/hooks_test.dart index 360eb077..fce73534 100644 --- a/test/hooks_test.dart +++ b/test/hooks_test.dart @@ -4,7 +4,7 @@ library hooks_test; import 'dart:html'; -import "package:js/js.dart"; +import 'package:js/js.dart'; import 'package:react/hooks.dart'; import 'package:react/react.dart' as react; import 'package:react/react.dart'; diff --git a/test/js_builds/shared_tests.dart b/test/js_builds/shared_tests.dart index d0c2df41..e8b4592f 100644 --- a/test/js_builds/shared_tests.dart +++ b/test/js_builds/shared_tests.dart @@ -88,7 +88,7 @@ void sharedConsoleWarnTests({@required bool expectDeduplicateSyntheticEventWarni void triggerRealDdcSyntheticEventWarning() { if (T == react.SyntheticEvent) { - throw ArgumentError("T must a subclass of SyntheticEvent, not SyntheticEvent itself, for this to reproduce."); + throw ArgumentError('T must a subclass of SyntheticEvent, not SyntheticEvent itself, for this to reproduce.'); } // Adapted from reduced test case in https://github.com/dart-lang/sdk/issues/43939 diff --git a/test/lifecycle_test.dart b/test/lifecycle_test.dart index 19de3ed8..c80ba4a1 100644 --- a/test/lifecycle_test.dart +++ b/test/lifecycle_test.dart @@ -8,7 +8,7 @@ import 'dart:convert'; import 'dart:html'; import 'dart:js'; -import "package:js/js.dart"; +import 'package:js/js.dart'; import 'package:meta/meta.dart'; import 'package:react/react.dart' as react; import 'package:react/react_client.dart'; @@ -337,7 +337,7 @@ main() { var renderedInstance = react_dom.render(components2.SetStateTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); LifecycleTestHelper.staticLifecycleCalls.clear(); - component.setState({"shouldThrow": true}); + component.setState({'shouldThrow': true}); // First render throws an error, caught by `getDerivedStateFromError`. // `getDerivedStateFromError` sets state, starting the update cycle @@ -362,7 +362,7 @@ main() { 'getSnapshotBeforeUpdate', 'componentDidUpdate' ])); - expect(component.state["shouldThrow"], isFalse, + expect(component.state['shouldThrow'], isFalse, reason: 'applies the state returned by `getDerivedStateFromError`'); }); @@ -377,7 +377,7 @@ main() { 'render': (_) { if (_shouldThrow) { _shouldThrow = false; - return components2.ErrorComponent({"key": "errorComp"}); + return components2.ErrorComponent({'key': 'errorComp'}); } return react.div({}); } @@ -412,7 +412,7 @@ main() { 'render': (_) { if (_shouldThrow) { _shouldThrow = false; - return components2.ErrorComponent({"key": "errorComp"}); + return components2.ErrorComponent({'key': 'errorComp'}); } return react.div({}); } @@ -445,7 +445,7 @@ main() { var renderedInstance = react_dom.render(components2.SetStateTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); LifecycleTestHelper.staticLifecycleCalls.clear(); - component.setState({"shouldThrow": true}); + component.setState({'shouldThrow': true}); expect( component.lifecycleCalls, @@ -454,7 +454,7 @@ main() { args: [isA(), isA()]), matchCall('getDerivedStateFromError', args: [isA()]), ])); - expect(component.state["shouldThrow"], isFalse, + expect(component.state['shouldThrow'], isFalse, reason: 'applies the state returned by `getDerivedStateFromError`'); }); @@ -463,7 +463,7 @@ main() { var renderedInstance = react_dom.render(components2.SkipMethodsTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); LifecycleTestHelper.staticLifecycleCalls.clear(); - component.setState({"shouldThrow": true}); + component.setState({'shouldThrow': true}); expect( component.lifecycleCallMemberNames, @@ -491,7 +491,7 @@ main() { LifecycleTestHelper component = getDartComponent(renderedInstance); Element renderedNode = react_dom.findDOMNode(renderedInstance); LifecycleTestHelper.staticLifecycleCalls.clear(); - component.setState({"shouldThrow": true}); + component.setState({'shouldThrow': true}); expect(renderedNode.children[1].text, contains(getComponent2ErrorMessage())); // Because the stacktrace will be different between JS and Dart, in @@ -511,7 +511,7 @@ main() { var renderedInstance = react_dom.render(components2.DefaultSkipMethodsTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); LifecycleTestHelper.staticLifecycleCalls.clear(); - component.setState({"shouldThrow": true}); + component.setState({'shouldThrow': true}); }, throwsA(anything)); }); }); diff --git a/test/lifecycle_test/component.dart b/test/lifecycle_test/component.dart index eac23854..73bff9f4 100644 --- a/test/lifecycle_test/component.dart +++ b/test/lifecycle_test/component.dart @@ -2,7 +2,7 @@ @JS() library react.lifecycle_test.component; -import "package:js/js.dart"; +import 'package:js/js.dart'; import 'package:react/react.dart' as react; import 'package:react/react_client.dart'; @@ -15,7 +15,7 @@ class _SetStateTest extends react.Component with LifecycleTestHelper { Map getDefaultProps() => {'shouldUpdate': true}; @override - getInitialState() => {"counter": 1}; + getInitialState() => {'counter': 1}; @override componentWillReceiveProps(_) { diff --git a/test/lifecycle_test/component2.dart b/test/lifecycle_test/component2.dart index 583c313b..56b3103b 100644 --- a/test/lifecycle_test/component2.dart +++ b/test/lifecycle_test/component2.dart @@ -2,7 +2,7 @@ @JS() library react.lifecycle_test.component2; -import "package:js/js.dart"; +import 'package:js/js.dart'; import 'package:react/react.dart' as react; import 'package:react/react_client/react_interop.dart'; @@ -58,7 +58,7 @@ class _SetStateTest extends react.Component2 with LifecycleTestHelper { @override Map getDerivedStateFromError(error) { lifecycleCall('getDerivedStateFromError', arguments: [error]); - return {"shouldThrow": false, "errorFromGetDerivedState": error}; + return {'shouldThrow': false, 'errorFromGetDerivedState': error}; } Map outerTransactionalSetStateCallback(Map previousState, __) { @@ -110,7 +110,7 @@ class _SetStateTest extends react.Component2 with LifecycleTestHelper { }); } }, [ - state["shouldThrow"] ? ErrorComponent({"key": "errorComp"}) : null, + state['shouldThrow'] ? ErrorComponent({'key': 'errorComp'}) : null, state['counter'] ])); } @@ -205,12 +205,12 @@ class TestDartException implements Exception { class _ErrorComponent extends react.Component2 { void _throwError() { - throw TestDartException("It crashed!", 100); + throw TestDartException('It crashed!', 100); } void render() { _throwError(); - return react.div({'key': 'defaultMessage'}, "Error"); + return react.div({'key': 'defaultMessage'}, 'Error'); } } diff --git a/test/react_test_utils_test.dart b/test/react_test_utils_test.dart index e0cf8336..cbe62d26 100644 --- a/test/react_test_utils_test.dart +++ b/test/react_test_utils_test.dart @@ -107,7 +107,7 @@ testUtils({isComponent2: false, dynamic eventComponent, dynamic sampleComponent, eventHandlerName: (e) { capturedEvent = e; }, - "ref": (r) => ref = r, + 'ref': (r) => ref = r, })); event(ref, eventData); From 5d2793d513ea3a72ba276080c5d718c24e51e0b8 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 15:13:27 -0700 Subject: [PATCH 05/31] dart fix --apply --code=deprecated_colon_for_default_value --- lib/react_client/component_factory.dart | 10 +++++----- test/lifecycle_test/util.dart | 4 ++-- test/react_test_utils_test.dart | 2 +- test/shared_type_tester.dart | 22 +++++++++++----------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/react_client/component_factory.dart b/lib/react_client/component_factory.dart index 86572777..2f5d6d47 100644 --- a/lib/react_client/component_factory.dart +++ b/lib/react_client/component_factory.dart @@ -204,9 +204,9 @@ class ReactJsContextComponentFactoryProxy extends ReactJsComponentFactoryProxy { ReactJsContextComponentFactoryProxy( ReactClass jsClass, { - this.shouldConvertDomProps: true, - this.isConsumer: false, - this.isProvider: false, + this.shouldConvertDomProps = true, + this.isConsumer = false, + this.isProvider = false, }) : this.type = jsClass, super(jsClass, shouldConvertDomProps: shouldConvertDomProps); @@ -261,8 +261,8 @@ class ReactJsComponentFactoryProxy extends ReactComponentFactoryProxy { ReactJsComponentFactoryProxy( ReactClass jsClass, { - this.shouldConvertDomProps: true, - this.alwaysReturnChildrenAsList: false, + this.shouldConvertDomProps = true, + this.alwaysReturnChildrenAsList = false, List additionalRefPropKeys = const [], }) : this.type = jsClass, this._additionalRefPropKeys = additionalRefPropKeys { diff --git a/test/lifecycle_test/util.dart b/test/lifecycle_test/util.dart index c646de3d..02afc5e2 100644 --- a/test/lifecycle_test/util.dart +++ b/test/lifecycle_test/util.dart @@ -5,7 +5,7 @@ import 'package:react/react.dart'; const Map defaultProps = {'defaultProp': 'default'}; const Map emptyChildrenProps = {'children': []}; -Map matchCall(String memberName, {args: anything, props: anything, state: anything, context: anything}) { +Map matchCall(String memberName, {args = anything, props = anything, state = anything, context = anything}) { return { 'memberName': memberName, 'arguments': args, @@ -31,7 +31,7 @@ mixin LifecycleTestHelper on Component { return call['memberName']; }).toList(); - dynamic lifecycleCall(String memberName, {List arguments: const [], defaultReturnValue(), Map staticProps}) { + dynamic lifecycleCall(String memberName, {List arguments = const [], defaultReturnValue(), Map staticProps}) { lifecycleCalls.add({ 'memberName': memberName, 'arguments': arguments, diff --git a/test/react_test_utils_test.dart b/test/react_test_utils_test.dart index cbe62d26..117c4e25 100644 --- a/test/react_test_utils_test.dart +++ b/test/react_test_utils_test.dart @@ -28,7 +28,7 @@ void main() { wrapperComponent: component2.wrapperComponent); } -testUtils({isComponent2: false, dynamic eventComponent, dynamic sampleComponent, dynamic wrapperComponent}) { +testUtils({isComponent2 = false, dynamic eventComponent, dynamic sampleComponent, dynamic wrapperComponent}) { var component; Element domNode; diff --git a/test/shared_type_tester.dart b/test/shared_type_tester.dart index f6ed3582..fe69e0eb 100644 --- a/test/shared_type_tester.dart +++ b/test/shared_type_tester.dart @@ -10,17 +10,17 @@ import 'package:test/test.dart'; void sharedTypeTests( void Function(dynamic value) testTypeValue, { - bool skipNormalDartObjects: false, - bool skipDartMaps: false, - bool skipPrimitives: false, - bool skipNumTypes: false, - bool skipFunctions: false, - bool skipBrowserObjects: false, - bool skipLists: false, - bool skipDatetimes: false, - bool skipFutures: false, - bool skipJsAnonInteropTypes: false, - bool skipJsInteropTypes: true, + bool skipNormalDartObjects = false, + bool skipDartMaps = false, + bool skipPrimitives = false, + bool skipNumTypes = false, + bool skipFunctions = false, + bool skipBrowserObjects = false, + bool skipLists = false, + bool skipDatetimes = false, + bool skipFutures = false, + bool skipJsAnonInteropTypes = false, + bool skipJsInteropTypes = true, }) { if (!skipNormalDartObjects) { test('normal Dart objects', () { From d19f23d689e3da30931f0eca9fada6b86a9c60c3 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 15:14:50 -0700 Subject: [PATCH 06/31] dart fix --apply --code=annotate_overrides --- example/js_components/js_components.dart | 2 + example/test/call_and_nosuchmethod_test.dart | 1 + example/test/false_and_null_test.dart | 1 + example/test/function_component_test.dart | 2 + example/test/get_dom_node_test.dart | 5 +++ example/test/order_test.dart | 4 ++ example/test/react_test_components.dart | 39 ++++++++++++++++++++ example/test/ref_test.dart | 2 + example/test/speed_test.dart | 6 +++ example/test/unmount_test.dart | 3 ++ lib/react.dart | 15 ++++++++ lib/react_client/component_factory.dart | 4 ++ test/hooks_test.dart | 2 + test/lifecycle_test/component.dart | 21 +++++++++++ test/lifecycle_test/component2.dart | 33 +++++++++++++++++ test/react_client_test.dart | 2 + test/react_context_test.dart | 5 +++ test/react_fragment_test.dart | 1 + test/react_memo_test.dart | 1 + test/test_components.dart | 4 ++ test/test_components2.dart | 4 ++ 21 files changed, 157 insertions(+) diff --git a/example/js_components/js_components.dart b/example/js_components/js_components.dart index af3d2281..19237b7b 100644 --- a/example/js_components/js_components.dart +++ b/example/js_components/js_components.dart @@ -20,6 +20,7 @@ var IndexComponent = react.registerComponent2(() => _IndexComponent()); class _IndexComponent extends react.Component2 { SimpleCustomComponent simpleRef; + @override get initialState => { 'open': false, }; @@ -37,6 +38,7 @@ class _IndexComponent extends react.Component2 { print(simpleRef.getFoo()); } + @override render() { return MuiThemeProvider( { diff --git a/example/test/call_and_nosuchmethod_test.dart b/example/test/call_and_nosuchmethod_test.dart index 8fa34262..6c379b65 100644 --- a/example/test/call_and_nosuchmethod_test.dart +++ b/example/test/call_and_nosuchmethod_test.dart @@ -5,6 +5,7 @@ import 'package:react/react_dom.dart' as react_dom; import 'package:react/react.dart' as react; class _CustomComponent extends react.Component { + @override render() { return react.div({}, props['children']); } diff --git a/example/test/false_and_null_test.dart b/example/test/false_and_null_test.dart index 5aaafd3c..d562a442 100644 --- a/example/test/false_and_null_test.dart +++ b/example/test/false_and_null_test.dart @@ -5,6 +5,7 @@ import 'package:react/react.dart' as react; import 'package:react/react_dom.dart' as react_dom; class _Component extends react.Component { + @override render() { if (props['hardCodedNullReturn'] == true) { return null; diff --git a/example/test/function_component_test.dart b/example/test/function_component_test.dart index b0327b7c..33b7e24b 100644 --- a/example/test/function_component_test.dart +++ b/example/test/function_component_test.dart @@ -190,8 +190,10 @@ var TestNewContext = react.createContext({'renderCount': 0}, calculateChang var newContextProviderComponent = react.registerComponent2(() => _NewContextProviderComponent()); class _NewContextProviderComponent extends react.Component2 { + @override get initialState => {'renderCount': 0, 'complexMap': false}; + @override render() { final provideMap = {'renderCount': this.state['renderCount']}; diff --git a/example/test/get_dom_node_test.dart b/example/test/get_dom_node_test.dart index 4d2e405d..df1ef374 100644 --- a/example/test/get_dom_node_test.dart +++ b/example/test/get_dom_node_test.dart @@ -16,6 +16,7 @@ var ChildComponent = react.registerComponent(() => _ChildComponent()); class _ChildComponent extends react.Component { var counter = 0; + @override render() => react.div({}, [ 'Test element', counter.toString(), @@ -37,10 +38,13 @@ class SimpleComponent extends react.Component { var refToSpan; var refToElement; + @override componentWillMount() => print('mount'); + @override componentWillUnmount() => print('unmount'); + @override componentDidMount() { customAssert('ref to span return span ', refToSpan.text == 'Test'); customAssert('findDOMNode works on this', react_dom.findDOMNode(this) != null); @@ -49,6 +53,7 @@ class SimpleComponent extends react.Component { var counter = 0; + @override render() => react.div({}, [ react.span({ 'key': 'span1', diff --git a/example/test/order_test.dart b/example/test/order_test.dart index e06596e0..d8cc5c65 100644 --- a/example/test/order_test.dart +++ b/example/test/order_test.dart @@ -5,15 +5,18 @@ import 'package:react/react.dart' as react; import 'package:react/react_dom.dart' as react_dom; class _Item extends react.Component { + @override componentWillReceiveProps(newProps) { print('Old props: $props'); print('New props: $newProps'); } + @override shouldComponentUpdate(nextProps, nextState) { return false; } + @override render() { return react.li({}, [props['text']]); } @@ -29,6 +32,7 @@ class _List extends react.Component { redraw(); } + @override render() { return react.ul({'onClick': (e) => remove()}, items.map((text) => item({'text': text, 'key': text}))); } diff --git a/example/test/react_test_components.dart b/example/test/react_test_components.dart index 88932891..785b7857 100644 --- a/example/test/react_test_components.dart +++ b/example/test/react_test_components.dart @@ -16,6 +16,7 @@ class _HelloComponent extends react.Component2 { }, }; + @override render() { return react.span({}, ["Hello ${props['name']}!"]); } @@ -25,6 +26,7 @@ var helloComponent = react.registerComponent(() => _HelloComponent()); class _HelloGreeter extends react.Component { var myInput; + @override getInitialState() => {'name': 'World'}; onInputChange(e) { @@ -33,6 +35,7 @@ class _HelloGreeter extends react.Component { setState({'name': e.target.value}); } + @override render() { return react.div({}, [ react.input({ @@ -50,12 +53,14 @@ class _HelloGreeter extends react.Component { var helloGreeter = react.registerComponent(() => _HelloGreeter()); class _CheckBoxComponent extends react.Component { + @override getInitialState() => {'checked': false}; _handleChange(e) { this.setState({'checked': e.target.checked}); } + @override render() { return react.div({ 'className': 'form-check' @@ -82,29 +87,36 @@ var checkBoxComponent = react.registerComponent(() => _CheckBoxComponent()); class _ClockComponent extends react.Component { Timer timer; + @override getInitialState() => {'secondsElapsed': 0}; + @override Map getDefaultProps() => {'refreshRate': 1000}; + @override void componentWillMount() { timer = Timer.periodic(Duration(milliseconds: this.props['refreshRate']), this.tick); } + @override void componentWillUnmount() { timer.cancel(); } + @override void componentDidMount() { var rootNode = react_dom.findDOMNode(this); rootNode.style.backgroundColor = '#FFAAAA'; } + @override bool shouldComponentUpdate(nextProps, nextState) { //print("Next state: $nextState, props: $nextProps"); //print("Old state: $state, props: $props"); return nextState['secondsElapsed'] % 2 == 1; } + @override void componentWillReceiveProps(nextProps) { print('Received props: $nextProps'); } @@ -113,6 +125,7 @@ class _ClockComponent extends react.Component { setState({'secondsElapsed': state['secondsElapsed'] + 1}); } + @override render() { return react.span({'onClick': (event) => print('Hello World!')}, // { 'onClick': (event, [domid = null]) => print("Hello World!") }, @@ -123,18 +136,21 @@ class _ClockComponent extends react.Component { var clockComponent = react.registerComponent(() => _ClockComponent()); class _ListComponent extends react.Component { + @override Map getInitialState() { return { 'items': List.from([0, 1, 2, 3]) }; } + @override void componentWillUpdate(nextProps, nextState) { if (nextState['items'].length > state['items'].length) { print('Adding ' + nextState['items'].last.toString()); } } + @override void componentDidUpdate(prevProps, prevState) { if (prevState['items'].length > state['items'].length) { print('Removed ' + prevState['items'].first.toString()); @@ -149,6 +165,7 @@ class _ListComponent extends react.Component { setState({'items': items}); } + @override dynamic render() { List items = []; for (var item in state['items']) { @@ -170,6 +187,7 @@ class _ListComponent extends react.Component { var listComponent = react.registerComponent(() => _ListComponent()); class _MainComponent extends react.Component { + @override render() { return react.div({}, props['children']); } @@ -191,6 +209,7 @@ class _LegacyContextComponent extends react.Component { 'renderCount': this.state['renderCount'] }; + @override render() { return react.ul({ 'key': 'ul' @@ -216,6 +235,7 @@ class _LegacyContextConsumerComponent extends react.Component { @override Iterable get contextKeys => const ['foo']; + @override render() { return react.ul({ 'key': 'ul' @@ -235,6 +255,7 @@ class _GrandchildLegacyContextConsumerComponent extends react.Component { @override Iterable get contextKeys => const ['renderCount']; + @override render() { return react.ul({ 'key': 'ul' @@ -252,6 +273,7 @@ var grandchildLegacyContextConsumerComponent = // REACT NEW CONTEXT COMPONENTS //// class _NewContextRefComponent extends react.Component2 { + @override render() { return react.div({}, props['children']); } @@ -276,12 +298,14 @@ var TestNewContext = react.createContext({'renderCount': 0}, calculateChang class _NewContextProviderComponent extends react.Component2 { _NewContextRefComponent componentRef; + @override get initialState => {'renderCount': 0, 'complexMap': false}; printMe() { print('printMe!'); } + @override render() { final provideMap = {'renderCount': this.state['renderCount']}; @@ -345,6 +369,7 @@ class _NewContextProviderComponent extends react.Component2 { var newContextProviderComponent = react.registerComponent(() => _NewContextProviderComponent()); class _NewContextConsumerComponent extends react.Component2 { + @override render() { return TestNewContext.Consumer({'unstable_observedBits': props['unstable_observedBits']}, (value) { return react.ul({ @@ -362,6 +387,7 @@ class _NewContextConsumerComponent extends react.Component2 { var newContextConsumerComponent = react.registerComponent(() => _NewContextConsumerComponent()); class _NewContextConsumerObservedBitsComponent extends react.Component2 { + @override render() { return TestNewContext.Consumer({'unstable_observedBits': props['unstable_observedBits']}, (value) { return react.ul({ @@ -383,6 +409,7 @@ class _NewContextTypeConsumerComponent extends react.Component2 { @override final contextType = TestNewContext; + @override render() { this.context['componentRef']?.test(); return react.ul({ @@ -394,10 +421,13 @@ class _NewContextTypeConsumerComponent extends react.Component2 { } class _Component2TestComponent extends react.Component2 with react.TypedSnapshot { + @override get defaultProps => {'defaultProp': true}; + @override get initialState => {'defaultState': true, 'items': []}; + @override Map getDerivedStateFromProps(nextProps, prevState) { final prevItems = prevState['items']; if (prevItems.isEmpty || prevItems[0] != 3) { @@ -408,6 +438,7 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot return null; } + @override String getSnapshotBeforeUpdate(nextProps, prevState) { if (prevState['items'].length > state['items'].length) { return 'removed ' + prevState['items'].last.toString(); @@ -416,6 +447,7 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot } } + @override void componentDidUpdate(prevProps, prevState, [String snapshot]) { if (snapshot != null) { print('Updated DOM and ' + snapshot); @@ -436,6 +468,7 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot setState({'items': items}); } + @override dynamic render() { // Used to generate unique keys even when the list contains duplicate items final itemCounts = {}; @@ -467,12 +500,14 @@ var newContextTypeConsumerComponentComponent = react.registerComponent(() => _Ne var component2TestComponent = react.registerComponent(() => _Component2TestComponent()); class _ErrorComponent extends react.Component2 { + @override void componentDidMount() { if (!props['errored']) { throw _CustomException('It broke!', 2); } } + @override dynamic render() { return react.div( {'key': 'eb-d1-e'}, @@ -503,12 +538,14 @@ class _CustomException implements Exception { } class _Component2ErrorTestComponent extends react.Component2 { + @override Map get initialState => { 'clicked': false, 'errored': false, 'error': null, }; + @override void componentDidCatch(error, info) { if (error is _CustomException) { print(info.dartStackTrace); @@ -521,6 +558,7 @@ class _Component2ErrorTestComponent extends react.Component2 { } } + @override Map getDerivedStateFromError(error) { return {'errored': true}; } @@ -533,6 +571,7 @@ class _Component2ErrorTestComponent extends react.Component2 { setState({'clicked': false, 'error': null, 'errored': false}); } + @override dynamic render() { dynamic errorMessage = state['error'] ?? 'No error yet'; diff --git a/example/test/ref_test.dart b/example/test/ref_test.dart index 22b478e2..8100052a 100644 --- a/example/test/ref_test.dart +++ b/example/test/ref_test.dart @@ -14,6 +14,7 @@ class _ChildComponent extends react.Component { redraw(); } + @override render() => react.span({}, 'Child element with value ${somevalue}'); } @@ -116,6 +117,7 @@ class _ParentComponent extends react.Component { _childCreateRef.current.incrementValue(); } + @override render() => react.div({}, [ react.h1({'key': 'h1'}, 'Refs'), react.div({ diff --git a/example/test/speed_test.dart b/example/test/speed_test.dart index c4e528eb..62a0e4b4 100644 --- a/example/test/speed_test.dart +++ b/example/test/speed_test.dart @@ -12,10 +12,12 @@ timeprint(message) { } class _Div extends react.Component { + @override shouldComponentUpdate(nProps, nState) { return nProps['key'] != props['key']; } + @override render() { return react.div(props, props['children']); } @@ -24,10 +26,12 @@ class _Div extends react.Component { var Div = react.registerComponent(() => _Div()); class _Span extends react.Component { + @override shouldComponentUpdate(nProps, nState) { return nProps['children'][0] != props['children'][0]; } + @override render() { return react.span(props, props['children']); } @@ -36,6 +40,7 @@ class _Span extends react.Component { var Span = react.registerComponent(() => _Span()); class _Hello extends react.Component { + @override componentWillMount() { Future.delayed(Duration(seconds: 5), () { stopwatch.reset(); @@ -45,6 +50,7 @@ class _Hello extends react.Component { }); } + @override render() { timeprint('rendering start'); var data = props['data']; diff --git a/example/test/unmount_test.dart b/example/test/unmount_test.dart index 9d4d7266..7c448593 100644 --- a/example/test/unmount_test.dart +++ b/example/test/unmount_test.dart @@ -7,10 +7,13 @@ import 'package:react/react_dom.dart' as react_dom; var simpleComponent = react.registerComponent(() => SimpleComponent()); class SimpleComponent extends react.Component { + @override componentWillMount() => print('mount'); + @override componentWillUnmount() => print('unmount'); + @override render() => react.div({}, [ 'Simple component', ]); diff --git a/lib/react.dart b/lib/react.dart index e518ef1b..587775b0 100644 --- a/lib/react.dart +++ b/lib/react.dart @@ -677,6 +677,7 @@ abstract class Component2 implements Component { /// /// This will result in the dart2js name being `ReactDartComponent2` (the /// name of the proxying JS component defined in _dart_helpers.js). + @override String get displayName { var value; assert(() { @@ -695,6 +696,7 @@ abstract class Component2 implements Component { /// To use a transactional `setState` callback, check out [setStateWithUpdater]. /// /// See: + @override void setState(Map newState, [SetStateCallback callback]) { _bridge.setState(this, newState, callback); } @@ -724,6 +726,7 @@ abstract class Component2 implements Component { /// The [componentDidMount] method of child `Component`s is invoked _before_ that of parent `Component`. /// /// See: + @override void componentDidMount() {} /// ReactJS lifecycle method that is invoked before rendering when new props ([nextProps]) are received. @@ -771,6 +774,7 @@ abstract class Component2 implements Component { /// will not require a component update. /// /// See: + @override bool shouldComponentUpdate(Map nextProps, Map nextState) => true; /// ReactJS lifecycle method that is invoked immediately after re-rendering @@ -828,6 +832,7 @@ abstract class Component2 implements Component { /// parameter in `componentDidUpdate` will be null. /// /// See: + @override void componentDidUpdate(Map prevProps, Map prevState, [dynamic snapshot]) {} /// ReactJS lifecycle method that is invoked immediately before a `Component` is unmounted from the DOM. @@ -836,6 +841,7 @@ abstract class Component2 implements Component { /// were created in [componentDidMount]. /// /// See: + @override void componentWillUnmount() {} /// ReactJS lifecycle method that is invoked after an [error] is thrown by a descendant. @@ -930,6 +936,7 @@ abstract class Component2 implements Component { /// or the other lifecycle methods instead. Keeping `render` pure makes components easier to think about. /// /// See: + @override dynamic render(); // ****************************************************************************************************************** @@ -971,6 +978,7 @@ abstract class Component2 implements Component { /// > __DEPRECATED - DO NOT USE__ /// > /// > Use the [initialState] getter instead. + @override @mustCallSuper @Deprecated('7.0.0') Map getInitialState() => throw _unsupportedLifecycleError('getInitialState'); @@ -986,6 +994,7 @@ abstract class Component2 implements Component { /// > __DEPRECATED - DO NOT USE__ /// > /// > Use the [defaultProps] getter instead. + @override @mustCallSuper @Deprecated('7.0.0') Map getDefaultProps() => throw _unsupportedLifecycleError('getDefaultProps'); @@ -995,6 +1004,7 @@ abstract class Component2 implements Component { /// > __DEPRECATED - DO NOT USE__ /// > /// > Use [componentDidMount] instead + @override @mustCallSuper @Deprecated('7.0.0') void componentWillMount() => throw _unsupportedLifecycleError('componentWillMount'); @@ -1052,6 +1062,7 @@ abstract class Component2 implements Component { /// /// // NOTE: You could also return a `snapshot` value from this method for later use in `componentDidUpdate`. /// } + @override @mustCallSuper @Deprecated('7.0.0') void componentWillReceiveProps(Map nextProps) => throw _unsupportedLifecycleError('componentWillReceiveProps'); @@ -1094,6 +1105,7 @@ abstract class Component2 implements Component { /// /// // NOTE: You could also return a `snapshot` value from this method for later use in `componentDidUpdate`. /// } + @override @mustCallSuper @Deprecated('7.0.0') void componentWillUpdate(Map nextProps, Map nextState) => throw _unsupportedLifecycleError('componentWillUpdate'); @@ -1210,6 +1222,7 @@ abstract class Component2 implements Component { @override @Deprecated('7.0.0') Map get prevState => throw _unsupportedError('"Legacy" Context [prevContext]'); + @override set prevState(_) => throw _unsupportedError('"Legacy" Context [prevContext]'); /// Do not use. @@ -1225,6 +1238,7 @@ abstract class Component2 implements Component { @override @Deprecated('7.0.0') Map get nextProps => throw _unsupportedError('nextProps'); + @override set nextProps(_) => throw _unsupportedError('nextProps'); /// Do not use. @@ -1240,6 +1254,7 @@ abstract class Component2 implements Component { @override @Deprecated('7.0.0') RefMethod get ref => throw _unsupportedError('ref'); + @override set ref(_) => throw _unsupportedError('ref'); /// Do not use. diff --git a/lib/react_client/component_factory.dart b/lib/react_client/component_factory.dart index 2f5d6d47..1c36950d 100644 --- a/lib/react_client/component_factory.dart +++ b/lib/react_client/component_factory.dart @@ -95,6 +95,7 @@ class ReactDartComponentFactoryProxy extends React @override ReactClass get type => reactClass; + @override ReactElement build(Map props, [List childrenArgs = const []]) { var children = convertArgsToChildren(childrenArgs); children = listifyChildren(children); @@ -175,8 +176,10 @@ class ReactDartComponentFactoryProxy2 extends Rea ReactDartComponentFactoryProxy { /// The ReactJS class used as the type for all [ReactElement]s built by /// this factory. + @override final ReactClass reactClass; + @override final Map defaultProps; ReactDartComponentFactoryProxy2(ReactClass reactClass) @@ -200,6 +203,7 @@ class ReactJsContextComponentFactoryProxy extends ReactJsComponentFactoryProxy { final ReactClass type; final bool isConsumer; final bool isProvider; + @override final bool shouldConvertDomProps; ReactJsContextComponentFactoryProxy( diff --git a/test/hooks_test.dart b/test/hooks_test.dart index fce73534..8841cd98 100644 --- a/test/hooks_test.dart +++ b/test/hooks_test.dart @@ -850,6 +850,7 @@ main() { ReactDartComponentFactoryProxy2 ContextProviderWrapper = react.registerComponent2(() => _ContextProviderWrapper()); class _ContextProviderWrapper extends react.Component2 { + @override get initialState { return {'counter': 1}; } @@ -858,6 +859,7 @@ class _ContextProviderWrapper extends react.Component2 { this.setState({'counter': state['counter'] + 1}); } + @override render() { return react.div({}, [ props['contextToUse'] diff --git a/test/lifecycle_test/component.dart b/test/lifecycle_test/component.dart index 73bff9f4..83a310fa 100644 --- a/test/lifecycle_test/component.dart +++ b/test/lifecycle_test/component.dart @@ -58,6 +58,7 @@ class _SetStateTest extends react.Component with LifecycleTestHelper { lifecycleCalls.add(name); } + @override render() { recordLifecyleCall('render'); @@ -85,16 +86,19 @@ _DefaultPropsCachingTest defaultPropsCachingTestComponentFactory() => _DefaultPr class _DefaultPropsCachingTest extends react.Component implements DefaultPropsCachingTestHelper { static int getDefaultPropsCallCount = 0; + @override int get staticGetDefaultPropsCallCount => getDefaultPropsCallCount; @override set staticGetDefaultPropsCallCount(int value) => getDefaultPropsCallCount = value; + @override Map getDefaultProps() { getDefaultPropsCallCount++; return {'getDefaultPropsCallCount': getDefaultPropsCallCount}; } + @override render() => false; } @@ -107,8 +111,10 @@ class _DefaultPropsTest extends react.Component { /// class is not known. int get staticGetDefaultPropsCallCount => getDefaultPropsCallCount; + @override Map getDefaultProps() => {'defaultProp': 'default'}; + @override render() => false; } @@ -128,6 +134,7 @@ class _ContextWrapperWithoutKeys extends react.Component with LifecycleTestHelpe }; } + @override dynamic render() => react.div({}, props['children']); } @@ -146,6 +153,7 @@ class _ContextWrapper extends react.Component with LifecycleTestHelper { }; } + @override dynamic render() => react.div({}, props['children']); } @@ -160,39 +168,52 @@ class _LifecycleTestWithContext extends _LifecycleTest { ReactDartComponentFactoryProxy LifecycleTest = react.registerComponent(() => _LifecycleTest()); class _LifecycleTest extends react.Component with LifecycleTestHelper { + @override void componentWillMount() => lifecycleCall('componentWillMount'); + @override void componentDidMount() => lifecycleCall('componentDidMount'); + @override void componentWillUnmount() => lifecycleCall('componentWillUnmount'); + @override void componentWillReceiveProps(newProps) => lifecycleCall('componentWillReceiveProps', arguments: [Map.from(newProps)]); + @override void componentWillReceivePropsWithContext(newProps, newContext) => lifecycleCall('componentWillReceivePropsWithContext', arguments: [Map.from(newProps), Map.from(newContext)]); + @override void componentWillUpdate(nextProps, nextState) => lifecycleCall('componentWillUpdate', arguments: [Map.from(nextProps), Map.from(nextState)]); + @override void componentWillUpdateWithContext(nextProps, nextState, nextContext) => lifecycleCall('componentWillUpdateWithContext', arguments: [Map.from(nextProps), Map.from(nextState), Map.from(nextContext)]); + @override void componentDidUpdate(prevProps, prevState) => lifecycleCall('componentDidUpdate', arguments: [Map.from(prevProps), Map.from(prevState)]); + @override bool shouldComponentUpdate(nextProps, nextState) => lifecycleCall('shouldComponentUpdate', arguments: [Map.from(nextProps), Map.from(nextState)], defaultReturnValue: () => true); + @override bool shouldComponentUpdateWithContext(nextProps, nextState, nextContext) => lifecycleCall('shouldComponentUpdateWithContext', arguments: [Map.from(nextProps), Map.from(nextState), Map.from(nextContext)], defaultReturnValue: () => true); + @override dynamic render() => lifecycleCall('render', defaultReturnValue: () => react.div({})); + @override Map getInitialState() => lifecycleCall('getInitialState', defaultReturnValue: () => {}); + @override Map getDefaultProps() { lifecycleCall('getDefaultProps'); diff --git a/test/lifecycle_test/component2.dart b/test/lifecycle_test/component2.dart index 56b3103b..c5980de7 100644 --- a/test/lifecycle_test/component2.dart +++ b/test/lifecycle_test/component2.dart @@ -71,6 +71,7 @@ class _SetStateTest extends react.Component2 with LifecycleTestHelper { return {'counter': previousState['counter'] + 1}; } + @override render() { lifecycleCall('render'); @@ -122,30 +123,36 @@ _DefaultPropsCachingTest defaultPropsCachingTestComponentFactory() => _DefaultPr class _DefaultPropsCachingTest extends react.Component2 implements DefaultPropsCachingTestHelper { static int getDefaultPropsCallCount = 0; + @override int get staticGetDefaultPropsCallCount => getDefaultPropsCallCount; @override set staticGetDefaultPropsCallCount(int value) => getDefaultPropsCallCount = value; + @override Map get defaultProps { getDefaultPropsCallCount++; return {'getDefaultPropsCallCount': getDefaultPropsCallCount}; } + @override render() => false; } final DefaultPropsTest = react.registerComponent2(() => _DefaultPropsTest()); class _DefaultPropsTest extends react.Component2 { + @override Map get defaultProps => {'defaultProp': 'default'}; + @override render() => false; } final PropTypesTest = react.registerComponent2(() => PropTypesTestComponent()); class PropTypesTestComponent extends react.Component2 { + @override get propTypes => { 'intProp': (Map props, info) { var propValue = props[info.propName]; @@ -157,6 +164,7 @@ class PropTypesTestComponent extends react.Component2 { } }; + @override render() => ''; } @@ -165,6 +173,7 @@ react.Context LifecycleTestContext = react.createContext(); final ContextConsumerWrapper = react.registerComponent2(() => _ContextConsumerWrapper()); class _ContextConsumerWrapper extends react.Component2 with LifecycleTestHelper { + @override dynamic render() { return LifecycleTestContext.Consumer({}, props['children'].first); } @@ -173,6 +182,7 @@ class _ContextConsumerWrapper extends react.Component2 with LifecycleTestHelper final ContextWrapper = react.registerComponent2(() => _ContextWrapper()); class _ContextWrapper extends react.Component2 with LifecycleTestHelper { + @override dynamic render() { return LifecycleTestContext.Provider( { @@ -198,6 +208,7 @@ class TestDartException implements Exception { TestDartException(this.message, this.code); + @override toString() { return message; } @@ -208,6 +219,7 @@ class _ErrorComponent extends react.Component2 { throw TestDartException('It crashed!', 100); } + @override void render() { _throwError(); return react.div({'key': 'defaultMessage'}, 'Error'); @@ -218,29 +230,40 @@ final ErrorLifecycleTest = react.registerComponent2(() => _LifecycleTest(), skip final LifecycleTest = react.registerComponent2(() => _LifecycleTest()); class _LifecycleTest extends react.Component2 with LifecycleTestHelper { + @override void componentDidMount() => lifecycleCall('componentDidMount'); + @override void componentWillUnmount() => lifecycleCall('componentWillUnmount'); + @override Map getDerivedStateFromProps(nextProps, prevState) => lifecycleCall('getDerivedStateFromProps', arguments: [Map.from(nextProps), Map.from(prevState)], staticProps: nextProps); + @override dynamic getSnapshotBeforeUpdate(prevProps, prevState) => lifecycleCall('getSnapshotBeforeUpdate', arguments: [Map.from(prevProps), Map.from(prevState)]); + @override void componentDidUpdate(prevProps, prevState, [snapshot]) => lifecycleCall('componentDidUpdate', arguments: [Map.from(prevProps), Map.from(prevState), snapshot]); + @override void componentDidCatch(error, info) => lifecycleCall('componentDidCatch', arguments: [error, info]); + @override Map getDerivedStateFromError(error) => lifecycleCall('getDerivedStateFromError', arguments: [error]); + @override bool shouldComponentUpdate(nextProps, nextState) => lifecycleCall('shouldComponentUpdate', arguments: [Map.from(nextProps), Map.from(nextState)], defaultReturnValue: () => true); + @override dynamic render() => lifecycleCall('render', defaultReturnValue: () => react.div({})); + @override Map get initialState => lifecycleCall('initialState', defaultReturnValue: () => {}); + @override Map get defaultProps => lifecycleCall('defaultProps', defaultReturnValue: () => {'defaultProp': 'default'}); } @@ -248,26 +271,36 @@ final NoGetDerivedStateFromErrorLifecycleTest = react.registerComponent2(() => _NoGetDerivedStateFromErrorLifecycleTest(), skipMethods: []); class _NoGetDerivedStateFromErrorLifecycleTest extends react.Component2 with LifecycleTestHelper { + @override void componentDidMount() => lifecycleCall('componentDidMount'); + @override void componentWillUnmount() => lifecycleCall('componentWillUnmount'); + @override Map getDerivedStateFromProps(nextProps, prevState) => lifecycleCall('getDerivedStateFromProps', arguments: [Map.from(nextProps), Map.from(prevState)], staticProps: nextProps); + @override dynamic getSnapshotBeforeUpdate(prevProps, prevState) => lifecycleCall('getSnapshotBeforeUpdate', arguments: [Map.from(prevProps), Map.from(prevState)]); + @override void componentDidUpdate(prevProps, prevState, [snapshot]) => lifecycleCall('componentDidUpdate', arguments: [Map.from(prevProps), Map.from(prevState), snapshot]); + @override void componentDidCatch(error, info) => lifecycleCall('componentDidCatch', arguments: [error, info]); + @override bool shouldComponentUpdate(nextProps, nextState) => lifecycleCall('shouldComponentUpdate', arguments: [Map.from(nextProps), Map.from(nextState)], defaultReturnValue: () => true); + @override dynamic render() => lifecycleCall('render', defaultReturnValue: () => react.div({})); + @override Map get initialState => lifecycleCall('initialState', defaultReturnValue: () => {}); + @override Map get defaultProps => lifecycleCall('defaultProps', defaultReturnValue: () => {'defaultProp': 'default'}); } diff --git a/test/react_client_test.dart b/test/react_client_test.dart index 8474d4ad..37312e6b 100644 --- a/test/react_client_test.dart +++ b/test/react_client_test.dart @@ -226,6 +226,7 @@ class ThrowsInDefaultPropsComponent extends Component { } class ThrowsInDefaultPropsComponent2 extends Component2 { + @override get defaultProps => throw StateError('bad default props'); @override @@ -235,6 +236,7 @@ class ThrowsInDefaultPropsComponent2 extends Component2 { } class ThrowsInPropTypesComponent2 extends Component2 { + @override get propTypes => throw StateError('bad prop types'); @override diff --git a/test/react_context_test.dart b/test/react_context_test.dart index 2b1a86e7..534cd3b0 100644 --- a/test/react_context_test.dart +++ b/test/react_context_test.dart @@ -119,6 +119,7 @@ var TestContext = react.createContext(); final ContextProviderWrapper = react.registerComponent2(() => _ContextProviderWrapper()); class _ContextProviderWrapper extends react.Component2 { + @override get initialState { return {'counter': 1}; } @@ -127,6 +128,7 @@ class _ContextProviderWrapper extends react.Component2 { this.setState({'counter': state['counter'] + 1}); } + @override render() { return react.div({}, [ props['contextToUse'] @@ -139,6 +141,7 @@ final ContextConsumerWrapper = react.registerComponent2(() => _ContextConsumerWr class _ContextConsumerWrapper extends react.Component2 { dynamic latestValue; + @override render() { return props['contextToUse'].Consumer({'unstable_observedBits': props['unstable_observedBits']}, (value) { latestValue = value; @@ -150,8 +153,10 @@ class _ContextConsumerWrapper extends react.Component2 { final ContextTypeComponent = react.registerComponent2(() => _ContextTypeComponent()); class _ContextTypeComponent extends react.Component2 { + @override var contextType = TestContext; + @override render() { return react.div({}, '${this.context}'); } diff --git a/test/react_fragment_test.dart b/test/react_fragment_test.dart index fe5534ee..0944a46f 100644 --- a/test/react_fragment_test.dart +++ b/test/react_fragment_test.dart @@ -75,6 +75,7 @@ class _FragmentTestDummy extends react.Component2 { props['onComponentDidMount'](); } + @override render() { return react.button(props, 'hi'); } diff --git a/test/react_memo_test.dart b/test/react_memo_test.dart index 5bc15356..0fe63396 100644 --- a/test/react_memo_test.dart +++ b/test/react_memo_test.dart @@ -174,6 +174,7 @@ final MemoTestWrapper = react.registerComponent2(() => _MemoTestWrapperComponent class _MemoTestWrapperComponent extends react.Component2 { int redrawCount = 0; + @override get initialState => { 'localCount': 0, 'valueMemoShouldIgnoreViaAreEqual': 0, diff --git a/test/test_components.dart b/test/test_components.dart index e818eb3c..cf622d0f 100644 --- a/test/test_components.dart +++ b/test/test_components.dart @@ -3,8 +3,10 @@ import 'package:react/react.dart'; /// Base component for event handling classes used in test cases. class EventComponent extends Component { + @override getInitialState() => {'text': ''}; onEvent(SyntheticEvent e) => setState({'text': '${e.type} ${e.timeStamp}'}); + @override render() => div({ 'onAnimationEnd': onEvent, 'onAnimationIteration': onEvent, @@ -61,6 +63,7 @@ class EventComponent extends Component { } class SampleComponent extends Component { + @override render() => div(props, [ h1({}, 'A header'), div({'className': 'div1'}, 'First div'), @@ -70,6 +73,7 @@ class SampleComponent extends Component { } class WrapperComponent extends Component { + @override render() => div(props, props['children']); } diff --git a/test/test_components2.dart b/test/test_components2.dart index 00b1e91c..db1cf10a 100644 --- a/test/test_components2.dart +++ b/test/test_components2.dart @@ -3,8 +3,10 @@ import 'package:react/react.dart'; /// Base component for event handling classes used in test cases. class EventComponent2 extends Component2 { + @override get initialState => {'text': ''}; onEvent(SyntheticEvent e) => setState({'text': '${e.type} ${e.timeStamp}'}); + @override render() => div({ 'onAnimationEnd': onEvent, 'onAnimationIteration': onEvent, @@ -61,6 +63,7 @@ class EventComponent2 extends Component2 { } class SampleComponent2 extends Component2 { + @override render() => div(props, [ h1({}, 'A header'), div({'className': 'div1'}, 'First div'), @@ -70,6 +73,7 @@ class SampleComponent2 extends Component2 { } class WrapperComponent2 extends Component2 { + @override render() => div(props, props['children']); } From bcad3b130ee7c7cf015270fd9a51320f18b4045e Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 15:17:09 -0700 Subject: [PATCH 07/31] dart fix --apply --code=prefer_final_in_for_each --- example/test/react_test_components.dart | 4 ++-- example/test/speed_test.dart | 2 +- lib/react_client/js_backed_map.dart | 2 +- lib/react_client/js_interop_helpers.dart | 2 +- lib/react_client/react_interop.dart | 2 +- lib/src/react_client/event_prop_key_to_event_factory.dart | 2 +- test/factory/common_factory_tests.dart | 4 ++-- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/example/test/react_test_components.dart b/example/test/react_test_components.dart index 785b7857..537a0791 100644 --- a/example/test/react_test_components.dart +++ b/example/test/react_test_components.dart @@ -168,7 +168,7 @@ class _ListComponent extends react.Component { @override dynamic render() { List items = []; - for (var item in state['items']) { + for (final item in state['items']) { items.add(react.li({'key': item}, '$item')); } @@ -473,7 +473,7 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot // Used to generate unique keys even when the list contains duplicate items final itemCounts = {}; final items = []; - for (var item in state['items']) { + for (final item in state['items']) { final count = itemCounts[item] = (itemCounts[item] ?? 0) + 1; items.add(react.li({'key': 'c2-$item-$count'}, '$item')); } diff --git a/example/test/speed_test.dart b/example/test/speed_test.dart index 62a0e4b4..943259ff 100644 --- a/example/test/speed_test.dart +++ b/example/test/speed_test.dart @@ -55,7 +55,7 @@ class _Hello extends react.Component { timeprint('rendering start'); var data = props['data']; var children = []; - for (var elem in data) { + for (final elem in data) { children.add(react.div({ 'key': elem[0] }, [ diff --git a/lib/react_client/js_backed_map.dart b/lib/react_client/js_backed_map.dart index ff3fbf27..f05969cc 100644 --- a/lib/react_client/js_backed_map.dart +++ b/lib/react_client/js_backed_map.dart @@ -79,7 +79,7 @@ class JsBackedMap extends MapBase { @override void clear() { - for (var key in _keys) { + for (final key in _keys) { _Reflect.deleteProperty(jsObject, key); } } diff --git a/lib/react_client/js_interop_helpers.dart b/lib/react_client/js_interop_helpers.dart index 7eeb438c..8ec9d3c4 100644 --- a/lib/react_client/js_interop_helpers.dart +++ b/lib/react_client/js_interop_helpers.dart @@ -100,7 +100,7 @@ _convertDataTree(data) { if (o is Map) { final convertedMap = newObject(); _convertedObjects[o] = convertedMap; - for (var key in o.keys) { + for (final key in o.keys) { setProperty(convertedMap, key, _convert(o[key])); } return convertedMap; diff --git a/lib/react_client/react_interop.dart b/lib/react_client/react_interop.dart index 4fe6fb69..7853e0eb 100644 --- a/lib/react_client/react_interop.dart +++ b/lib/react_client/react_interop.dart @@ -243,7 +243,7 @@ ReactJsComponentFactoryProxy forwardRef( }) { final wrappedComponent = allowInterop((JsMap props, JsRef ref) => componentZone.run(() { final dartProps = JsBackedMap.backedBy(props); - for (var value in dartProps.values) { + for (final value in dartProps.values) { if (value is Function) { // Tag functions that came straight from the JS // so that we know to pass them through as-is during prop conversion. diff --git a/lib/src/react_client/event_prop_key_to_event_factory.dart b/lib/src/react_client/event_prop_key_to_event_factory.dart index 64084c85..1ea510c2 100644 --- a/lib/src/react_client/event_prop_key_to_event_factory.dart +++ b/lib/src/react_client/event_prop_key_to_event_factory.dart @@ -80,7 +80,7 @@ final Set knownEventKeys = (() { }; // Add support for capturing variants; e.g., onClick/onClickCapture - for (var key in _knownEventKeys.toList()) { + for (final key in _knownEventKeys.toList()) { _knownEventKeys.add(key + 'Capture'); } diff --git a/test/factory/common_factory_tests.dart b/test/factory/common_factory_tests.dart index c6b2135d..db3bbbad 100644 --- a/test/factory/common_factory_tests.dart +++ b/test/factory/common_factory_tests.dart @@ -263,7 +263,7 @@ void domEventHandlerWrappingTests(ReactComponentFactoryProxy factory) { }); group('passing Dart events to Dart handlers, and JS events to handlers originating from JS:', () { - for (var eventCase in eventCases) { + for (final eventCase in eventCases) { test(eventCase.description, () { eventCase.simulate(node); expect(events[eventCase], isNotNull, reason: 'handler should have been called'); @@ -289,7 +289,7 @@ void domEventHandlerWrappingTests(ReactComponentFactoryProxy factory) { final dummyEvent = event; - for (var eventCase in eventCases.where((helper) => helper.isDart)) { + for (final eventCase in eventCases.where((helper) => helper.isDart)) { test(eventCase.description, () { expect(() => propsFromDartRender[eventCase.eventPropKey](dummyEvent), returnsNormally); }); From 8d1a82963ed4dbf5c06951caa11cc96ed4508de7 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 15:18:29 -0700 Subject: [PATCH 08/31] dart fix --apply --code=omit_local_variable_types,prefer_final_locals --- example/geocodes/geocodes.dart | 12 +- example/js_components/js_components.dart | 2 +- example/suspense/suspense.dart | 2 +- example/test/false_and_null_test.dart | 2 +- example/test/function_component_test.dart | 12 +- example/test/get_dom_node_test.dart | 2 +- example/test/react_test_components.dart | 14 +- example/test/ref_test.dart | 8 +- example/test/speed_test.dart | 8 +- example/test/unmount_test.dart | 2 +- lib/hooks.dart | 4 +- lib/react.dart | 2 +- lib/react_client/bridge.dart | 4 +- lib/react_client/component_factory.dart | 24 +-- lib/react_client/react_interop.dart | 2 +- lib/src/context.dart | 4 +- lib/src/ddc_emulated_function_name_bug.dart | 4 +- .../react_client/component_registration.dart | 20 +- .../react_client/dart_interop_statics.dart | 26 +-- lib/src/react_client/factory_util.dart | 4 +- lib/src/react_client/private_utils.dart | 2 +- test/factory/common_factory_tests.dart | 16 +- test/forward_ref_test.dart | 8 +- test/hooks_test.dart | 42 ++-- test/js_builds/shared_tests.dart | 2 +- test/lifecycle_test.dart | 186 +++++++++--------- test/lifecycle_test/component2.dart | 2 +- test/lifecycle_test/util.dart | 2 +- test/react_client/event_helpers_test.dart | 26 +-- test/react_client_test.dart | 16 +- test/react_context_test.dart | 6 +- test/react_fragment_test.dart | 2 +- test/react_suspense_test.dart | 6 +- test/react_test_utils_test.dart | 30 +-- test/util.dart | 6 +- 35 files changed, 255 insertions(+), 255 deletions(-) diff --git a/example/geocodes/geocodes.dart b/example/geocodes/geocodes.dart index 60f4126d..3ca39da4 100644 --- a/example/geocodes/geocodes.dart +++ b/example/geocodes/geocodes.dart @@ -160,7 +160,7 @@ class _GeocodesForm extends react.Component { event.preventDefault(); InputElement inputElement = react_dom.findDOMNode(searchInputInstance); // The input's value is accessed. - var address = inputElement.value; + final address = inputElement.value; inputElement.value = ''; // Call the callback from the parent element is called. props['submitter'](address); @@ -247,15 +247,15 @@ class _GeocodesApp extends react.Component { /// Sends the [addressQuery] to the API and processes the result newQuery(String addressQuery) async { // Once the query is being sent, it appears in the history and is given an id. - var id = addQueryToHistory(addressQuery); + final id = addQueryToHistory(addressQuery); // Prepare the URL addressQuery = Uri.encodeQueryComponent(addressQuery); - var path = 'https://maps.googleapis.com/maps/api/geocode/json?address=$addressQuery'; + final path = 'https://maps.googleapis.com/maps/api/geocode/json?address=$addressQuery'; try { // Send the request - var raw = await HttpRequest.getString(path); + final raw = await HttpRequest.getString(path); // Delay the answer 2 more seconds, for test purposes await Future.delayed(Duration(seconds: 2)); // Is this the answer to the last request? @@ -263,7 +263,7 @@ class _GeocodesApp extends react.Component { // If yes, query was `OK` and `shown_addresses` are replaced state['history'][id]['status'] = 'OK'; - var data = json.decode(raw); + final data = json.decode(raw); // Calling `setState` will update the state and then repaint the component. // @@ -291,7 +291,7 @@ class _GeocodesApp extends react.Component { /// Add a new [addressQuery] to the `state.history` Map with its status set to 'pending', then return its `id`. addQueryToHistory(String addressQuery) { - var id = ++last_id; + final id = ++last_id; state['history'][id] = {'query': addressQuery, 'status': 'pending'}; diff --git a/example/js_components/js_components.dart b/example/js_components/js_components.dart index 19237b7b..bee8ce77 100644 --- a/example/js_components/js_components.dart +++ b/example/js_components/js_components.dart @@ -10,7 +10,7 @@ import 'package:react/react_client/react_interop.dart'; import 'package:react/react_dom.dart' as react_dom; main() { - var content = IndexComponent({}); + final content = IndexComponent({}); react_dom.render(content, querySelector('#content')); } diff --git a/example/suspense/suspense.dart b/example/suspense/suspense.dart index 6c8654fe..0767f174 100644 --- a/example/suspense/suspense.dart +++ b/example/suspense/suspense.dart @@ -32,7 +32,7 @@ ReactJsComponentFactoryProxy lazy(Future factory()) ); main() { - var content = wrapper({}); + final content = wrapper({}); react_dom.render(content, querySelector('#content')); } diff --git a/example/test/false_and_null_test.dart b/example/test/false_and_null_test.dart index d562a442..c26fe843 100644 --- a/example/test/false_and_null_test.dart +++ b/example/test/false_and_null_test.dart @@ -18,7 +18,7 @@ class _Component extends react.Component { var component = react.registerComponent(() => _Component()); void main() { - var content = react.div({}, [ + final content = react.div({}, [ react.p({}, 'Testing a dynamic return value of "null"...'), component({'returnValue': null, 'key': 0}), react.p({}, 'Testing a hard-coded return value of "null"...'), diff --git a/example/test/function_component_test.dart b/example/test/function_component_test.dart index 33b7e24b..3537d93f 100644 --- a/example/test/function_component_test.dart +++ b/example/test/function_component_test.dart @@ -114,7 +114,7 @@ Map reducer(Map state, Map action) { } UseReducerTestComponent(Map props) { - final ReducerHook state = useReducerLazy(reducer, props['initialCount'], initializeCount); + final state = useReducerLazy(reducer, props['initialCount'], initializeCount); return react.Fragment({}, [ state.state['count'], @@ -149,11 +149,11 @@ UseCallbackTestComponent(Map props) { final count = useState(0); final delta = useState(1); - var increment = useCallback((_) { + final increment = useCallback((_) { count.setWithUpdater((prev) => prev + delta.value); }, [delta.value]); - var incrementDelta = useCallback((_) { + final incrementDelta = useCallback((_) { delta.setWithUpdater((prev) => prev + 1); }, []); @@ -178,7 +178,7 @@ UseContextTestComponent(Map props) { } int calculateChangedBits(currentValue, nextValue) { - int result = 1 << 1; + var result = 1 << 1; if (nextValue['renderCount'] % 2 == 0) { result |= 1 << 2; } @@ -297,7 +297,7 @@ final randomUseLayoutEffectTestComponent = react.registerFunctionComponent(RandomUseLayoutEffectTestComponent, displayName: 'randomUseLayoutEffectTest'); RandomUseLayoutEffectTestComponent(Map props) { - StateHook value = useState(0); + final value = useState(0); useLayoutEffect(() { if (value.value == 0) { @@ -317,7 +317,7 @@ final randomUseEffectTestComponent = react.registerFunctionComponent(RandomUseEffectTestComponent, displayName: 'randomUseEffectTest'); RandomUseEffectTestComponent(Map props) { - StateHook value = useState(0); + final value = useState(0); useEffect(() { if (value.value == 0) { diff --git a/example/test/get_dom_node_test.dart b/example/test/get_dom_node_test.dart index df1ef374..dfa812f9 100644 --- a/example/test/get_dom_node_test.dart +++ b/example/test/get_dom_node_test.dart @@ -87,6 +87,6 @@ class SimpleComponent extends react.Component { var mountedNode = querySelector('#content'); void main() { - var component = simpleComponent({}); + final component = simpleComponent({}); react_dom.render(component, mountedNode); } diff --git a/example/test/react_test_components.dart b/example/test/react_test_components.dart index 537a0791..1e30a9c6 100644 --- a/example/test/react_test_components.dart +++ b/example/test/react_test_components.dart @@ -30,7 +30,7 @@ class _HelloGreeter extends react.Component { getInitialState() => {'name': 'World'}; onInputChange(e) { - var input = react_dom.findDOMNode(myInput); + final input = react_dom.findDOMNode(myInput); print(input.borderEdge); setState({'name': e.target.value}); } @@ -105,7 +105,7 @@ class _ClockComponent extends react.Component { @override void componentDidMount() { - var rootNode = react_dom.findDOMNode(this); + final rootNode = react_dom.findDOMNode(this); rootNode.style.backgroundColor = '#FFAAAA'; } @@ -160,14 +160,14 @@ class _ListComponent extends react.Component { int iterator = 3; void addItem(event) { - List items = List.from(state['items']); + final items = List.from(state['items']); items.add(++iterator); setState({'items': items}); } @override dynamic render() { - List items = []; + final items = []; for (final item in state['items']) { items.add(react.li({'key': item}, '$item')); } @@ -286,7 +286,7 @@ class _NewContextRefComponent extends react.Component2 { var newContextRefComponent = react.registerComponent(() => _NewContextRefComponent()); int calculateChangedBits(currentValue, nextValue) { - int result = 1 << 1; + var result = 1 << 1; if (nextValue['renderCount'] % 2 == 0) { result |= 1 << 2; } @@ -457,13 +457,13 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot } void removeItem(event) { - List items = List.from(state['items']); + final items = List.from(state['items']); items.removeAt(items.length - 1); setState({'items': items}); } void addItem(event) { - List items = List.from(state['items']); + final items = List.from(state['items']); items.add(items.length); setState({'items': items}); } diff --git a/example/test/ref_test.dart b/example/test/ref_test.dart index 8100052a..3a9fe63e 100644 --- a/example/test/ref_test.dart +++ b/example/test/ref_test.dart @@ -72,7 +72,7 @@ var ParentComponent = react.registerComponent(() => _ParentComponent()); class _ParentComponent extends react.Component { // String refs showInputValue(_) { - var input = react_dom.findDOMNode(ref('inputRef')) as InputElement; + final input = react_dom.findDOMNode(ref('inputRef')) as InputElement; print(input.value); } @@ -88,7 +88,7 @@ class _ParentComponent extends react.Component { InputElement _inputCallbackRef; _ChildComponent _childCallbackRef; showInputCallbackRefValue(_) { - var input = react_dom.findDOMNode(_inputCallbackRef); + final input = react_dom.findDOMNode(_inputCallbackRef); print(input.value); } @@ -105,7 +105,7 @@ class _ParentComponent extends react.Component { final Ref<_ChildComponent> _childCreateRef = react.createRef(); showInputCreateRefValue(_) { - var input = react_dom.findDOMNode(_inputCreateRef.current); + final input = react_dom.findDOMNode(_inputCreateRef.current); print(input.value); } @@ -233,6 +233,6 @@ class _ParentComponent extends react.Component { var mountedNode = querySelector('#content'); void main() { - var component = ParentComponent({}); + final component = ParentComponent({}); react_dom.render(component, mountedNode); } diff --git a/example/test/speed_test.dart b/example/test/speed_test.dart index 943259ff..057e5a93 100644 --- a/example/test/speed_test.dart +++ b/example/test/speed_test.dart @@ -53,8 +53,8 @@ class _Hello extends react.Component { @override render() { timeprint('rendering start'); - var data = props['data']; - var children = []; + final data = props['data']; + final children = []; for (final elem in data) { children.add(react.div({ 'key': elem[0] @@ -72,7 +72,7 @@ class _Hello extends react.Component { // ])) // ); timeprint('rendering almost ends'); - var res = react.div({}, children); + final res = react.div({}, children); timeprint('rendering ends'); return res; } @@ -81,7 +81,7 @@ class _Hello extends react.Component { var Hello = react.registerComponent(() => _Hello()); void main() { - var data = []; + final data = []; for (num i = 0; i < 1000; i++) { data.add(['name_$i', 'value_$i']); } diff --git a/example/test/unmount_test.dart b/example/test/unmount_test.dart index 7c448593..2cb484a2 100644 --- a/example/test/unmount_test.dart +++ b/example/test/unmount_test.dart @@ -21,7 +21,7 @@ class SimpleComponent extends react.Component { void main() { print('What'); - var mountedNode = querySelector('#content'); + final mountedNode = querySelector('#content'); querySelector('#mount').onClick.listen((_) => react_dom.render(simpleComponent({}), mountedNode)); diff --git a/lib/hooks.dart b/lib/hooks.dart index 9fe1df67..4af5e706 100644 --- a/lib/hooks.dart +++ b/lib/hooks.dart @@ -141,8 +141,8 @@ StateHook useStateLazy(T init()) => StateHook.lazy(init); /// /// See: . void useEffect(dynamic Function() sideEffect, [List dependencies]) { - var wrappedSideEffect = allowInterop(() { - var result = sideEffect(); + final wrappedSideEffect = allowInterop(() { + final result = sideEffect(); if (result is Function) { return allowInterop(result); } diff --git a/lib/react.dart b/lib/react.dart index 587775b0..079e449a 100644 --- a/lib/react.dart +++ b/lib/react.dart @@ -355,7 +355,7 @@ abstract class Component { /// > Use [setState] instead. @Deprecated('7.0.0') void replaceState(Map newState, [callback()]) { - Map nextState = newState == null ? {} : Map.from(newState); + final nextState = newState == null ? {} : Map.from(newState); _nextState = nextState; if (callback != null) _setStateCallbacks.add(callback); diff --git a/lib/react_client/bridge.dart b/lib/react_client/bridge.dart index 8b626e88..63fbaff8 100644 --- a/lib/react_client/bridge.dart +++ b/lib/react_client/bridge.dart @@ -125,9 +125,9 @@ class Component2BridgeImpl extends Component2Bridge { String secret, ) { // Create a Dart consumable version of the JsMap. - var convertedProps = JsBackedMap.fromJs(props); + final convertedProps = JsBackedMap.fromJs(props); // Call the users validator with the newly wrapped props. - var error = validator( + final error = validator( convertedProps, PropValidatorInfo( propName: propName, diff --git a/lib/react_client/component_factory.dart b/lib/react_client/component_factory.dart index 1c36950d..127afda1 100644 --- a/lib/react_client/component_factory.dart +++ b/lib/react_client/component_factory.dart @@ -43,7 +43,7 @@ dynamic listifyChildren(dynamic children) { /// If `style` is specified in props, then it too is shallow-converted and included /// in the returned Map. Map unconvertJsProps(/* ReactElement|ReactComponent */ instance) { - var props = Map.from(JsBackedMap.backedBy(instance.props)); + final props = Map.from(JsBackedMap.backedBy(instance.props)); // Catch if a Dart component has been passed in. Component (version 1) can be identified by having the "internal" // prop. Component2, however, does not have that but can be detected by checking whether or not the style prop is a @@ -55,7 +55,7 @@ Map unconvertJsProps(/* ReactElement|ReactComponent */ instance) { } // Convert the nested style map so it can be read by Dart code. - var style = props['style']; + final style = props['style']; if (style != null) { props['style'] = Map.from(JsBackedMap.backedBy(style)); } @@ -67,8 +67,8 @@ Map unconvertJsProps(/* ReactElement|ReactComponent */ instance) { mixin JsBackedMapComponentFactoryMixin on ReactComponentFactoryProxy { @override ReactElement build(Map props, [List childrenArgs = const []]) { - var children = generateChildren(childrenArgs, shouldAlwaysBeList: true); - var convertedProps = generateExtendedJsProps(props); + final children = generateChildren(childrenArgs, shouldAlwaysBeList: true); + final convertedProps = generateExtendedJsProps(props); return React.createElement(type, convertedProps, children); } @@ -117,7 +117,7 @@ class ReactDartComponentFactoryProxy extends React // 3. Remove "reserved" props that should not be visible to the rendered component. // [1] - Map extendedProps = (defaultProps != null ? Map.from(defaultProps) : {}) + final extendedProps = (defaultProps != null ? Map.from(defaultProps) : {}) // [2] ..addAll(props) ..['children'] = children @@ -125,9 +125,9 @@ class ReactDartComponentFactoryProxy extends React ..remove('key') ..remove('ref'); - var internal = ReactDartComponentInternal()..props = extendedProps; + final internal = ReactDartComponentInternal()..props = extendedProps; - var interopProps = InteropProps(internal: internal); + final interopProps = InteropProps(internal: internal); // Don't pass a key into InteropProps if one isn't defined, so that the value will // be `undefined` in the JS, which is ignored by React, whereas `null` isn't. @@ -136,7 +136,7 @@ class ReactDartComponentFactoryProxy extends React } if (props.containsKey('ref')) { - var ref = props['ref']; + final ref = props['ref']; // If the ref is a callback, pass ReactJS a function that will call it // with the Dart Component instance, not the ReactComponent instance. @@ -233,7 +233,7 @@ class ReactJsContextComponentFactoryProxy extends ReactJsComponentFactoryProxy { /// Returns a JavaScript version of the specified [props], preprocessed for consumption by ReactJS and prepared for /// consumption by the `react` library internals. JsMap generateExtendedJsProps(Map props) { - JsBackedMap propsForJs = JsBackedMap.from(props); + final propsForJs = JsBackedMap.from(props); if (isProvider) { propsForJs['value'] = ContextHelpers.jsifyNewContext(propsForJs['value']); @@ -279,7 +279,7 @@ class ReactJsComponentFactoryProxy extends ReactComponentFactoryProxy { @override ReactElement build(Map props, [List childrenArgs]) { dynamic children = generateChildren(childrenArgs, shouldAlwaysBeList: alwaysReturnChildrenAsList); - JsMap convertedProps = + final convertedProps = generateJsProps(props, convertCallbackRefValue: false, additionalRefPropKeys: _additionalRefPropKeys); return React.createElement(type, convertedProps, children); } @@ -304,8 +304,8 @@ class ReactDomComponentFactoryProxy extends ReactComponentFactoryProxy { @override ReactElement build(Map props, [List childrenArgs = const []]) { - var children = generateChildren(childrenArgs); - var convertedProps = generateJsProps(props, convertCallbackRefValue: false, wrapWithJsify: true); + final children = generateChildren(childrenArgs); + final convertedProps = generateJsProps(props, convertCallbackRefValue: false, wrapWithJsify: true); return React.createElement(type, convertedProps, children); } diff --git a/lib/react_client/react_interop.dart b/lib/react_client/react_interop.dart index 7853e0eb..b8fbd370 100644 --- a/lib/react_client/react_interop.dart +++ b/lib/react_client/react_interop.dart @@ -256,7 +256,7 @@ ReactJsComponentFactoryProxy forwardRef( })); defineProperty(wrappedComponent, 'displayName', JsPropertyDescriptor(value: displayName)); - var hoc = React.forwardRef(wrappedComponent); + final hoc = React.forwardRef(wrappedComponent); // ignore: invalid_use_of_protected_member setProperty(hoc, 'dartComponentVersion', ReactDartComponentVersion.component2); diff --git a/lib/src/context.dart b/lib/src/context.dart index c89fb58d..7ef5f482 100644 --- a/lib/src/context.dart +++ b/lib/src/context.dart @@ -111,7 +111,7 @@ Context createContext([ ContextHelpers.unjsifyNewContext(currentValue), ContextHelpers.unjsifyNewContext(nextValue)); } - var JSContext = React.createContext(ContextHelpers.jsifyNewContext(defaultValue), + final JSContext = React.createContext(ContextHelpers.jsifyNewContext(defaultValue), calculateChangedBits != null ? allowInterop(jsifyCalculateChangedBitsArgs) : null); return Context( ReactJsContextComponentFactoryProxy(JSContext.Provider, isProvider: true), @@ -131,7 +131,7 @@ abstract class ContextHelpers { // Wraps context value in a JS Object for use on the JS side. // It is wrapped so that the same Dart value can be retrieved from Dart with [_unjsifyNewContext]. static dynamic jsifyNewContext(dynamic context) { - var jsContextHolder = newObject(); + final jsContextHolder = newObject(); setProperty(jsContextHolder, _reactDartContextSymbol, DartValueWrapper.wrapIfNeeded(context)); return jsContextHolder; } diff --git a/lib/src/ddc_emulated_function_name_bug.dart b/lib/src/ddc_emulated_function_name_bug.dart index ba4df865..c527ee80 100644 --- a/lib/src/ddc_emulated_function_name_bug.dart +++ b/lib/src/ddc_emulated_function_name_bug.dart @@ -29,7 +29,7 @@ class _NsmEmulatedFunctionWithNameProperty implements Function { final bool isBugPresent = (() { const testValue = 'test value'; - var testObject = _NsmEmulatedFunctionWithNameProperty(); + final testObject = _NsmEmulatedFunctionWithNameProperty(); try { // In the DDC, this throws: @@ -73,7 +73,7 @@ external void _defineProperty(dynamic object, String propertyName, _PropertyDesc void patchName(dynamic object) { var current = object; while ((current = _getPrototypeOf(current)) != null) { - var nameDescriptor = _getOwnPropertyDescriptor(current, 'name'); + final nameDescriptor = _getOwnPropertyDescriptor(current, 'name'); if (nameDescriptor != null) { _defineProperty(object, 'name', nameDescriptor); diff --git a/lib/src/react_client/component_registration.dart b/lib/src/react_client/component_registration.dart index 75204b49..9d75c51b 100644 --- a/lib/src/react_client/component_registration.dart +++ b/lib/src/react_client/component_registration.dart @@ -20,8 +20,8 @@ import '../js_interop_util.dart'; /// important ones. If an important lifecycle event was set for skipping, a /// warning is issued. List _filterSkipMethods(Iterable methods) { - List finalList = List.from(methods); - bool shouldWarn = false; + final finalList = List.from(methods); + var shouldWarn = false; if (finalList.contains('shouldComponentUpdate')) { finalList.remove('shouldComponentUpdate'); @@ -56,15 +56,15 @@ ReactDartComponentFactoryProxy registerComponent( Iterable skipMethods = const ['getDerivedStateFromError', 'componentDidCatch'], ]) { try { - var componentInstance = componentFactory(); + final componentInstance = componentFactory(); if (componentInstance is Component2) { return registerComponent2(componentFactory, skipMethods: skipMethods); } - var componentStatics = ComponentStatics(componentFactory); + final componentStatics = ComponentStatics(componentFactory); - var jsConfig = JsComponentConfig( + final jsConfig = JsComponentConfig( childContextKeys: componentInstance.childContextKeys, contextKeys: componentInstance.contextKeys, ); @@ -73,7 +73,7 @@ ReactDartComponentFactoryProxy registerComponent( /// Create the JS [`ReactClass` component class](https://facebook.github.io/react/docs/top-level-api.html#react.createclass) /// with custom JS lifecycle methods. - var reactComponentClass = createReactDartComponentClass(dartInteropStatics, componentStatics, jsConfig) + final reactComponentClass = createReactDartComponentClass(dartInteropStatics, componentStatics, jsConfig) // ignore: invalid_use_of_protected_member ..dartComponentVersion = ReactDartComponentVersion.component // This is redundant since we also set `name` below, but some code may depend on reading displayName @@ -86,7 +86,7 @@ ReactDartComponentFactoryProxy registerComponent( // Cache default props and store them on the ReactClass so they can be used // by ReactDartComponentFactoryProxy and externally. - final Map defaultProps = Map.unmodifiable(componentInstance.getDefaultProps()); + final defaultProps = Map.unmodifiable(componentInstance.getDefaultProps()); reactComponentClass.dartDefaultProps = defaultProps; return ReactDartComponentFactoryProxy(reactComponentClass); @@ -103,7 +103,7 @@ ReactDartComponentFactoryProxy2 registerComponent2( Iterable skipMethods = const ['getDerivedStateFromError', 'componentDidCatch'], Component2BridgeFactory bridgeFactory, }) { - bool errorPrinted = false; + var errorPrinted = false; try { bridgeFactory ??= Component2BridgeImpl.bridgeFactory; @@ -139,7 +139,7 @@ ReactDartComponentFactoryProxy2 registerComponent2( rethrow; } - var jsConfig2 = JsComponentConfig2( + final jsConfig2 = JsComponentConfig2( defaultProps: defaultProps.jsObject, contextType: componentInstance.contextType?.jsThis, skipMethods: filteredSkipMethods, @@ -150,7 +150,7 @@ ReactDartComponentFactoryProxy2 registerComponent2( /// Create the JS [`ReactClass` component class](https://facebook.github.io/react/docs/top-level-api.html#react.createclass) /// with custom JS lifecycle methods. - var reactComponentClass = + final reactComponentClass = createReactDartComponentClass2(ReactDartInteropStatics2.staticsForJs, componentStatics, jsConfig2) // This is redundant since we also set `name` below, but some code may depend on reading displayName // so we'll leave this in place for now. diff --git a/lib/src/react_client/dart_interop_statics.dart b/lib/src/react_client/dart_interop_statics.dart index 0d68e079..1a763a95 100644 --- a/lib/src/react_client/dart_interop_statics.dart +++ b/lib/src/react_client/dart_interop_statics.dart @@ -19,7 +19,7 @@ import 'package:react/src/typedefs.dart'; /// The static methods that proxy JS component lifecycle methods to Dart components. @Deprecated('7.0.0') final ReactDartInteropStatics dartInteropStatics = (() { - var zone = Zone.current; + final zone = Zone.current; /// Wrapper for [Component.getInitialState]. Component initComponent(ReactComponent jsThis, ReactDartComponentInternal internal, InteropContextValue context, @@ -29,8 +29,8 @@ final ReactDartInteropStatics dartInteropStatics = (() { jsThis.setState(newObject()); } - RefMethod getRef = (name) { - var ref = getProperty(jsThis.refs, name); + final getRef = (name) { + final ref = getProperty(jsThis.refs, name); if (ref == null) return null; if (ref is Element) return ref; if (ref is ReactComponent) return ref.dartComponent ?? ref; @@ -38,7 +38,7 @@ final ReactDartInteropStatics dartInteropStatics = (() { return ref; }; - Component component = componentStatics.componentFactory() + final component = componentStatics.componentFactory() ..initComponentInternal(internal.props, jsRedraw, getRef, jsThis, unjsifyContext(context)) ..initStateInternal(); @@ -64,7 +64,7 @@ final ReactDartInteropStatics dartInteropStatics = (() { }); Map _getNextProps(Component component, ReactDartComponentInternal nextInternal) { - var newProps = nextInternal.props; + final newProps = nextInternal.props; return newProps != null ? Map.from(newProps) : {}; } @@ -85,7 +85,7 @@ final ReactDartInteropStatics dartInteropStatics = (() { } void _callSetStateCallbacks(Component component) { - var callbacks = component.setStateCallbacks.toList(); + final callbacks = component.setStateCallbacks.toList(); // Prevent concurrent modification during iteration component.setStateCallbacks.clear(); callbacks.forEach((callback) { @@ -94,8 +94,8 @@ final ReactDartInteropStatics dartInteropStatics = (() { } void _callSetStateTransactionalCallbacks(Component component) { - var nextState = component.nextState; - var props = UnmodifiableMapView(component.props); + final nextState = component.nextState; + final props = UnmodifiableMapView(component.props); component.transactionalSetStateCallbacks.forEach((callback) { final stateUpdates = callback(nextState, props); @@ -108,8 +108,8 @@ final ReactDartInteropStatics dartInteropStatics = (() { void handleComponentWillReceiveProps( Component component, ReactDartComponentInternal nextInternal, InteropContextValue nextContext) => zone.run(() { - var nextProps = _getNextProps(component, nextInternal); - var newContext = unjsifyContext(nextContext); + final nextProps = _getNextProps(component, nextInternal); + final newContext = unjsifyContext(nextContext); component ..nextProps = nextProps @@ -124,7 +124,7 @@ final ReactDartInteropStatics dartInteropStatics = (() { // If shouldComponentUpdateWithContext returns a valid bool (default implementation returns null), // then don't bother calling `shouldComponentUpdate` and have it trump. - bool shouldUpdate = + var shouldUpdate = component.shouldComponentUpdateWithContext(component.nextProps, component.nextState, component.nextContext); if (shouldUpdate == null) { @@ -157,7 +157,7 @@ final ReactDartInteropStatics dartInteropStatics = (() { /// /// Uses [prevState] which was transferred from [Component.nextState] in [componentWillUpdate]. void handleComponentDidUpdate(Component component, ReactDartComponentInternal prevInternal) => zone.run(() { - var prevInternalProps = prevInternal.props; + final prevInternalProps = prevInternal.props; /// Call `componentDidUpdate` and the context variant component.componentDidUpdate(prevInternalProps, component.prevState); @@ -247,7 +247,7 @@ abstract class ReactDartInteropStatics2 { static JsMap handleGetDerivedStateFromProps( ComponentStatics2 componentStatics, JsMap jsNextProps, JsMap jsPrevState) => // dartfmt componentZone.run(() { - var derivedState = componentStatics.instanceForStaticMethods + final derivedState = componentStatics.instanceForStaticMethods .getDerivedStateFromProps(JsBackedMap.backedBy(jsNextProps), JsBackedMap.backedBy(jsPrevState)); if (derivedState != null) { return jsBackingMapOrJsCopy(derivedState); diff --git a/lib/src/react_client/factory_util.dart b/lib/src/react_client/factory_util.dart index fd055391..4ec5115e 100644 --- a/lib/src/react_client/factory_util.dart +++ b/lib/src/react_client/factory_util.dart @@ -34,7 +34,7 @@ dynamic convertArgsToChildren(List childrenArgs) { Function unconvertJsEventHandler(Function jsConvertedEventHandler) => null; void convertRefValue(Map args) { - var ref = args['ref']; + final ref = args['ref']; if (ref is Ref) { args['ref'] = ref.jsRef; } @@ -48,7 +48,7 @@ void convertRefValue2( final refKeys = ['ref', ...additionalRefPropKeys]; for (final refKey in refKeys) { - var ref = args[refKey]; + final ref = args[refKey]; if (ref is Ref) { args[refKey] = ref.jsRef; // If the ref is a callback, pass ReactJS a function that will call it diff --git a/lib/src/react_client/private_utils.dart b/lib/src/react_client/private_utils.dart index cc563f26..9e3d6831 100644 --- a/lib/src/react_client/private_utils.dart +++ b/lib/src/react_client/private_utils.dart @@ -14,7 +14,7 @@ bool _isJsApiValid = false; @Deprecated('7.0.0') InteropContextValue jsifyContext(Map context) { - var interopContext = InteropContextValue(); + final interopContext = InteropContextValue(); context.forEach((key, value) { // ignore: argument_type_not_assignable setProperty(interopContext, key, ReactDartContextInternal(value)); diff --git a/test/factory/common_factory_tests.dart b/test/factory/common_factory_tests.dart index db3bbbad..58b1c984 100644 --- a/test/factory/common_factory_tests.dart +++ b/test/factory/common_factory_tests.dart @@ -35,7 +35,7 @@ void commonFactoryTests(ReactComponentFactoryProxy factory, ); test('renders an instance with the corresponding `type`', () { - var instance = factory({}); + final instance = factory({}); expect(instance.type, equals(factory.type)); }); @@ -83,7 +83,7 @@ void commonFactoryTests(ReactComponentFactoryProxy factory, }); test('a List', () { - var instance = factory(props, [ + final instance = factory(props, [ 'one', 'two', ]); @@ -91,17 +91,17 @@ void commonFactoryTests(ReactComponentFactoryProxy factory, }); test('an empty List', () { - var instance = factory(props, []); + final instance = factory(props, []); expect(getChildren(instance), equals([])); }); test('an Iterable', () { - var instance = factory(props, Iterable.generate(3, (int i) => '$i')); + final instance = factory(props, Iterable.generate(3, (int i) => '$i')); expect(getChildren(instance), equals(['0', '1', '2'])); }); test('an empty Iterable', () { - var instance = factory(props, Iterable.empty()); + final instance = factory(props, Iterable.empty()); expect(getChildren(instance), equals([])); }); } @@ -404,7 +404,7 @@ void refTests( } test('string refs', () { - ReactComponent renderedInstance = _renderWithStringRefSupportingOwner(() => factory({'ref': 'test'})); + final renderedInstance = _renderWithStringRefSupportingOwner(() => factory({'ref': 'test'})); // ignore: deprecated_member_use_from_same_package verifyRefValue(renderedInstance.dartComponent.ref('test')); @@ -418,7 +418,7 @@ void refTests( if (!name.contains('callback ref')) { test(name, () { final testCase = testCaseCollection.createCaseByName(name); - var ForwardRefTestComponent = forwardRef((props, ref) { + final ForwardRefTestComponent = forwardRef((props, ref) { return factory({'ref': ref}); }); @@ -436,7 +436,7 @@ void refTests( for (final name in testCaseCollection.allTestCaseNames) { test(name, () { final testCase = testCaseCollection.createCaseByName(name); - var ForwardRefTestComponent = forwardRef2((props, ref) { + final ForwardRefTestComponent = forwardRef2((props, ref) { return factory({'ref': ref}); }); diff --git a/test/forward_ref_test.dart b/test/forward_ref_test.dart index ca9cedfe..4097043e 100644 --- a/test/forward_ref_test.dart +++ b/test/forward_ref_test.dart @@ -33,13 +33,13 @@ main() { group('sets displayName on the rendered component as expected', () { test('falling back to "Anonymous" when the displayName argument is not passed to forwardRef', () { - var ForwardRefTestComponent = forwardRef((props, ref) {}); + final ForwardRefTestComponent = forwardRef((props, ref) {}); expect(getProperty(getProperty(ForwardRefTestComponent.type, 'render'), 'displayName'), 'Anonymous'); }); test('when displayName argument is passed to forwardRef', () { const name = 'ForwardRefTestComponent'; - var ForwardRefTestComponent = forwardRef((props, ref) {}, displayName: name); + final ForwardRefTestComponent = forwardRef((props, ref) {}, displayName: name); expect(getProperty(getProperty(ForwardRefTestComponent.type, 'render'), 'displayName'), name); }); }); @@ -64,13 +64,13 @@ main() { group('sets name on the rendered component as expected', () { test('unless the displayName argument is not passed to forwardRef2', () { - var ForwardRefTestComponent = forwardRef2((props, ref) {}); + final ForwardRefTestComponent = forwardRef2((props, ref) {}); expect(getProperty(getProperty(ForwardRefTestComponent.type, 'render'), 'name'), anyOf('', isNull)); }); test('when displayName argument is passed to forwardRef2', () { const name = 'ForwardRefTestComponent'; - var ForwardRefTestComponent = forwardRef2((props, ref) {}, displayName: name); + final ForwardRefTestComponent = forwardRef2((props, ref) {}, displayName: name); expect(getProperty(getProperty(ForwardRefTestComponent.type, 'render'), 'name'), name); }); }); diff --git a/test/hooks_test.dart b/test/hooks_test.dart index 8841cd98..9290628d 100644 --- a/test/hooks_test.dart +++ b/test/hooks_test.dart @@ -25,7 +25,7 @@ main() { ButtonElement setWithUpdaterButtonRef; setUpAll(() { - var mountNode = DivElement(); + final mountNode = DivElement(); UseStateTest = react.registerFunctionComponent((Map props) { final text = useStateLazy(() { @@ -115,7 +115,7 @@ main() { } setUpAll(() { - var mountNode = DivElement(); + final mountNode = DivElement(); UseReducerTest = react.registerFunctionComponent((Map props) { final state = useReducer(reducer, { @@ -209,10 +209,10 @@ main() { } setUpAll(() { - var mountNode = DivElement(); + final mountNode = DivElement(); UseReducerTest = react.registerFunctionComponent((Map props) { - final ReducerHook state = useReducerLazy(reducer2, props['initialCount'], initializeCount); + final state = useReducerLazy(reducer2, props['initialCount'], initializeCount); return react.div({}, [ react.div({ @@ -282,21 +282,21 @@ main() { ButtonElement incrementDeltaButtonRef; setUpAll(() { - var mountNode = DivElement(); + final mountNode = DivElement(); UseCallbackTest = react.registerFunctionComponent((Map props) { final count = useState(0); final delta = useState(1); - var incrementNoDep = useCallback((_) { + final incrementNoDep = useCallback((_) { count.setWithUpdater((prev) => prev + delta.value); }, []); - var incrementWithDep = useCallback((_) { + final incrementWithDep = useCallback((_) { count.setWithUpdater((prev) => prev + delta.value); }, [delta.value]); - var incrementDelta = useCallback((_) { + final incrementDelta = useCallback((_) { delta.setWithUpdater((prev) => prev + 1); }, []); @@ -376,7 +376,7 @@ main() { group('useContext -', () { DivElement mountNode; _ContextProviderWrapper providerRef; - int currentCount = 0; + var currentCount = 0; Context testContext; Function useContextTestFunctionComponent; @@ -436,7 +436,7 @@ main() { }); group('useRef -', () { - var mountNode = DivElement(); + final mountNode = DivElement(); ReactDartFunctionComponentFactoryProxy UseRefTest; ButtonElement reRenderButton; var noInitRef; @@ -521,9 +521,9 @@ main() { ButtonElement incrementButtonRef; // Count how many times createFunction() is called for each variation of dependencies. - int createFunctionCallCountWithDeps = 0; - int createFunctionCallCountNoDeps = 0; - int createFunctionCallCountEmptyDeps = 0; + var createFunctionCallCountWithDeps = 0; + var createFunctionCallCountNoDeps = 0; + var createFunctionCallCountEmptyDeps = 0; // Keeps track of return value of useMemo() for each variation of dependencies. int returnValueWithDeps; @@ -644,7 +644,7 @@ main() { group('useImperativeHandle -', () { group('updates `ref.current` to the return value of `createHandle()`', () { - var mountNode = DivElement(); + final mountNode = DivElement(); ReactDartFunctionComponentFactoryProxy UseImperativeHandleTest; ButtonElement incrementButton; ButtonElement reRenderButtonRef1; @@ -655,7 +655,7 @@ main() { StateHook count; setUpAll(() { - var NoDepsComponent = react.forwardRef2((props, ref) { + final NoDepsComponent = react.forwardRef2((props, ref) { count = useState(0); useImperativeHandle( @@ -666,8 +666,8 @@ main() { return react.div({'ref': ref}, count.value); }); - var EmptyDepsComponent = react.forwardRef2((props, ref) { - var count = useState(0); + final EmptyDepsComponent = react.forwardRef2((props, ref) { + final count = useState(0); useImperativeHandle(ref, () => count.value, []); @@ -680,8 +680,8 @@ main() { ]); }); - var DepsComponent = react.forwardRef2((props, ref) { - var count = useState(0); + final DepsComponent = react.forwardRef2((props, ref) { + final count = useState(0); useImperativeHandle(ref, () => count.value, [count.value]); @@ -694,8 +694,8 @@ main() { ]); }); - var NullRefComponent = react.registerFunctionComponent((props) { - var count = useState(0); + final NullRefComponent = react.registerFunctionComponent((props) { + final count = useState(0); Ref someRefThatIsNotSet = props['someRefThatIsNotSet']; useImperativeHandle(someRefThatIsNotSet, () => count.value, [count.value]); diff --git a/test/js_builds/shared_tests.dart b/test/js_builds/shared_tests.dart index e8b4592f..54c3f567 100644 --- a/test/js_builds/shared_tests.dart +++ b/test/js_builds/shared_tests.dart @@ -13,7 +13,7 @@ import 'package:react/react_client/react_interop.dart'; import 'package:test/test.dart'; void verifyJsFileLoaded(String filename) { - var isLoaded = document.getElementsByTagName('script').any((script) { + final isLoaded = document.getElementsByTagName('script').any((script) { return Uri.parse((script as ScriptElement).src).pathSegments.last == filename; }); diff --git a/test/lifecycle_test.dart b/test/lifecycle_test.dart index c80ba4a1..69d96654 100644 --- a/test/lifecycle_test.dart +++ b/test/lifecycle_test.dart @@ -43,8 +43,8 @@ main() { test('throws when setState is called with something other than a Map or Function that accepts two parameters', () { - var mountNode = DivElement(); - var renderedInstance = react_dom.render(components.SetStateTest({}), mountNode); + final mountNode = DivElement(); + final renderedInstance = react_dom.render(components.SetStateTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); expect(() => component.setState(Map()), returnsNormally); @@ -135,7 +135,7 @@ main() { String consoleErrorMessage; JsFunction originalConsoleError; DivElement mountNode; - final String expectedWarningPrefix = 'Warning: Failed prop type: Invalid argument(s): intProp should be int. '; + final expectedWarningPrefix = 'Warning: Failed prop type: Invalid argument(s): intProp should be int. '; setUp(() { consoleErrorCalled = false; @@ -187,10 +187,10 @@ main() { contains(expectedWarningPrefix), reason: 'Did the warning message change? This test will break if the format cannot be converted to json.', ); - RegExp regExp = RegExp(r'.*?({.*}).*', multiLine: true); - var matches = regExp.allMatches(consoleErrorMessage); + final regExp = RegExp(r'.*?({.*}).*', multiLine: true); + final matches = regExp.allMatches(consoleErrorMessage); expect(matches, hasLength(1), reason: 'Should have found a json structure in the error.'); - var match = matches.elementAt(0); // => extract the first (and only) match + final match = matches.elementAt(0); // => extract the first (and only) match Map errorArgs = json.decode(match.group(1)); expect(errorArgs, { 'props': '{intProp: test, children: []}', @@ -208,10 +208,10 @@ main() { 'initialState': 'initial', }; - final Map initialProps = + final initialProps = unmodifiableMap({'getInitialState': (_) => initialState, 'initialState': (_) => initialState}); - final Map expectedProps = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); + final expectedProps = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); LifecycleTestHelper component = getDartComponent(render(components2.LifecycleTest(initialProps))); @@ -258,19 +258,19 @@ main() { 'initialDerivedState': 'updated', }; - final Map initialProps = unmodifiableMap({ + final initialProps = unmodifiableMap({ 'getDerivedStateFromProps': (_, __, ___) => initialDerivedState, 'defaultProp': 'default', 'children': [] }); - final Map updatedProps = unmodifiableMap({ + final updatedProps = unmodifiableMap({ 'getDerivedStateFromProps': (_, __, ___) => updatedDerivedState, 'defaultProp': 'default', 'children': [] }); - var mountNode = DivElement(); + final mountNode = DivElement(); var instance = react_dom.render(components2.LifecycleTest(initialProps), mountNode); LifecycleTestHelper component = getDartComponent(instance); @@ -304,16 +304,16 @@ main() { const Map initialState = { 'foo': 'sudo', }; - final Map initialProps = unmodifiableMap({ + final initialProps = unmodifiableMap({ 'getDerivedStateFromProps': (_, __, ___) => null, 'getInitialState': (_) => initialState, 'initialState': (_) => initialState, }); - final Map expectedProps = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); + final expectedProps = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); - var mountNode = DivElement(); - var instance = react_dom.render(components2.LifecycleTest(initialProps), mountNode); + final mountNode = DivElement(); + final instance = react_dom.render(components2.LifecycleTest(initialProps), mountNode); LifecycleTestHelper component = getDartComponent(instance); @@ -333,8 +333,8 @@ main() { }); test('triggers error lifecycle events when an error is thrown', () { - var mountNode = DivElement(); - var renderedInstance = react_dom.render(components2.SetStateTest({}), mountNode); + final mountNode = DivElement(); + final renderedInstance = react_dom.render(components2.SetStateTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); LifecycleTestHelper.staticLifecycleCalls.clear(); component.setState({'shouldThrow': true}); @@ -371,7 +371,7 @@ main() { 'originalState': true, }; var _shouldThrow = true; - final Map initialProps = unmodifiableMap({ + final initialProps = unmodifiableMap({ 'initialState': (_) => initialState, 'getDerivedStateFromError': (_, __) => null, 'render': (_) { @@ -407,7 +407,7 @@ main() { 'originalState': true, }; var _shouldThrow = true; - final Map initialProps = unmodifiableMap({ + final initialProps = unmodifiableMap({ 'initialState': (_) => initialState, 'render': (_) { if (_shouldThrow) { @@ -441,8 +441,8 @@ main() { }); test('error lifecycle methods get passed Dartified Error/Exception when an error is thrown', () { - var mountNode = DivElement(); - var renderedInstance = react_dom.render(components2.SetStateTest({}), mountNode); + final mountNode = DivElement(); + final renderedInstance = react_dom.render(components2.SetStateTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); LifecycleTestHelper.staticLifecycleCalls.clear(); component.setState({'shouldThrow': true}); @@ -459,8 +459,8 @@ main() { }); test('can skip methods passed into _registerComponent2', () { - var mountNode = DivElement(); - var renderedInstance = react_dom.render(components2.SkipMethodsTest({}), mountNode); + final mountNode = DivElement(); + final renderedInstance = react_dom.render(components2.SkipMethodsTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); LifecycleTestHelper.staticLifecycleCalls.clear(); component.setState({'shouldThrow': true}); @@ -486,8 +486,8 @@ main() { }); test('passes the correct error/info to lifecycle methods when an error is thrown', () { - var mountNode = DivElement(); - var renderedInstance = react_dom.render(components2.SetStateTest({}), mountNode); + final mountNode = DivElement(); + final renderedInstance = react_dom.render(components2.SetStateTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); Element renderedNode = react_dom.findDOMNode(renderedInstance); LifecycleTestHelper.staticLifecycleCalls.clear(); @@ -505,10 +505,10 @@ main() { }); test('defaults toward not being an error boundary', () { - var mountNode = DivElement(); + final mountNode = DivElement(); expect(() { - var renderedInstance = react_dom.render(components2.DefaultSkipMethodsTest({}), mountNode); + final renderedInstance = react_dom.render(components2.DefaultSkipMethodsTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); LifecycleTestHelper.staticLifecycleCalls.clear(); component.setState({'shouldThrow': true}); @@ -533,14 +533,14 @@ main() { }); test('renders correctly', () { - var testProps = {'testProp': 'test'}; + final testProps = {'testProp': 'test'}; react_dom.render(PropsTest(testProps, ['Child']), mountNode); expect(mountNode.innerHtml, 'testChild'); }); test('updates on rerender with new props', () { - var testProps = {'testProp': 'test'}; - var updatedProps = {'testProp': 'test2'}; + final testProps = {'testProp': 'test'}; + final updatedProps = {'testProp': 'test2'}; react_dom.render(PropsTest(testProps, ['Child']), mountNode); expect(mountNode.innerHtml, 'testChild'); react_dom.render(PropsTest(updatedProps, ['Child']), mountNode); @@ -594,7 +594,7 @@ void sharedLifecycleTests({ // Need to run registerComponent in this test, which is what calls getDefaultProps. ReactDartComponentFactoryProxy DefaultPropsTest = react.registerComponent(defaultPropsCachingTestComponentFactory); - var components = [ + final components = [ render(DefaultPropsTest({})), render(DefaultPropsTest({})), render(DefaultPropsTest({})), @@ -606,17 +606,17 @@ void sharedLifecycleTests({ group('are merged into props when the ReactElement is created when', () { test('the specified props are empty', () { - var props = getDartElementProps(DefaultPropsTest({})); + final props = getDartElementProps(DefaultPropsTest({})); expect(props, containsPair('defaultProp', 'default')); }); test('the default props are overridden', () { - var props = getDartElementProps(DefaultPropsTest({'defaultProp': 'overridden'})); + final props = getDartElementProps(DefaultPropsTest({'defaultProp': 'overridden'})); expect(props, containsPair('defaultProp', 'overridden')); }); test('non-default props are added', () { - var props = getDartElementProps(DefaultPropsTest({'otherProp': 'other'})); + final props = getDartElementProps(DefaultPropsTest({'otherProp': 'other'})); expect(props, containsPair('defaultProp', 'default')); expect(props, containsPair('otherProp', 'other')); }); @@ -624,17 +624,17 @@ void sharedLifecycleTests({ group('are merged into props by the time the Dart Component is rendered when', () { test('the specified props are empty', () { - var props = getDartComponentProps(render(DefaultPropsTest({}))); + final props = getDartComponentProps(render(DefaultPropsTest({}))); expect(props, containsPair('defaultProp', 'default')); }); test('the default props are overridden', () { - var props = getDartComponentProps(render(DefaultPropsTest({'defaultProp': 'overridden'}))); + final props = getDartComponentProps(render(DefaultPropsTest({'defaultProp': 'overridden'}))); expect(props, containsPair('defaultProp', 'overridden')); }); test('non-default props are added', () { - var props = getDartComponentProps(render(DefaultPropsTest({'otherProp': 'other'}))); + final props = getDartComponentProps(render(DefaultPropsTest({'otherProp': 'other'}))); expect(props, containsPair('defaultProp', 'default')); expect(props, containsPair('otherProp', 'other')); }); @@ -665,8 +665,8 @@ void sharedLifecycleTests({ }); test('receives correct lifecycle calls on component unmount order', () { - var mountNode = DivElement(); - var instance = react_dom.render(LifecycleTest({}), mountNode); + final mountNode = DivElement(); + final instance = react_dom.render(LifecycleTest({}), mountNode); LifecycleTestHelper component = getDartComponent(instance); component.lifecycleCalls.clear(); @@ -682,8 +682,8 @@ void sharedLifecycleTests({ if (!isComponent2) { test('does not call getChildContext when childContextKeys is empty', () { - var mountNode = DivElement(); - var instance = + final mountNode = DivElement(); + final instance = react_dom.render(ContextWrapperWithoutKeys({'foo': false}, LifecycleTestWithContext({})), mountNode); LifecycleTestHelper component = getDartComponent(instance); @@ -698,8 +698,8 @@ void sharedLifecycleTests({ }); test('calls getChildContext when childContextKeys exist', () { - var mountNode = DivElement(); - var instance = react_dom.render(ContextWrapper({'foo': false}, LifecycleTestWithContext({})), mountNode); + final mountNode = DivElement(); + final instance = react_dom.render(ContextWrapper({'foo': false}, LifecycleTestWithContext({})), mountNode); LifecycleTestHelper component = getDartComponent(instance); expect( @@ -723,10 +723,10 @@ void sharedLifecycleTests({ 'newProp': 'new', }; - final Map initialPropsWithDefaults = unmodifiableMap({} + final initialPropsWithDefaults = unmodifiableMap({} ..addAll(defaultProps) ..addAll(initialProps)); - final Map newPropsWithDefaults = unmodifiableMap({} + final newPropsWithDefaults = unmodifiableMap({} ..addAll(defaultProps) ..addAll(newProps)); @@ -741,11 +741,11 @@ void sharedLifecycleTests({ }; // Add the 'ref' prop separately so it isn't an expected prop since React removes it internally - var initialPropsWithRef = Map.from(initialProps)..addAll(refMap); - var newPropsWithRef = Map.from(newPropsWithDefaults)..addAll(refMap); + final initialPropsWithRef = Map.from(initialProps)..addAll(refMap); + final newPropsWithRef = Map.from(newPropsWithDefaults)..addAll(refMap); // Render the initial instance - var mountNode = DivElement(); + final mountNode = DivElement(); react_dom.render(ContextWrapper({'foo': false}, LifecycleTestWithContext(initialPropsWithRef)), mountNode); // Verify initial context/setup @@ -811,12 +811,12 @@ void sharedLifecycleTests({ 'ref': ((ref) => component = ref), }; - var initialProps = Map.from(defaultProps)..addAll({'children': const []}); + final initialProps = Map.from(defaultProps)..addAll({'children': const []}); // Add the 'ref' prop separately so it isn't an expected prop since React removes it internally - var initialPropsWithRef = Map.from(initialProps)..addAll(refMap); + final initialPropsWithRef = Map.from(initialProps)..addAll(refMap); // Render the initial instance - var mountNode = DivElement(); + final mountNode = DivElement(); react_dom.render( ContextWrapper( {'foo': false}, @@ -875,15 +875,15 @@ void sharedLifecycleTests({ 'ref': ((ref) => component = ref), }; - var initialProps = Map.from(defaultProps) + final initialProps = Map.from(defaultProps) ..addAll(initialContext) ..addAll({'children': const []}); // Add the 'ref' prop separately so it isn't an expected prop since React removes it internally - var initialPropsWithRef = Map.from(initialProps)..addAll(refMap); + final initialPropsWithRef = Map.from(initialProps)..addAll(refMap); - var expectedProps = Map.from(initialProps)..addAll(expectedContext); + final expectedProps = Map.from(initialProps)..addAll(expectedContext); // Render the initial instance - var mountNode = DivElement(); + final mountNode = DivElement(); react_dom.render( ContextWrapper( initialContext, @@ -941,10 +941,10 @@ void sharedLifecycleTests({ const Map initialProps = {'initialProp': 'initial', 'children': []}; const Map newProps = {'newProp': 'new', 'children': []}; - final Map initialPropsWithDefaults = unmodifiableMap({} + final initialPropsWithDefaults = unmodifiableMap({} ..addAll(defaultProps) ..addAll(initialProps)); - final Map newPropsWithDefaults = unmodifiableMap({} + final newPropsWithDefaults = unmodifiableMap({} ..addAll(defaultProps) ..addAll(newProps)); @@ -952,8 +952,8 @@ void sharedLifecycleTests({ final dynamic expectedContext = isComponent2 ? null : const {}; const Null expectedSnapshot = null; - var mountNode = DivElement(); - var instance = react_dom.render(LifecycleTest(initialProps), mountNode); + final mountNode = DivElement(); + final instance = react_dom.render(LifecycleTest(initialProps), mountNode); LifecycleTestHelper component = getDartComponent(instance); component.lifecycleCalls.clear(); @@ -1003,8 +1003,8 @@ void sharedLifecycleTests({ 'initialState': 'initial', }; - final Map initialProps = unmodifiableMap({'initialState': (_) => initialState}); - final Map expectedProps = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); + final initialProps = unmodifiableMap({'initialState': (_) => initialState}); + final expectedProps = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); LifecycleTestHelper component = getDartComponent(render(LifecycleTest(initialProps))); expect( @@ -1050,7 +1050,7 @@ void sharedLifecycleTests({ }); tearDown(() { - var expectedState = updatingStateWithNull ? initialState : newState; + final expectedState = updatingStateWithNull ? initialState : newState; expect( component.lifecycleCalls, (updatingStateWithNull && isComponent2) @@ -1085,7 +1085,7 @@ void sharedLifecycleTests({ }); test('setState with updater argument', () { - var calls = []; + final calls = []; Map stateUpdater(Map prevState, Map props) { calls.add({ 'name': 'stateUpdater', @@ -1118,7 +1118,7 @@ void sharedLifecycleTests({ test('setStateWithUpdater argument that returns null (no re-render)', () { updatingStateWithNull = true; - var calls = []; + final calls = []; Map stateUpdater(Map prevState, Map props) { calls.add({ 'name': 'stateUpdater', @@ -1155,12 +1155,12 @@ void sharedLifecycleTests({ 'initialState': 'initial', }; - final Map initialProps = + final initialProps = unmodifiableMap({'initialState': (_) => initialState, 'getInitialState': (_) => initialState}); final dynamic newContext = isComponent2 ? null : const {}; - final Map expectedProps = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); + final expectedProps = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); final Null expectedSnapshot = null; @@ -1278,20 +1278,20 @@ void sharedLifecycleTests({ }; const Map expectedContext = {}; - final Map lifecycleTestProps = unmodifiableMap({ + final lifecycleTestProps = unmodifiableMap({ 'getInitialState': (_) => initialState, 'componentWillReceiveProps': (LifecycleTestHelper component, Map props) { component.setState(stateDelta); }, }); - final Map initialProps = unmodifiableMap({'initialProp': 'initial'}, lifecycleTestProps); - final Map newProps = unmodifiableMap({'newProp': 'new'}, lifecycleTestProps); + final initialProps = unmodifiableMap({'initialProp': 'initial'}, lifecycleTestProps); + final newProps = unmodifiableMap({'newProp': 'new'}, lifecycleTestProps); - final Map initialPropsWithDefaults = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); - final Map newPropsWithDefaults = unmodifiableMap(defaultProps, newProps, emptyChildrenProps); + final initialPropsWithDefaults = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); + final newPropsWithDefaults = unmodifiableMap(defaultProps, newProps, emptyChildrenProps); - var mountNode = DivElement(); - var instance = react_dom.render(LifecycleTest(initialProps), mountNode); + final mountNode = DivElement(); + final instance = react_dom.render(LifecycleTest(initialProps), mountNode); LifecycleTestHelper component = getDartComponent(instance); component.lifecycleCalls.clear(); @@ -1334,7 +1334,7 @@ void sharedLifecycleTests({ void testShouldUpdates({bool shouldComponentUpdateWithContext, bool shouldComponentUpdate}) { test('receives updated props with correct lifecycle calls and does not rerender', () { final dynamic expectedContext = isComponent2 ? null : const {}; - final Map initialProps = unmodifiableMap({ + final initialProps = unmodifiableMap({ 'shouldComponentUpdate': (_, __, ___) => shouldComponentUpdate, 'shouldComponentUpdateWithContext': (_, __, ___, ____) => shouldComponentUpdateWithContext, 'initialProp': 'initial', @@ -1342,13 +1342,13 @@ void sharedLifecycleTests({ }); const Map newProps = {'newProp': 'new', 'children': []}; - final Map initialPropsWithDefaults = unmodifiableMap(defaultProps, initialProps); - final Map newPropsWithDefaults = unmodifiableMap(defaultProps, newProps); + final initialPropsWithDefaults = unmodifiableMap(defaultProps, initialProps); + final newPropsWithDefaults = unmodifiableMap(defaultProps, newProps); const Map expectedState = {}; - var mountNode = DivElement(); - var instance = react_dom.render(LifecycleTest(initialProps), mountNode); + final mountNode = DivElement(); + final instance = react_dom.render(LifecycleTest(initialProps), mountNode); LifecycleTestHelper component = getDartComponent(instance); component.lifecycleCalls.clear(); @@ -1395,14 +1395,14 @@ void sharedLifecycleTests({ 'newState': 'new', }; - final Map initialProps = unmodifiableMap({ + final initialProps = unmodifiableMap({ 'getInitialState': (_) => initialState, 'initialState': (_) => initialState, 'shouldComponentUpdate': (_, __, ___) => shouldComponentUpdate, 'shouldComponentUpdateWithContext': (_, __, ___, ____) => shouldComponentUpdateWithContext, }); - final Map expectedProps = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); + final expectedProps = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); LifecycleTestHelper component = getDartComponent(render(LifecycleTest(initialProps))); component.lifecycleCalls.clear(); @@ -1444,7 +1444,7 @@ void sharedLifecycleTests({ 'newState': 'new', }; - final Map lifecycleTestProps = unmodifiableMap({ + final lifecycleTestProps = unmodifiableMap({ 'shouldComponentUpdate': (_, __, ___) => shouldComponentUpdate, 'shouldComponentUpdateWithContext': (_, __, ___, ____) => shouldComponentUpdateWithContext, 'getInitialState': (_) => initialState, @@ -1452,16 +1452,16 @@ void sharedLifecycleTests({ component.setState(stateDelta); }, }); - final Map initialProps = unmodifiableMap({'initialProp': 'initial'}, lifecycleTestProps); - final Map newProps = unmodifiableMap({'newProp': 'new'}, lifecycleTestProps); + final initialProps = unmodifiableMap({'initialProp': 'initial'}, lifecycleTestProps); + final newProps = unmodifiableMap({'newProp': 'new'}, lifecycleTestProps); - final Map initialPropsWithDefaults = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); - final Map newPropsWithDefaults = unmodifiableMap(defaultProps, newProps, emptyChildrenProps); + final initialPropsWithDefaults = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); + final newPropsWithDefaults = unmodifiableMap(defaultProps, newProps, emptyChildrenProps); final Map expectedContext = const {}; - var mountNode = DivElement(); - var instance = react_dom.render(LifecycleTest(initialProps), mountNode); + final mountNode = DivElement(); + final instance = react_dom.render(LifecycleTest(initialProps), mountNode); LifecycleTestHelper component = getDartComponent(instance); component.lifecycleCalls.clear(); @@ -1511,8 +1511,8 @@ void sharedLifecycleTests({ LifecycleTestHelper component; setUp(() { - var mountNode = DivElement(); - var renderedInstance = react_dom.render(SetStateTest({}), mountNode); + final mountNode = DivElement(); + final renderedInstance = react_dom.render(SetStateTest({}), mountNode); component = getDartComponent(renderedInstance); component.lifecycleCalls.clear(); }); @@ -1540,8 +1540,8 @@ void sharedLifecycleTests({ group('calls the setState callback, and transactional setState callback in the correct order', () { test('when shouldComponentUpdate returns false', () { - var mountNode = DivElement(); - var renderedInstance = react_dom.render(SetStateTest({'shouldUpdate': false}), mountNode); + final mountNode = DivElement(); + final renderedInstance = react_dom.render(SetStateTest({'shouldUpdate': false}), mountNode); Element renderedNode = react_dom.findDOMNode(renderedInstance); LifecycleTestHelper component = getDartComponent(renderedInstance); @@ -1563,8 +1563,8 @@ void sharedLifecycleTests({ }); test('when shouldComponentUpdate returns true', () { - var mountNode = DivElement(); - var renderedInstance = react_dom.render(SetStateTest({}), mountNode); + final mountNode = DivElement(); + final renderedInstance = react_dom.render(SetStateTest({}), mountNode); Element renderedNode = react_dom.findDOMNode(renderedInstance); LifecycleTestHelper component = getDartComponent(renderedInstance); diff --git a/test/lifecycle_test/component2.dart b/test/lifecycle_test/component2.dart index c5980de7..5500e8a9 100644 --- a/test/lifecycle_test/component2.dart +++ b/test/lifecycle_test/component2.dart @@ -155,7 +155,7 @@ class PropTypesTestComponent extends react.Component2 { @override get propTypes => { 'intProp': (Map props, info) { - var propValue = props[info.propName]; + final propValue = props[info.propName]; if (propValue is! int) { return ArgumentError( '${info.propName} should be int. {"props": "$props", "propName": "${info.propName}", "componentName": "${info.componentName}", "location": "${info.location}", "propFullName": "${info.propFullName}"}'); diff --git a/test/lifecycle_test/util.dart b/test/lifecycle_test/util.dart index 02afc5e2..f4455955 100644 --- a/test/lifecycle_test/util.dart +++ b/test/lifecycle_test/util.dart @@ -40,7 +40,7 @@ mixin LifecycleTestHelper on Component { 'context': context, }); - var lifecycleCallback = props == null + final lifecycleCallback = props == null ? staticProps == null ? null : staticProps[memberName] diff --git a/test/react_client/event_helpers_test.dart b/test/react_client/event_helpers_test.dart index 5d4b50d0..742e209c 100644 --- a/test/react_client/event_helpers_test.dart +++ b/test/react_client/event_helpers_test.dart @@ -99,10 +99,10 @@ main() { } test('wrapNativeKeyboardEvent', () { - var nativeKeyboardEvent = MockKeyboardEvent(); - var currentTarget = DivElement(); - var target = DivElement(); - var calls = []; + final nativeKeyboardEvent = MockKeyboardEvent(); + final currentTarget = DivElement(); + final target = DivElement(); + final calls = []; when(nativeKeyboardEvent.bubbles).thenReturn(true); when(nativeKeyboardEvent.cancelable).thenReturn(true); @@ -125,7 +125,7 @@ main() { expect(nativeKeyboardEvent.defaultPrevented, isFalse); - var syntheticKeyboardEvent = wrapNativeKeyboardEvent(nativeKeyboardEvent); + final syntheticKeyboardEvent = wrapNativeKeyboardEvent(nativeKeyboardEvent); expect(syntheticKeyboardEvent, isA()); @@ -157,11 +157,11 @@ main() { }); test('wrapNativeMouseEvent', () { - var nativeMouseEvent = MockMouseEvent(); - var currentTarget = DivElement(); - var target = DivElement(); - var relatedTarget = DivElement(); - var calls = []; + final nativeMouseEvent = MockMouseEvent(); + final currentTarget = DivElement(); + final target = DivElement(); + final relatedTarget = DivElement(); + final calls = []; when(nativeMouseEvent.bubbles).thenReturn(true); when(nativeMouseEvent.cancelable).thenReturn(true); @@ -183,7 +183,7 @@ main() { when(nativeMouseEvent.page).thenReturn(Point(3, 4)); when(nativeMouseEvent.screen).thenReturn(Point(5, 6)); - var syntheticMouseEvent = wrapNativeMouseEvent(nativeMouseEvent); + final syntheticMouseEvent = wrapNativeMouseEvent(nativeMouseEvent); expect(syntheticMouseEvent, isA()); @@ -218,8 +218,8 @@ main() { }); test('fakeSyntheticFormEvent', () { - var element = DivElement(); - var fakeEvent = fakeSyntheticFormEvent(element, 'change'); + final element = DivElement(); + final fakeEvent = fakeSyntheticFormEvent(element, 'change'); expect(fakeEvent, isA()); diff --git a/test/react_client_test.dart b/test/react_client_test.dart index 37312e6b..f612f649 100644 --- a/test/react_client_test.dart +++ b/test/react_client_test.dart @@ -19,8 +19,8 @@ import 'package:react/src/react_client/event_prop_key_to_event_factory.dart'; main() { group('unconvertJsProps', () { - const List testChildren = ['child1', 'child2']; - const Map testStyle = {'background': 'white'}; + const testChildren = ['child1', 'child2']; + const testStyle = {'background': 'white'}; test('returns props for a composite JS component ReactElement', () { ReactElement instance = testJsComponentFactory({ @@ -58,7 +58,7 @@ main() { }); test('returns props for a composite JS ReactComponent', () { - var mountNode = DivElement(); + final mountNode = DivElement(); ReactComponent renderedInstance = react_dom.render( testJsComponentFactory({ 'jsProp': 'js', @@ -77,7 +77,7 @@ main() { }); test('returns props for a composite JS ReactComponent, even when the props change', () { - var mountNode = DivElement(); + final mountNode = DivElement(); ReactComponent renderedInstance = react_dom.render( testJsComponentFactory({ 'jsProp': 'js', @@ -142,8 +142,8 @@ main() { }); test('for a DOM element', () { - var component = react.div(props); - var jsProps = unconvertJsProps(component); + final component = react.div(props); + final jsProps = unconvertJsProps(component); for (final key in knownEventKeys) { expect(jsProps[key], isNotNull, reason: 'JS event handler prop should not be null'); expect(jsProps[key], anyOf(same(originalHandlers[key]), same(allowInterop(originalHandlers[key]))), @@ -152,8 +152,8 @@ main() { }); test(', except for a JS composite component (handlers should already be unconverted)', () { - var component = testJsComponentFactory(props); - var jsProps = unconvertJsProps(component); + final component = testJsComponentFactory(props); + final jsProps = unconvertJsProps(component); for (final key in knownEventKeys) { expect(jsProps[key], isNotNull, reason: 'JS event handler prop should not be null'); expect(jsProps[key], same(allowInterop(originalHandlers[key])), diff --git a/test/react_context_test.dart b/test/react_context_test.dart index 534cd3b0..11b2a0d3 100644 --- a/test/react_context_test.dart +++ b/test/react_context_test.dart @@ -14,7 +14,7 @@ import 'shared_type_tester.dart'; main() { void testTypeValue(dynamic typeToTest) { - var mountNode = html.DivElement(); + final mountNode = html.DivElement(); var contextTypeRef; var consumerRef; react_dom.render( @@ -45,7 +45,7 @@ main() { }); group('calculateChangeBits argument functions correctly', () { - var mountNode = html.DivElement(); + final mountNode = html.DivElement(); _ContextProviderWrapper providerRef; _ContextConsumerWrapper consumerEvenRef; _ContextConsumerWrapper consumerOddRef; @@ -100,7 +100,7 @@ main() { } int calculateChangedBits(currentValue, nextValue) { - int result = 0; + var result = 0; if (nextValue % 2 == 0) { // Bit for even values result |= 1 << 2; diff --git a/test/react_fragment_test.dart b/test/react_fragment_test.dart index 0944a46f..e0f590be 100644 --- a/test/react_fragment_test.dart +++ b/test/react_fragment_test.dart @@ -36,7 +36,7 @@ main() { test('passes the key properly onto the fragment', () { var callCount = 0; - var mountElement = Element.div(); + final mountElement = Element.div(); react_dom.render( react.Fragment({ diff --git a/test/react_suspense_test.dart b/test/react_suspense_test.dart index 4245ffd4..4e1c3e89 100644 --- a/test/react_suspense_test.dart +++ b/test/react_suspense_test.dart @@ -44,7 +44,7 @@ main() { return simple.SimpleFunctionComponent; }); var wrappingDivRef; - var mountElement = Element.div(); + final mountElement = Element.div(); react_dom.render( react.div({ 'ref': (ref) { @@ -78,8 +78,8 @@ main() { }); var wrappingDivRef; var wrappingDivRef2; - var mountElement = Element.div(); - var mountElement2 = Element.div(); + final mountElement = Element.div(); + final mountElement2 = Element.div(); react_dom.render( react.div({ diff --git a/test/react_test_utils_test.dart b/test/react_test_utils_test.dart index 117c4e25..60b4ef3b 100644 --- a/test/react_test_utils_test.dart +++ b/test/react_test_utils_test.dart @@ -48,8 +48,8 @@ testUtils({isComponent2 = false, dynamic eventComponent, dynamic sampleComponent }); tearDown(() { - ReactElement renderedOutput = shallowRenderer.getRenderOutput(); - var props = getProps(renderedOutput); + final renderedOutput = shallowRenderer.getRenderOutput(); + final props = getProps(renderedOutput); expect(props['className'], 'test'); expect(props['id'], 'createRendererTest'); @@ -205,7 +205,7 @@ testUtils({isComponent2 = false, dynamic eventComponent, dynamic sampleComponent const testKeyCode = 42; String callInfo; - bool wasStopPropagationCalled = false; + var wasStopPropagationCalled = false; final renderedNode = renderIntoDocument(div({ 'onKeyDown': (event) { @@ -228,21 +228,21 @@ testUtils({isComponent2 = false, dynamic eventComponent, dynamic sampleComponent test('findRenderedDOMComponentWithClass on a Component${isComponent2 ? "2" : ""}', () { component = renderIntoDocument(sampleComponent({})); - var spanComponent = findRenderedDOMComponentWithClass(component, 'span1'); + final spanComponent = findRenderedDOMComponentWithClass(component, 'span1'); expect(getProperty(spanComponent, 'tagName'), equals('SPAN')); }); test('findRenderedDOMComponentWithTag on a Component${isComponent2 ? "2" : ""}', () { component = renderIntoDocument(sampleComponent({})); - var h1Component = findRenderedDOMComponentWithTag(component, 'h1'); + final h1Component = findRenderedDOMComponentWithTag(component, 'h1'); expect(getProperty(h1Component, 'tagName'), equals('H1')); }); test('findRenderedComponentWithTypeV2 on a Component${isComponent2 ? "2" : ""}', () { component = renderIntoDocument(wrapperComponent({}, [sampleComponent({})])); - var result = findRenderedComponentWithTypeV2(component, sampleComponent); + final result = findRenderedComponentWithTypeV2(component, sampleComponent); expect(isCompositeComponentWithTypeV2(result, sampleComponent), isTrue); }); @@ -261,7 +261,7 @@ testUtils({isComponent2 = false, dynamic eventComponent, dynamic sampleComponent }); group('isCompositeComponentWithTypeV2 on a Component${isComponent2 ? "2" : ""}', () { - var renderedInstance = renderIntoDocument(sampleComponent({})); + final renderedInstance = renderIntoDocument(sampleComponent({})); test('returns true when element is a composite component (created with React.createClass()) of the specified type', () { @@ -278,7 +278,7 @@ testUtils({isComponent2 = false, dynamic eventComponent, dynamic sampleComponent group('isDOMComponent on a Component${isComponent2 ? "2" : ""}', () { test('returns true when argument is a DOM component', () { component = renderIntoDocument(sampleComponent({})); - var h1Element = findRenderedDOMComponentWithTag(component, 'h1'); + final h1Element = findRenderedDOMComponentWithTag(component, 'h1'); expect(isDOMComponent(h1Element), isTrue); }); @@ -312,7 +312,7 @@ testUtils({isComponent2 = false, dynamic eventComponent, dynamic sampleComponent component = renderIntoDocument(wrapperComponent({}, [sampleComponent({}), sampleComponent({}), eventComponent({})])); - var results = scryRenderedComponentsWithTypeV2(component, sampleComponent); + final results = scryRenderedComponentsWithTypeV2(component, sampleComponent); expect(results.length, 2); expect(isCompositeComponentWithTypeV2(results[0], sampleComponent), isTrue); @@ -326,7 +326,7 @@ testUtils({isComponent2 = false, dynamic eventComponent, dynamic sampleComponent span({}) ])); - var results = scryRenderedDOMComponentsWithClass(component, 'divClass'); + final results = scryRenderedDOMComponentsWithClass(component, 'divClass'); expect(results.length, 2); expect(getProperty(results[0], 'tagName'), equals('DIV')); @@ -336,7 +336,7 @@ testUtils({isComponent2 = false, dynamic eventComponent, dynamic sampleComponent test('scryRenderedDOMComponentsWithTag', () { component = renderIntoDocument(wrapperComponent({}, [div({}), div({}), span({})])); - var results = scryRenderedDOMComponentsWithTag(component, 'div'); + final results = scryRenderedDOMComponentsWithTag(component, 'div'); expect(results.length, 3); expect(getProperty(results[0], 'tagName'), equals('DIV')); @@ -345,10 +345,10 @@ testUtils({isComponent2 = false, dynamic eventComponent, dynamic sampleComponent }); test('renderIntoDocument with a Component${isComponent2 ? "2" : ""}', () { - var reactComponent = renderIntoDocument(sampleComponent({})); - var divElements = scryRenderedDOMComponentsWithTag(reactComponent, 'div'); - var h1Elements = scryRenderedDOMComponentsWithTag(reactComponent, 'h1'); - var spanElements = scryRenderedDOMComponentsWithTag(reactComponent, 'span'); + final reactComponent = renderIntoDocument(sampleComponent({})); + final divElements = scryRenderedDOMComponentsWithTag(reactComponent, 'div'); + final h1Elements = scryRenderedDOMComponentsWithTag(reactComponent, 'h1'); + final spanElements = scryRenderedDOMComponentsWithTag(reactComponent, 'span'); expect(divElements.length, equals(3)); // First div should be the parent div created by renderIntoDocument() diff --git a/test/util.dart b/test/util.dart index 80c2da38..ea62dc55 100644 --- a/test/util.dart +++ b/test/util.dart @@ -15,7 +15,7 @@ import 'package:react/src/js_interop_util.dart'; import 'package:test/test.dart'; Map getProps(dynamic elementOrComponent) { - var props = elementOrComponent.props; + final props = elementOrComponent.props; return Map.fromIterable(objectKeys(props), value: (key) => getProperty(props, key)); } @@ -46,7 +46,7 @@ ReactComponent render(ReactElement reactElement) { /// Returns a new [Map.unmodifiable] with all argument maps merged in. Map unmodifiableMap([Map map1, Map map2, Map map3, Map map4]) { - var merged = {}; + final merged = {}; if (map1 != null) merged.addAll(map1); if (map2 != null) merged.addAll(map2); if (map3 != null) merged.addAll(map3); @@ -55,7 +55,7 @@ Map unmodifiableMap([Map map1, Map map2, Map map3, Map map4]) { } bool assertsEnabled() { - bool assertsEnabled = false; + var assertsEnabled = false; assert(assertsEnabled = true); return assertsEnabled; } From 46a38d201a8b41b8322f3c6335f279a6b872a505 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 15:19:40 -0700 Subject: [PATCH 09/31] Fix missing inferred generics --- example/test/function_component_test.dart | 6 +++--- test/hooks_test.dart | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/example/test/function_component_test.dart b/example/test/function_component_test.dart index 3537d93f..eaaca2ab 100644 --- a/example/test/function_component_test.dart +++ b/example/test/function_component_test.dart @@ -114,7 +114,7 @@ Map reducer(Map state, Map action) { } UseReducerTestComponent(Map props) { - final state = useReducerLazy(reducer, props['initialCount'], initializeCount); + final state = useReducerLazy(reducer, props['initialCount'] as int, initializeCount); return react.Fragment({}, [ state.state['count'], @@ -297,7 +297,7 @@ final randomUseLayoutEffectTestComponent = react.registerFunctionComponent(RandomUseLayoutEffectTestComponent, displayName: 'randomUseLayoutEffectTest'); RandomUseLayoutEffectTestComponent(Map props) { - final value = useState(0); + final value = useState(0); useLayoutEffect(() { if (value.value == 0) { @@ -317,7 +317,7 @@ final randomUseEffectTestComponent = react.registerFunctionComponent(RandomUseEffectTestComponent, displayName: 'randomUseEffectTest'); RandomUseEffectTestComponent(Map props) { - final value = useState(0); + final value = useState(0); useEffect(() { if (value.value == 0) { diff --git a/test/hooks_test.dart b/test/hooks_test.dart index 9290628d..53d8bf2e 100644 --- a/test/hooks_test.dart +++ b/test/hooks_test.dart @@ -212,7 +212,7 @@ main() { final mountNode = DivElement(); UseReducerTest = react.registerFunctionComponent((Map props) { - final state = useReducerLazy(reducer2, props['initialCount'], initializeCount); + final state = useReducerLazy(reducer2, props['initialCount'] as int, initializeCount); return react.div({}, [ react.div({ From 17b30ccbafad7b9c206707e745b7771b87080844 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 15:26:31 -0700 Subject: [PATCH 10/31] dart fix --apply --code=use_function_type_syntax_for_parameters,prefer_generic_function_type_aliases --- example/suspense/suspense.dart | 2 +- lib/hooks.dart | 6 +++--- lib/react.dart | 16 ++++++++-------- lib/react_client/react_interop.dart | 2 +- lib/src/typedefs.dart | 8 ++++---- test/factory/common_factory_tests.dart | 10 +++++----- test/lifecycle_test/util.dart | 2 +- test/react_suspense_test.dart | 2 +- test/react_test_utils_test.dart | 4 ++-- 9 files changed, 26 insertions(+), 26 deletions(-) diff --git a/example/suspense/suspense.dart b/example/suspense/suspense.dart index 0767f174..4e7e8372 100644 --- a/example/suspense/suspense.dart +++ b/example/suspense/suspense.dart @@ -18,7 +18,7 @@ external ReactClass jsLazy(Promise Function() factory); // Only intended for testing purposes, Please do not copy/paste this into repo. // This will most likely be added to the PUBLIC api in the future, // but needs more testing and Typing decisions to be made first. -ReactJsComponentFactoryProxy lazy(Future factory()) => ReactJsComponentFactoryProxy( +ReactJsComponentFactoryProxy lazy(Future Function() factory) => ReactJsComponentFactoryProxy( jsLazy( allowInterop( () => futureToPromise( diff --git a/lib/hooks.dart b/lib/hooks.dart index 4af5e706..0f61c449 100644 --- a/lib/hooks.dart +++ b/lib/hooks.dart @@ -33,7 +33,7 @@ class StateHook { /// initialize [_value] to the return value of [init]. /// /// See: . - StateHook.lazy(T init()) { + StateHook.lazy(T Function() init) { final result = React.useState(allowInterop(init)); _value = result[0]; _setValue = result[1]; @@ -52,7 +52,7 @@ class StateHook { /// Updates [value] to the return value of [computeNewValue]. /// /// See: . - void setWithUpdater(T computeNewValue(T oldValue)) => _setValue(allowInterop(computeNewValue)); + void setWithUpdater(T Function(T oldValue) computeNewValue) => _setValue(allowInterop(computeNewValue)); } /// Adds local state to a [DartFunctionComponent] @@ -100,7 +100,7 @@ StateHook useState(T initialValue) => StateHook(initialValue); /// ``` /// /// Learn more: . -StateHook useStateLazy(T init()) => StateHook.lazy(init); +StateHook useStateLazy(T Function() init) => StateHook.lazy(init); /// Runs [sideEffect] after every completed render of a [DartFunctionComponent]. /// diff --git a/lib/react.dart b/lib/react.dart index 079e449a..53952100 100644 --- a/lib/react.dart +++ b/lib/react.dart @@ -27,7 +27,7 @@ export 'package:react/src/react_client/synthetic_event_wrappers.dart' hide NonNa export 'package:react/src/react_client/synthetic_data_transfer.dart' show SyntheticDataTransfer; export 'package:react/src/react_client/event_helpers.dart'; -typedef Error PropValidator(TProps props, PropValidatorInfo info); +typedef PropValidator = Error Function(TProps props, PropValidatorInfo info); /// A React component declared using a function that takes in [props] and returns rendered output. /// @@ -45,18 +45,18 @@ typedef DartFunctionComponent = dynamic Function(JsBackedMap props); /// and not just a ref object, so we type [ref] as dynamic here. typedef DartForwardRefFunctionComponent = dynamic Function(JsBackedMap props, dynamic ref); -typedef T ComponentFactory(); +typedef ComponentFactory = T Function(); -typedef ReactComponentFactoryProxy ComponentRegistrar(ComponentFactory componentFactory, +typedef ComponentRegistrar = ReactComponentFactoryProxy Function(ComponentFactory componentFactory, [Iterable skipMethods]); -typedef ReactDartComponentFactoryProxy2 ComponentRegistrar2( +typedef ComponentRegistrar2 = ReactDartComponentFactoryProxy2 Function( ComponentFactory componentFactory, { Iterable skipMethods, Component2BridgeFactory bridgeFactory, }); -typedef ReactDartFunctionComponentFactoryProxy FunctionComponentRegistrar(DartFunctionComponent componentFactory, +typedef FunctionComponentRegistrar = ReactDartFunctionComponentFactoryProxy Function(DartFunctionComponent componentFactory, {String displayName}); /// Fragment component that allows the wrapping of children without the necessity of using @@ -318,7 +318,7 @@ abstract class Component { /// Force a call to [render] by calling [setState], which effectively "redraws" the `Component`. /// /// Optionally accepts a [callback] that gets called after the component updates. - void redraw([callback()]) { + void redraw([Function() callback]) { setState({}, callback); } @@ -329,7 +329,7 @@ abstract class Component { /// Also allows [newState] to be used as a transactional `setState` callback. /// /// See: - void setState(covariant dynamic newState, [callback()]) { + void setState(covariant dynamic newState, [Function() callback]) { if (newState is Map) { _nextState.addAll(newState); } else if (newState is StateUpdaterCallback) { @@ -354,7 +354,7 @@ abstract class Component { /// > /// > Use [setState] instead. @Deprecated('7.0.0') - void replaceState(Map newState, [callback()]) { + void replaceState(Map newState, [Function() callback]) { final nextState = newState == null ? {} : Map.from(newState); _nextState = nextState; if (callback != null) _setStateCallbacks.add(callback); diff --git a/lib/react_client/react_interop.dart b/lib/react_client/react_interop.dart index b8fbd370..cd1a64dd 100644 --- a/lib/react_client/react_interop.dart +++ b/lib/react_client/react_interop.dart @@ -26,7 +26,7 @@ import 'package:react/src/js_interop_util.dart'; import 'package:react/src/react_client/dart2_interop_workaround_bindings.dart'; typedef ReactElement ReactJsComponentFactory(props, children); -typedef dynamic JsPropValidator( +typedef JsPropValidator = dynamic Function( JsMap props, String propName, String componentName, String location, String propFullName, String secret); // ---------------------------------------------------------------------------- diff --git a/lib/src/typedefs.dart b/lib/src/typedefs.dart index 0f7f0e48..fe086251 100644 --- a/lib/src/typedefs.dart +++ b/lib/src/typedefs.dart @@ -6,7 +6,7 @@ import 'package:react/react_client/js_backed_map.dart'; /// The type of `Component.ref` specified as a callback. /// /// See: -typedef CallbackRef(T componentOrDomNode); +typedef CallbackRef = Function(T componentOrDomNode); /// The function signature for ReactJS Function Components. /// @@ -21,14 +21,14 @@ typedef JsForwardRefFunctionComponent = dynamic Function(JsMap props, dynamic re /// /// * `react.Component` if it is a Dart component. /// * `Element` _(DOM node)_ if it is a React DOM component. -typedef dynamic RefMethod(String ref); +typedef RefMethod = dynamic Function(String ref); /// Typedef for the `updater` argument of [Component2.setStateWithUpdater]. /// /// See: -typedef Map StateUpdaterCallback(Map prevState, Map props); +typedef StateUpdaterCallback = Map Function(Map prevState, Map props); /// Typedef of a non-transactional [Component2.setState] callback. /// /// See: -typedef SetStateCallback(); +typedef SetStateCallback = Function(); diff --git a/test/factory/common_factory_tests.dart b/test/factory/common_factory_tests.dart index 58b1c984..ee51df05 100644 --- a/test/factory/common_factory_tests.dart +++ b/test/factory/common_factory_tests.dart @@ -45,7 +45,7 @@ void commonFactoryTests(ReactComponentFactoryProxy factory, expect(ReactDartComponentVersion.fromType(factory.type), dartComponentVersion); }); - void sharedChildrenTests(dynamic getChildren(ReactElement instance), + void sharedChildrenTests(dynamic Function(ReactElement instance) getChildren, {@required bool shouldAlwaysBeList, Map props = const {}}) { // There are different code paths for 0, 1, 2, 3, 4, 5, 6, and 6+ arguments. // Test all of them. @@ -368,8 +368,8 @@ void domEventHandlerWrappingTests(ReactComponentFactoryProxy factory) { /// It will be called with the actual ref value for JS refs, (e.g., JS ref objects as opposed to Dart objects) void refTests( ReactComponentFactoryProxy factory, { - @required void verifyRefValue(dynamic refValue), - void verifyJsRefValue(dynamic refValue), + void Function(dynamic refValue) verifyRefValue, + void Function(dynamic refValue) verifyJsRefValue, }) { if (T == dynamic) { throw ArgumentError('Generic parameter T must be specified'); @@ -601,7 +601,7 @@ class _StringRefOwnerOwnerHelperComponent extends react.Component { /// Renders the provided [render] function with a Component owner that supports string refs, /// for string ref tests. -ReactComponent _renderWithStringRefSupportingOwner(ReactElement render()) { +ReactComponent _renderWithStringRefSupportingOwner(ReactElement Function() render) { final factory = react.registerComponent(() => _StringRefOwnerOwnerHelperComponent()) as ReactDartComponentFactoryProxy; @@ -613,7 +613,7 @@ int _nextFactoryId = 0; /// Renders the provided [render] function with a Component2 owner that will have a unique name. /// /// This prevents React JS from not printing key warnings it deems as "duplicates". -void _renderWithUniqueOwnerName(ReactElement render()) { +void _renderWithUniqueOwnerName(ReactElement Function() render) { final factory = react.registerComponent2(() => _UniqueOwnerHelperComponent()); factory.reactClass.displayName = 'OwnerHelperComponent_$_nextFactoryId'; _nextFactoryId++; diff --git a/test/lifecycle_test/util.dart b/test/lifecycle_test/util.dart index f4455955..20eef874 100644 --- a/test/lifecycle_test/util.dart +++ b/test/lifecycle_test/util.dart @@ -31,7 +31,7 @@ mixin LifecycleTestHelper on Component { return call['memberName']; }).toList(); - dynamic lifecycleCall(String memberName, {List arguments = const [], defaultReturnValue(), Map staticProps}) { + dynamic lifecycleCall(String memberName, {List arguments = const [], Function() defaultReturnValue, Map staticProps}) { lifecycleCalls.add({ 'memberName': memberName, 'arguments': arguments, diff --git a/test/react_suspense_test.dart b/test/react_suspense_test.dart index 4e1c3e89..e1054753 100644 --- a/test/react_suspense_test.dart +++ b/test/react_suspense_test.dart @@ -22,7 +22,7 @@ external ReactClass jsLazy(Promise Function() factory); // Only intended for testing purposes, Please do not copy/paste this into repo. // This will most likely be added to the PUBLIC api in the future, // but needs more testing and Typing decisions to be made first. -ReactJsComponentFactoryProxy lazy(Future factory()) => ReactJsComponentFactoryProxy( +ReactJsComponentFactoryProxy lazy(Future Function() factory) => ReactJsComponentFactoryProxy( jsLazy( allowInterop( () => futureToPromise( diff --git a/test/react_test_utils_test.dart b/test/react_test_utils_test.dart index 60b4ef3b..f003a0c4 100644 --- a/test/react_test_utils_test.dart +++ b/test/react_test_utils_test.dart @@ -72,9 +72,9 @@ testUtils({isComponent2 = false, dynamic eventComponent, dynamic sampleComponent }); void testEvent( - void event(dynamic instanceOrNode, Map eventData), + void Function(dynamic instanceOrNode, Map eventData) event, String eventName, - void expectEventType(SyntheticEvent e), + void Function(SyntheticEvent e) expectEventType, ) { final eventHandlerName = 'on${eventName[0].toUpperCase() + eventName.substring(1)}'; eventName = eventName.toLowerCase(); From b79d3ebb08576c9171ec455700193a054b6b2050 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 15:39:24 -0700 Subject: [PATCH 11/31] Fix more typedefs --- lib/react_client/react_interop.dart | 2 +- lib/react_test_utils.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/react_client/react_interop.dart b/lib/react_client/react_interop.dart index cd1a64dd..a035e12d 100644 --- a/lib/react_client/react_interop.dart +++ b/lib/react_client/react_interop.dart @@ -25,7 +25,7 @@ import 'package:react/react_client/zone.dart'; import 'package:react/src/js_interop_util.dart'; import 'package:react/src/react_client/dart2_interop_workaround_bindings.dart'; -typedef ReactElement ReactJsComponentFactory(props, children); +typedef ReactJsComponentFactory = ReactElement Function(dynamic props, dynamic children); typedef JsPropValidator = dynamic Function( JsMap props, String propName, String componentName, String location, String propFullName, String secret); diff --git a/lib/react_test_utils.dart b/lib/react_test_utils.dart index 0c00efd9..2ee735d3 100644 --- a/lib/react_test_utils.dart +++ b/lib/react_test_utils.dart @@ -38,7 +38,7 @@ import 'package:react/src/react_test_utils/simulate_wrappers.dart' as sw; /// * For custom composite components React.createClass()-based components, this will return the [ReactClass]. dynamic getComponentTypeV2(ReactComponentFactoryProxy componentFactory) => componentFactory.type; -typedef bool ComponentTestFunction(/* [1] */ component); +typedef ComponentTestFunction = bool Function(dynamic /* [1] */ component); dynamic _jsifyEventData(Map eventData) => jsifyAndAllowInterop(eventData ?? const {}); From 6490a9cb7c45998a03c64f8cd4dbdb5cdcc6c6d3 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 15:47:40 -0700 Subject: [PATCH 12/31] dart fix --apply --code=unnecessary_this --- example/js_components/js_components.dart | 4 ++-- example/test/function_component_test.dart | 16 ++++++++-------- example/test/get_dom_node_test.dart | 2 +- example/test/react_test_components.dart | 20 ++++++++++---------- lib/react.dart | 6 +++--- lib/react_client/component_factory.dart | 20 ++++++++++---------- test/hooks_test.dart | 2 +- test/lifecycle_test/component2.dart | 2 +- test/react_context_test.dart | 4 ++-- test/react_memo_test.dart | 10 +++++----- 10 files changed, 43 insertions(+), 43 deletions(-) diff --git a/example/js_components/js_components.dart b/example/js_components/js_components.dart index bee8ce77..40634e6b 100644 --- a/example/js_components/js_components.dart +++ b/example/js_components/js_components.dart @@ -26,13 +26,13 @@ class _IndexComponent extends react.Component2 { }; handleClose(_) { - this.setState({ + setState({ 'open': false, }); } handleClick(_) { - this.setState({ + setState({ 'open': true, }); print(simpleRef.getFoo()); diff --git a/example/test/function_component_test.dart b/example/test/function_component_test.dart index eaaca2ab..e0ba2348 100644 --- a/example/test/function_component_test.dart +++ b/example/test/function_component_test.dart @@ -46,24 +46,24 @@ class _MemoTestDemoWrapper extends react.Component2 { return react.div( {'key': 'mtdw'}, MemoTest({ - 'localCount': this.state['localCount'], - 'someKeyThatMemoShouldIgnore': this.state['someKeyThatMemoShouldIgnore'], + 'localCount': state['localCount'], + 'someKeyThatMemoShouldIgnore': state['someKeyThatMemoShouldIgnore'], }), react.button({ 'type': 'button', 'className': 'btn btn-primary', 'style': {'marginRight': '10px'}, 'onClick': (_) { - this.setState({'localCount': this.state['localCount'] + 1}); + setState({'localCount': state['localCount'] + 1}); }, - }, 'Update MemoTest props.localCount value (${this.state['localCount']})'), + }, 'Update MemoTest props.localCount value (${state['localCount']})'), react.button({ 'type': 'button', 'className': 'btn btn-primary', 'onClick': (_) { - this.setState({'someKeyThatMemoShouldIgnore': this.state['someKeyThatMemoShouldIgnore'] + 1}); + setState({'someKeyThatMemoShouldIgnore': state['someKeyThatMemoShouldIgnore'] + 1}); }, - }, 'Update prop value that MemoTest will ignore (${this.state['someKeyThatMemoShouldIgnore']})'), + }, 'Update prop value that MemoTest will ignore (${state['someKeyThatMemoShouldIgnore']})'), ); } } @@ -195,7 +195,7 @@ class _NewContextProviderComponent extends react.Component2 { @override render() { - final provideMap = {'renderCount': this.state['renderCount']}; + final provideMap = {'renderCount': state['renderCount']}; return react.div({ 'key': 'ulasda', @@ -221,7 +221,7 @@ class _NewContextProviderComponent extends react.Component2 { } _onButtonClick(event) { - this.setState({'renderCount': this.state['renderCount'] + 1, 'complexMap': false}); + setState({'renderCount': state['renderCount'] + 1, 'complexMap': false}); } } diff --git a/example/test/get_dom_node_test.dart b/example/test/get_dom_node_test.dart index dfa812f9..3d8d26a6 100644 --- a/example/test/get_dom_node_test.dart +++ b/example/test/get_dom_node_test.dart @@ -48,7 +48,7 @@ class SimpleComponent extends react.Component { componentDidMount() { customAssert('ref to span return span ', refToSpan.text == 'Test'); customAssert('findDOMNode works on this', react_dom.findDOMNode(this) != null); - customAssert('random ref resolves to null', this.ref('someRandomRef') == null); + customAssert('random ref resolves to null', ref('someRandomRef') == null); } var counter = 0; diff --git a/example/test/react_test_components.dart b/example/test/react_test_components.dart index 1e30a9c6..4470c007 100644 --- a/example/test/react_test_components.dart +++ b/example/test/react_test_components.dart @@ -57,7 +57,7 @@ class _CheckBoxComponent extends react.Component { getInitialState() => {'checked': false}; _handleChange(e) { - this.setState({'checked': e.target.checked}); + setState({'checked': e.target.checked}); } @override @@ -76,7 +76,7 @@ class _CheckBoxComponent extends react.Component { react.label({ 'htmlFor': 'doTheDishes', 'key': 'label', - 'className': 'form-check-label ' + (this.state['checked'] ? 'striked' : 'not-striked') + 'className': 'form-check-label ' + (state['checked'] ? 'striked' : 'not-striked') }, 'do the dishes'), ]); } @@ -95,7 +95,7 @@ class _ClockComponent extends react.Component { @override void componentWillMount() { - timer = Timer.periodic(Duration(milliseconds: this.props['refreshRate']), this.tick); + timer = Timer.periodic(Duration(milliseconds: props['refreshRate']), tick); } @override @@ -206,7 +206,7 @@ class _LegacyContextComponent extends react.Component { Map getChildContext() => { 'foo': {'object': 'with value'}, 'bar': true, - 'renderCount': this.state['renderCount'] + 'renderCount': state['renderCount'] }; @override @@ -225,7 +225,7 @@ class _LegacyContextComponent extends react.Component { } _onButtonClick(event) { - this.setState({'renderCount': (this.state['renderCount'] ?? 0) + 1}); + setState({'renderCount': (state['renderCount'] ?? 0) + 1}); } } @@ -307,7 +307,7 @@ class _NewContextProviderComponent extends react.Component2 { @override render() { - final provideMap = {'renderCount': this.state['renderCount']}; + final provideMap = {'renderCount': state['renderCount']}; final complexValues = { 'callback': printMe, @@ -358,11 +358,11 @@ class _NewContextProviderComponent extends react.Component2 { } _onComplexClick(event) { - this.setState({'complexMap': true, 'renderCount': this.state['renderCount'] + 1}); + setState({'complexMap': true, 'renderCount': state['renderCount'] + 1}); } _onButtonClick(event) { - this.setState({'renderCount': this.state['renderCount'] + 1, 'complexMap': false}); + setState({'renderCount': state['renderCount'] + 1, 'complexMap': false}); } } @@ -411,11 +411,11 @@ class _NewContextTypeConsumerComponent extends react.Component2 { @override render() { - this.context['componentRef']?.test(); + context['componentRef']?.test(); return react.ul({ 'key': 'ul3' }, [ - 'Using Component.contextType: this.context = ${this.context}', + 'Using Component.contextType: this.context = ${context}', ]); } } diff --git a/lib/react.dart b/lib/react.dart index 53952100..43ef9748 100644 --- a/lib/react.dart +++ b/lib/react.dart @@ -231,16 +231,16 @@ abstract class Component { /// [nextContext]s typing was loosened from Map to dynamic to support the new context API in [Component2] /// which extends from [Component]. Only "legacy" context APIs are supported in [Component] - which means /// it will still be expected to be a Map. - this.nextContext = Map.from(this.context ?? const {}); + nextContext = Map.from(this.context ?? const {}); } _initProps(props) { this.props = Map.from(props); - this.nextProps = this.props; + nextProps = this.props; } initStateInternal() { - this.state = Map.from(getInitialState()); + state = Map.from(getInitialState()); // Call `transferComponentState` to get state also to `_prevState` transferComponentState(); diff --git a/lib/react_client/component_factory.dart b/lib/react_client/component_factory.dart index 127afda1..3e7d78cf 100644 --- a/lib/react_client/component_factory.dart +++ b/lib/react_client/component_factory.dart @@ -89,8 +89,8 @@ class ReactDartComponentFactoryProxy extends React final Map defaultProps; ReactDartComponentFactoryProxy(ReactClass reactClass) - : this.reactClass = reactClass, - this.defaultProps = reactClass.dartDefaultProps; + : reactClass = reactClass, + defaultProps = reactClass.dartDefaultProps; @override ReactClass get type => reactClass; @@ -183,8 +183,8 @@ class ReactDartComponentFactoryProxy2 extends Rea final Map defaultProps; ReactDartComponentFactoryProxy2(ReactClass reactClass) - : this.reactClass = reactClass, - this.defaultProps = JsBackedMap.fromJs(reactClass.defaultProps); + : reactClass = reactClass, + defaultProps = JsBackedMap.fromJs(reactClass.defaultProps); @override ReactClass get type => reactClass; @@ -211,7 +211,7 @@ class ReactJsContextComponentFactoryProxy extends ReactJsComponentFactoryProxy { this.shouldConvertDomProps = true, this.isConsumer = false, this.isProvider = false, - }) : this.type = jsClass, + }) : type = jsClass, super(jsClass, shouldConvertDomProps: shouldConvertDomProps); @override @@ -268,8 +268,8 @@ class ReactJsComponentFactoryProxy extends ReactComponentFactoryProxy { this.shouldConvertDomProps = true, this.alwaysReturnChildrenAsList = false, List additionalRefPropKeys = const [], - }) : this.type = jsClass, - this._additionalRefPropKeys = additionalRefPropKeys { + }) : type = jsClass, + _additionalRefPropKeys = additionalRefPropKeys { if (jsClass == null) { throw ArgumentError('`jsClass` must not be null. ' 'Ensure that the JS component class you\'re referencing is available and being accessed correctly.'); @@ -324,8 +324,8 @@ class ReactDartFunctionComponentFactoryProxy extends ReactComponentFactoryProxy final JsFunctionComponent reactFunction; ReactDartFunctionComponentFactoryProxy(DartFunctionComponent dartFunctionComponent, {String displayName}) - : this.displayName = displayName ?? _getJsFunctionName(dartFunctionComponent), - this.reactFunction = _wrapFunctionComponent(dartFunctionComponent, + : displayName = displayName ?? _getJsFunctionName(dartFunctionComponent), + reactFunction = _wrapFunctionComponent(dartFunctionComponent, displayName: displayName ?? _getJsFunctionName(dartFunctionComponent)); @override @@ -342,7 +342,7 @@ class ReactDartWrappedComponentFactoryProxy extends ReactComponentFactoryProxy w ReactDartWrappedComponentFactoryProxy.forwardRef(DartForwardRefFunctionComponent dartFunctionComponent, {String displayName}) - : this.type = _wrapForwardRefFunctionComponent(dartFunctionComponent, + : type = _wrapForwardRefFunctionComponent(dartFunctionComponent, displayName: displayName ?? _getJsFunctionName(dartFunctionComponent)); } diff --git a/test/hooks_test.dart b/test/hooks_test.dart index 53d8bf2e..b1d23b14 100644 --- a/test/hooks_test.dart +++ b/test/hooks_test.dart @@ -856,7 +856,7 @@ class _ContextProviderWrapper extends react.Component2 { } increment() { - this.setState({'counter': state['counter'] + 1}); + setState({'counter': state['counter'] + 1}); } @override diff --git a/test/lifecycle_test/component2.dart b/test/lifecycle_test/component2.dart index 5500e8a9..1bca228b 100644 --- a/test/lifecycle_test/component2.dart +++ b/test/lifecycle_test/component2.dart @@ -52,7 +52,7 @@ class _SetStateTest extends react.Component2 with LifecycleTestHelper { @override componentDidCatch(dynamic error, ReactErrorInfo info) { lifecycleCall('componentDidCatch', arguments: [error, info]); - this.setState({'error': error, 'info': info.componentStack}); + setState({'error': error, 'info': info.componentStack}); } @override diff --git a/test/react_context_test.dart b/test/react_context_test.dart index 11b2a0d3..8f94dc61 100644 --- a/test/react_context_test.dart +++ b/test/react_context_test.dart @@ -125,7 +125,7 @@ class _ContextProviderWrapper extends react.Component2 { } increment() { - this.setState({'counter': state['counter'] + 1}); + setState({'counter': state['counter'] + 1}); } @override @@ -158,6 +158,6 @@ class _ContextTypeComponent extends react.Component2 { @override render() { - return react.div({}, '${this.context}'); + return react.div({}, '${context}'); } } diff --git a/test/react_memo_test.dart b/test/react_memo_test.dart index 0fe63396..a461fb85 100644 --- a/test/react_memo_test.dart +++ b/test/react_memo_test.dart @@ -187,15 +187,15 @@ class _MemoTestWrapperComponent extends react.Component2 { } void increaseLocalCount() { - this.setState({'localCount': this.state['localCount'] + 1}); + setState({'localCount': state['localCount'] + 1}); } void increaseValueMemoShouldIgnoreViaAreEqual() { - this.setState({'valueMemoShouldIgnoreViaAreEqual': this.state['valueMemoShouldIgnoreViaAreEqual'] + 1}); + setState({'valueMemoShouldIgnoreViaAreEqual': state['valueMemoShouldIgnoreViaAreEqual'] + 1}); } void increaseValueMemoShouldNotKnowAbout() { - this.setState({'valueMemoShouldNotKnowAbout': this.state['valueMemoShouldNotKnowAbout'] + 1}); + setState({'valueMemoShouldNotKnowAbout': state['valueMemoShouldNotKnowAbout'] + 1}); } @override @@ -203,8 +203,8 @@ class _MemoTestWrapperComponent extends react.Component2 { return react.div( {}, props['memoComponentFactory']({ - 'localCount': this.state['localCount'], - 'valueMemoShouldIgnoreViaAreEqual': this.state['valueMemoShouldIgnoreViaAreEqual'], + 'localCount': state['localCount'], + 'valueMemoShouldIgnoreViaAreEqual': state['valueMemoShouldIgnoreViaAreEqual'], }), ); } From 1b5f9725f3016229f1433bdc78a2b92763117557 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 15:50:34 -0700 Subject: [PATCH 13/31] dart fix --apply --code=unnecessary_brace_in_string_interps --- example/test/function_component_test.dart | 4 ++-- example/test/get_dom_node_test.dart | 2 +- example/test/react_test_components.dart | 8 ++++---- example/test/ref_test.dart | 2 +- test/hooks_test.dart | 2 +- test/react_context_test.dart | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/example/test/function_component_test.dart b/example/test/function_component_test.dart index e0ba2348..74694412 100644 --- a/example/test/function_component_test.dart +++ b/example/test/function_component_test.dart @@ -210,7 +210,7 @@ class _NewContextProviderComponent extends react.Component2 { 'onClick': _onButtonClick, }, 'Redraw'), react.br({'key': 'break1'}), - 'TestContext.Provider props.value: ${provideMap}', + 'TestContext.Provider props.value: $provideMap', react.br({'key': 'break2'}), react.br({'key': 'break3'}), TestNewContext.Provider( @@ -285,7 +285,7 @@ UseMemoTestComponent2(Map props) { final fib = fibonacci(count.value); return react.Fragment({}, [ - react.div({'key': 'div'}, ['Fibonacci of ${count.value} is ${fib}']), + react.div({'key': 'div'}, ['Fibonacci of ${count.value} is $fib']), react.button({'key': 'button1', 'onClick': (_) => count.setWithUpdater((prev) => prev + 1)}, ['+']), react.button({'key': 'button2', 'onClick': (_) => reRender.setWithUpdater((prev) => prev + 1)}, ['re-render']), ]); diff --git a/example/test/get_dom_node_test.dart b/example/test/get_dom_node_test.dart index 3d8d26a6..55e72ec1 100644 --- a/example/test/get_dom_node_test.dart +++ b/example/test/get_dom_node_test.dart @@ -6,7 +6,7 @@ import 'package:react/react_dom.dart' as react_dom; customAssert(text, condition) { if (condition) - print('${text} passed'); + print('$text passed'); else throw (text); } diff --git a/example/test/react_test_components.dart b/example/test/react_test_components.dart index 4470c007..42219e42 100644 --- a/example/test/react_test_components.dart +++ b/example/test/react_test_components.dart @@ -347,7 +347,7 @@ class _NewContextProviderComponent extends react.Component2 { 'onClick': _onComplexClick, }, 'Redraw With Complex Value'), react.br({'key': 'break1'}), - 'TestContext.Provider props.value: ${provideMap}', + 'TestContext.Provider props.value: $provideMap', react.br({'key': 'break2'}), react.br({'key': 'break3'}), TestNewContext.Provider( @@ -375,7 +375,7 @@ class _NewContextConsumerComponent extends react.Component2 { return react.ul({ 'key': 'ul1' }, [ - 'TestContext.Consumer: value = ${value}', + 'TestContext.Consumer: value = $value', react.br({'key': 'break12'}), react.br({'key': 'break22'}), props['children'], @@ -393,7 +393,7 @@ class _NewContextConsumerObservedBitsComponent extends react.Component2 { return react.ul({ 'key': 'ul2' }, [ - 'TestContext.Consumer (with unstable_observedBits set to trigger when `renderCount % 2 == 0`): value = ${value}', + 'TestContext.Consumer (with unstable_observedBits set to trigger when `renderCount % 2 == 0`): value = $value', react.br({'key': 'break13'}), react.br({'key': 'break23'}), props['children'], @@ -415,7 +415,7 @@ class _NewContextTypeConsumerComponent extends react.Component2 { return react.ul({ 'key': 'ul3' }, [ - 'Using Component.contextType: this.context = ${context}', + 'Using Component.contextType: this.context = $context', ]); } } diff --git a/example/test/ref_test.dart b/example/test/ref_test.dart index 3a9fe63e..cb2c4f6c 100644 --- a/example/test/ref_test.dart +++ b/example/test/ref_test.dart @@ -15,7 +15,7 @@ class _ChildComponent extends react.Component { } @override - render() => react.span({}, 'Child element with value ${somevalue}'); + render() => react.span({}, 'Child element with value $somevalue'); } var InputComponentForm = react.forwardRef2((props, ref) { diff --git a/test/hooks_test.dart b/test/hooks_test.dart index b1d23b14..6430e33d 100644 --- a/test/hooks_test.dart +++ b/test/hooks_test.dart @@ -389,7 +389,7 @@ main() { return react.div({ 'key': 'uct1' }, [ - react.div({'key': 'uct2'}, ['useContext counter value is ${context}']), + react.div({'key': 'uct2'}, ['useContext counter value is $context']), ]); } diff --git a/test/react_context_test.dart b/test/react_context_test.dart index 8f94dc61..31cbeb91 100644 --- a/test/react_context_test.dart +++ b/test/react_context_test.dart @@ -158,6 +158,6 @@ class _ContextTypeComponent extends react.Component2 { @override render() { - return react.div({}, '${context}'); + return react.div({}, '$context'); } } From 2948941a235dfb5bfa70be4f41d1f76b1987e357 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 15:51:11 -0700 Subject: [PATCH 14/31] dart fix --apply --code=unnecessary_parenthesis --- example/test/context_test.dart | 2 +- example/test/get_dom_node_test.dart | 2 +- example/test/react_test_components.dart | 4 ++-- test/lifecycle_test.dart | 6 +++--- test/shared_type_tester.dart | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/example/test/context_test.dart b/example/test/context_test.dart index 61970e52..503ab13e 100644 --- a/example/test/context_test.dart +++ b/example/test/context_test.dart @@ -25,7 +25,7 @@ void main() { }), newContextConsumerObservedBitsComponent({ 'key': 'newConsumerObservedBitsComponent', - 'unstable_observedBits': (1 << 2), + 'unstable_observedBits': 1 << 2, }), newContextTypeConsumerComponentComponent({'key': 'newContextTypeConsumerComponent'}, []), ]), diff --git a/example/test/get_dom_node_test.dart b/example/test/get_dom_node_test.dart index 55e72ec1..5dca8d86 100644 --- a/example/test/get_dom_node_test.dart +++ b/example/test/get_dom_node_test.dart @@ -8,7 +8,7 @@ customAssert(text, condition) { if (condition) print('$text passed'); else - throw (text); + throw text; } var ChildComponent = react.registerComponent(() => _ChildComponent()); diff --git a/example/test/react_test_components.dart b/example/test/react_test_components.dart index 42219e42..e8772291 100644 --- a/example/test/react_test_components.dart +++ b/example/test/react_test_components.dart @@ -431,9 +431,9 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot Map getDerivedStateFromProps(nextProps, prevState) { final prevItems = prevState['items']; if (prevItems.isEmpty || prevItems[0] != 3) { - return ({ + return { 'items': List.from([3, 1, 2, 0]) - }); + }; } return null; } diff --git a/test/lifecycle_test.dart b/test/lifecycle_test.dart index 69d96654..f41d38f2 100644 --- a/test/lifecycle_test.dart +++ b/test/lifecycle_test.dart @@ -737,7 +737,7 @@ void sharedLifecycleTests({ const Map expectedContext = {'foo': true}; Map refMap = { - 'ref': ((ref) => component = ref), + 'ref': (ref) => component = ref, }; // Add the 'ref' prop separately so it isn't an expected prop since React removes it internally @@ -808,7 +808,7 @@ void sharedLifecycleTests({ const Map expectedContext = {'foo': true}; Map refMap = { - 'ref': ((ref) => component = ref), + 'ref': (ref) => component = ref, }; final initialProps = Map.from(defaultProps)..addAll({'children': const []}); @@ -872,7 +872,7 @@ void sharedLifecycleTests({ Map expectedContext = {'foo': true}; Map refMap = { - 'ref': ((ref) => component = ref), + 'ref': (ref) => component = ref, }; final initialProps = Map.from(defaultProps) diff --git a/test/shared_type_tester.dart b/test/shared_type_tester.dart index fe69e0eb..4f996acf 100644 --- a/test/shared_type_tester.dart +++ b/test/shared_type_tester.dart @@ -51,9 +51,9 @@ void sharedTypeTests( }); if (!skipNumTypes) { test('num types', () { - final intValue = (1 as int); // ignore: unnecessary_cast + final intValue = 1 as int; // ignore: unnecessary_cast final doubleValue = 1.1; - final numValue = (1 as num); // ignore: unnecessary_cast + final numValue = 1 as num; // ignore: unnecessary_cast testTypeValue(intValue); testTypeValue(doubleValue); From 911c9142570dc09386657a3b3610c76c3a3076ed Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 15:54:25 -0700 Subject: [PATCH 15/31] Disable some more lints --- analysis_options.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/analysis_options.yaml b/analysis_options.yaml index b53d84ad..c8879839 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -9,6 +9,11 @@ analyzer: comment_references: info # This is too noisy since it warns for all lifecycle methods. always_declare_return_types: ignore + # We very often need to annotate parameters when they're embedded in Maps + # with dynamic values, so this lint is noisy and wrong in those cases. + avoid_types_on_closure_parameters: ignore + # This makes string concatenation less readable in some cases + prefer_interpolation_to_compose_strings: ignore # The following are ignored to avoid merge conflicts with null safety branch directives_ordering: ignore prefer_typing_uninitialized_variables: ignore From 70429ac5bc12d2db077029f0d3c11a46e305b0ea Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Fri, 11 Aug 2023 10:08:04 -0700 Subject: [PATCH 16/31] Remove some unnecessary function parameter types, link to linter issue --- analysis_options.yaml | 1 + example/test/function_component_test.dart | 2 +- test/hooks_test.dart | 18 +++++++++--------- test/react_memo_test.dart | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index c8879839..ed7c50a6 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -11,6 +11,7 @@ analyzer: always_declare_return_types: ignore # We very often need to annotate parameters when they're embedded in Maps # with dynamic values, so this lint is noisy and wrong in those cases. + # See: https://github.com/dart-lang/linter/issues/1099 avoid_types_on_closure_parameters: ignore # This makes string concatenation less readable in some cases prefer_interpolation_to_compose_strings: ignore diff --git a/example/test/function_component_test.dart b/example/test/function_component_test.dart index 74694412..5a57d551 100644 --- a/example/test/function_component_test.dart +++ b/example/test/function_component_test.dart @@ -68,7 +68,7 @@ class _MemoTestDemoWrapper extends react.Component2 { } } -final MemoTest = react.memo2(react.registerFunctionComponent((Map props) { +final MemoTest = react.memo2(react.registerFunctionComponent((props) { final context = useContext(TestNewContext); return react.div( {}, diff --git a/test/hooks_test.dart b/test/hooks_test.dart index 6430e33d..5061573b 100644 --- a/test/hooks_test.dart +++ b/test/hooks_test.dart @@ -27,7 +27,7 @@ main() { setUpAll(() { final mountNode = DivElement(); - UseStateTest = react.registerFunctionComponent((Map props) { + UseStateTest = react.registerFunctionComponent((props) { final text = useStateLazy(() { return 'initialValue'; }); @@ -117,7 +117,7 @@ main() { setUpAll(() { final mountNode = DivElement(); - UseReducerTest = react.registerFunctionComponent((Map props) { + UseReducerTest = react.registerFunctionComponent((props) { final state = useReducer(reducer, { 'text': 'initialValue', 'count': 0, @@ -211,7 +211,7 @@ main() { setUpAll(() { final mountNode = DivElement(); - UseReducerTest = react.registerFunctionComponent((Map props) { + UseReducerTest = react.registerFunctionComponent((props) { final state = useReducerLazy(reducer2, props['initialCount'] as int, initializeCount); return react.div({}, [ @@ -284,7 +284,7 @@ main() { setUpAll(() { final mountNode = DivElement(); - UseCallbackTest = react.registerFunctionComponent((Map props) { + UseCallbackTest = react.registerFunctionComponent((props) { final count = useState(0); final delta = useState(1); @@ -447,7 +447,7 @@ main() { var refFromCreateRef; setUpAll(() { - UseRefTest = react.registerFunctionComponent((Map props) { + UseRefTest = react.registerFunctionComponent((props) { noInitRef = useRef(); initRef = useRef(mountNode); domElementRef = useRef(); @@ -540,7 +540,7 @@ main() { setUpAll(() { final mountNode = DivElement(); - UseMemoTest = react.registerFunctionComponent((Map props) { + UseMemoTest = react.registerFunctionComponent((props) { final reRender = useState(0); count = useState(5); @@ -800,7 +800,7 @@ main() { setUpAll(() { final mountNode = DivElement(); - UseDebugValueTest1 = react.registerFunctionComponent((Map props) { + UseDebugValueTest1 = react.registerFunctionComponent((props) { isOnline1 = useFriendStatus(); return react.li({ @@ -810,7 +810,7 @@ main() { ]); }); - UseDebugValueTest2 = react.registerFunctionComponent((Map props) { + UseDebugValueTest2 = react.registerFunctionComponent((props) { isOnline2 = useFriendStatusWithFormatFunction(); return react.li({ @@ -893,7 +893,7 @@ void testEffectHook(Function effectHook) { useEffectWithEmptyDepsCallCount = 0; useEffectCleanupWithEmptyDepsCallCount = 0; - UseEffectTest = react.registerFunctionComponent((Map props) { + UseEffectTest = react.registerFunctionComponent((props) { final count = useState(0); final countDown = useState(0); diff --git a/test/react_memo_test.dart b/test/react_memo_test.dart index a461fb85..aa874a48 100644 --- a/test/react_memo_test.dart +++ b/test/react_memo_test.dart @@ -80,7 +80,7 @@ void sharedMemoTests(MemoFunction memoFunction) { return prevProps['localCount'] == nextProps['localCount']; }; - final MemoTest = memoFunction(react.registerFunctionComponent((Map props) { + final MemoTest = memoFunction(react.registerFunctionComponent((props) { childMemoRenderCount++; return react.div( {}, From ae1914ed5da2ceb557130863ed94d8a21f67599c Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 15:58:59 -0700 Subject: [PATCH 17/31] Ignore lints that could change behavior or break public API if fixed --- lib/react.dart | 6 ++++++ lib/react_client/bridge.dart | 1 + lib/react_client/component_factory.dart | 1 + lib/src/react_client/factory_util.dart | 1 + test/js_builds/shared_tests.dart | 1 + test/react_client/event_helpers_test.dart | 3 +++ test/shared_type_tester.dart | 1 + 7 files changed, 14 insertions(+) diff --git a/lib/react.dart b/lib/react.dart index 43ef9748..ab2a2a6c 100644 --- a/lib/react.dart +++ b/lib/react.dart @@ -160,12 +160,14 @@ abstract class Component { /// ReactJS [Component] props. /// /// Related: [state] + // ignore: unnecessary_getters_setters Map get props => _props; set props(Map value) => _props = value; /// ReactJS [Component] state. /// /// Related: [props] + // ignore: unnecessary_getters_setters Map get state => _state; set state(Map value) => _state = value; @@ -195,8 +197,10 @@ abstract class Component { dynamic _jsThis; + // ignore: prefer_final_fields List _setStateCallbacks = []; + // ignore: prefer_final_fields List _transactionalSetStateCallbacks = []; /// The List of callbacks to be called after the component has been updated from a call to [setState]. @@ -421,6 +425,7 @@ abstract class Component { /// > /// > This will be completely removed when the JS side of it is slated for removal (ReactJS 18 / react.dart 7.0.0) @Deprecated('7.0.0') + // ignore: avoid_returning_null bool shouldComponentUpdateWithContext(Map nextProps, Map nextState, Map nextContext) => null; /// ReactJS lifecycle method that is invoked immediately before rendering when [nextProps] or [nextState] are being @@ -916,6 +921,7 @@ abstract class Component2 implements Component { /// ``` /// /// See: + // ignore: prefer_void_to_null Map> get propTypes => {}; /// Examines [props] and [state] and returns one of the following types: diff --git a/lib/react_client/bridge.dart b/lib/react_client/bridge.dart index 63fbaff8..6b51a29e 100644 --- a/lib/react_client/bridge.dart +++ b/lib/react_client/bridge.dart @@ -63,6 +63,7 @@ class Component2BridgeImpl extends Component2Bridge { /// Returns a const bridge instance suitable for use with any component. /// /// See [Component2BridgeFactory] for more info. + // ignore: prefer_constructors_over_static_methods static Component2BridgeImpl bridgeFactory(Component2 _) => const Component2BridgeImpl(); @override diff --git a/lib/react_client/component_factory.dart b/lib/react_client/component_factory.dart index 3e7d78cf..37bbcc9c 100644 --- a/lib/react_client/component_factory.dart +++ b/lib/react_client/component_factory.dart @@ -144,6 +144,7 @@ class ReactDartComponentFactoryProxy extends React // Use CallbackRef to check arity, since parameters could be non-dynamic, and thus // would fail the `is CallbackRef` check. // See https://github.com/dart-lang/sdk/issues/34593 for more information on arity checks. + // ignore: prefer_void_to_null if (ref is CallbackRef) { interopProps.ref = allowInterop((dynamic instance) { // Call as dynamic to perform dynamic dispatch, since we can't cast to CallbackRef, diff --git a/lib/src/react_client/factory_util.dart b/lib/src/react_client/factory_util.dart index 4ec5115e..2dec8e99 100644 --- a/lib/src/react_client/factory_util.dart +++ b/lib/src/react_client/factory_util.dart @@ -57,6 +57,7 @@ void convertRefValue2( // Use _CallbackRef to check arity, since parameters could be non-dynamic, and thus // would fail the `is _CallbackRef` check. // See https://github.com/dart-lang/sdk/issues/34593 for more information on arity checks. + // ignore: prefer_void_to_null } else if (ref is CallbackRef && convertCallbackRefValue) { args[refKey] = allowInterop((dynamic instance) { // Call as dynamic to perform dynamic dispatch, since we can't cast to _CallbackRef, diff --git a/test/js_builds/shared_tests.dart b/test/js_builds/shared_tests.dart index 54c3f567..c92ea006 100644 --- a/test/js_builds/shared_tests.dart +++ b/test/js_builds/shared_tests.dart @@ -92,6 +92,7 @@ void sharedConsoleWarnTests({@required bool expectDeduplicateSyntheticEventWarni } // Adapted from reduced test case in https://github.com/dart-lang/sdk/issues/43939 + // ignore: prefer_function_declarations_over_variables dynamic function = (react.SyntheticEvent event) {}; // ignore: unused_local_variable dynamic Function(T) function2 = function; diff --git a/test/react_client/event_helpers_test.dart b/test/react_client/event_helpers_test.dart index 742e209c..883a5ae4 100644 --- a/test/react_client/event_helpers_test.dart +++ b/test/react_client/event_helpers_test.dart @@ -133,6 +133,7 @@ main() { expect(syntheticKeyboardEvent.cancelable, isTrue); expect(syntheticKeyboardEvent.currentTarget, currentTarget); expect(syntheticKeyboardEvent.defaultPrevented, isFalse); + // ignore: unnecessary_lambdas expect(() => syntheticKeyboardEvent.preventDefault(), returnsNormally); expect(calls, contains('preventDefault')); expect(() => syntheticKeyboardEvent.stopPropagation(), returnsNormally); @@ -191,6 +192,7 @@ main() { expect(syntheticMouseEvent.cancelable, isTrue); expect(syntheticMouseEvent.currentTarget, currentTarget); expect(syntheticMouseEvent.defaultPrevented, isFalse); + // ignore: unnecessary_lambdas expect(() => syntheticMouseEvent.preventDefault(), returnsNormally); expect(calls, contains('preventDefault')); expect(() => syntheticMouseEvent.stopPropagation(), returnsNormally); @@ -227,6 +229,7 @@ main() { expect(fakeEvent.cancelable, isFalse); expect(fakeEvent.currentTarget, element); expect(fakeEvent.defaultPrevented, false); + // ignore: unnecessary_lambdas expect(() => fakeEvent.preventDefault(), returnsNormally); expect(() => fakeEvent.stopPropagation(), returnsNormally); expect(fakeEvent.eventPhase, Event.AT_TARGET); diff --git a/test/shared_type_tester.dart b/test/shared_type_tester.dart index 4f996acf..dc80f4d8 100644 --- a/test/shared_type_tester.dart +++ b/test/shared_type_tester.dart @@ -67,6 +67,7 @@ void sharedTypeTests( test('functions', () { _functionLocalMethod() {} final functionLocalMethod = _functionLocalMethod; + // ignore: prefer_function_declarations_over_variables final functionExpression = () {}; final functionTearOff = Object().toString; final functionAllowInterop = allowInterop(() {}); From 8b83f8928e1615a400b209ba108f89400497111d Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 16:01:59 -0700 Subject: [PATCH 18/31] dart fix --apply --code=unused_import --- lib/src/js_interop_util.dart | 1 - lib/src/react_client/component_registration.dart | 1 - lib/src/react_client/dart_interop_statics.dart | 1 - test/react_suspense_lazy_component.dart | 1 - 4 files changed, 4 deletions(-) diff --git a/lib/src/js_interop_util.dart b/lib/src/js_interop_util.dart index 6149b83c..281ca659 100644 --- a/lib/src/js_interop_util.dart +++ b/lib/src/js_interop_util.dart @@ -4,7 +4,6 @@ library js_interop_util; import 'dart:js_util'; import 'package:js/js.dart'; -import 'package:react/react_client/js_backed_map.dart' show JsMap; @JS('Object.keys') external List objectKeys(Object object); diff --git a/lib/src/react_client/component_registration.dart b/lib/src/react_client/component_registration.dart index 9d75c51b..405615ab 100644 --- a/lib/src/react_client/component_registration.dart +++ b/lib/src/react_client/component_registration.dart @@ -1,6 +1,5 @@ import 'dart:html'; -import 'package:js/js_util.dart'; import 'package:react/react.dart'; import 'package:react/react_client/bridge.dart'; import 'package:react/react_client/js_backed_map.dart'; diff --git a/lib/src/react_client/dart_interop_statics.dart b/lib/src/react_client/dart_interop_statics.dart index 1a763a95..78048107 100644 --- a/lib/src/react_client/dart_interop_statics.dart +++ b/lib/src/react_client/dart_interop_statics.dart @@ -14,7 +14,6 @@ import 'package:react/react_client/zone.dart'; import 'package:react/src/context.dart'; import 'package:react/src/react_client/private_utils.dart'; -import 'package:react/src/typedefs.dart'; /// The static methods that proxy JS component lifecycle methods to Dart components. @Deprecated('7.0.0') diff --git a/test/react_suspense_lazy_component.dart b/test/react_suspense_lazy_component.dart index ceca28e1..c023532c 100644 --- a/test/react_suspense_lazy_component.dart +++ b/test/react_suspense_lazy_component.dart @@ -1,4 +1,3 @@ -import 'package:react/hooks.dart'; import 'package:react/react.dart' as react; var SimpleFunctionComponent = react.registerFunctionComponent(SimpleComponent, displayName: 'simple'); From ae87897a7f54fa42a9bad021f9a8e75ab3e34d32 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 16:03:37 -0700 Subject: [PATCH 19/31] dart fix --apply --code=unnecessary_import --- lib/react.dart | 1 - lib/react_client/bridge.dart | 1 - lib/react_client/component_factory.dart | 1 - lib/react_client/react_interop.dart | 1 - lib/src/react_client/dart_interop_statics.dart | 1 - lib/src/react_client/factory_util.dart | 1 - test/factory/common_factory_tests.dart | 1 - test/react_client/event_helpers_test.dart | 1 - test/react_client_test.dart | 1 - 9 files changed, 9 deletions(-) diff --git a/lib/react.dart b/lib/react.dart index ab2a2a6c..0417eba3 100644 --- a/lib/react.dart +++ b/lib/react.dart @@ -14,7 +14,6 @@ import 'package:react/src/prop_validator.dart'; import 'package:react/src/typedefs.dart'; import 'package:react/react_client.dart'; import 'package:react/react_client/react_interop.dart'; -import 'package:react/react_client/component_factory.dart'; import 'package:react/src/context.dart'; import 'package:react/src/react_client/component_registration.dart' as registration_utils; import 'package:react/src/react_client/private_utils.dart' show validateJsApiThenReturn; diff --git a/lib/react_client/bridge.dart b/lib/react_client/bridge.dart index 6b51a29e..94c2db56 100644 --- a/lib/react_client/bridge.dart +++ b/lib/react_client/bridge.dart @@ -3,7 +3,6 @@ import 'package:meta/meta.dart'; import 'package:react/react.dart'; import 'package:react/react_client/js_backed_map.dart'; import 'package:react/react_client/react_interop.dart'; -import 'package:react/src/prop_validator.dart'; import 'package:react/src/typedefs.dart'; /// A function that returns a bridge instance for use with a given [component]. diff --git a/lib/react_client/component_factory.dart b/lib/react_client/component_factory.dart index 37bbcc9c..d4c88cc7 100644 --- a/lib/react_client/component_factory.dart +++ b/lib/react_client/component_factory.dart @@ -10,7 +10,6 @@ import 'package:react/react_client.dart'; import 'package:react/react_client/js_backed_map.dart'; import 'package:react/react_client/react_interop.dart'; -import 'package:react/src/context.dart'; import 'package:react/src/ddc_emulated_function_name_bug.dart' as ddc_emulated_function_name_bug; import 'package:react/src/js_interop_util.dart'; import 'package:react/src/typedefs.dart'; diff --git a/lib/react_client/react_interop.dart b/lib/react_client/react_interop.dart index a035e12d..ecc4d877 100644 --- a/lib/react_client/react_interop.dart +++ b/lib/react_client/react_interop.dart @@ -15,7 +15,6 @@ import 'package:js/js_util.dart'; import 'package:meta/meta.dart'; import 'package:react/hooks.dart'; import 'package:react/react.dart'; -import 'package:react/react_client.dart' show ComponentFactory; import 'package:react/react_client/bridge.dart'; import 'package:react/react_client/js_backed_map.dart'; import 'package:react/react_client/component_factory.dart' diff --git a/lib/src/react_client/dart_interop_statics.dart b/lib/src/react_client/dart_interop_statics.dart index 78048107..2ccb788b 100644 --- a/lib/src/react_client/dart_interop_statics.dart +++ b/lib/src/react_client/dart_interop_statics.dart @@ -12,7 +12,6 @@ import 'package:react/react_client/js_interop_helpers.dart'; import 'package:react/react_client/react_interop.dart'; import 'package:react/react_client/zone.dart'; -import 'package:react/src/context.dart'; import 'package:react/src/react_client/private_utils.dart'; /// The static methods that proxy JS component lifecycle methods to Dart components. diff --git a/lib/src/react_client/factory_util.dart b/lib/src/react_client/factory_util.dart index 2dec8e99..fd1205b5 100644 --- a/lib/src/react_client/factory_util.dart +++ b/lib/src/react_client/factory_util.dart @@ -1,7 +1,6 @@ @JS() library react_client_factory_utils; -import 'dart:js'; import 'package:js/js.dart'; diff --git a/test/factory/common_factory_tests.dart b/test/factory/common_factory_tests.dart index ee51df05..cfa319e3 100644 --- a/test/factory/common_factory_tests.dart +++ b/test/factory/common_factory_tests.dart @@ -9,7 +9,6 @@ import 'dart:js_util'; import 'package:js/js.dart'; import 'package:meta/meta.dart'; -import 'package:react/react_client/component_factory.dart'; import 'package:react/react_client/js_backed_map.dart'; import 'package:react/react_client/js_interop_helpers.dart'; import 'package:test/test.dart'; diff --git a/test/react_client/event_helpers_test.dart b/test/react_client/event_helpers_test.dart index 883a5ae4..0f98fc2e 100644 --- a/test/react_client/event_helpers_test.dart +++ b/test/react_client/event_helpers_test.dart @@ -7,7 +7,6 @@ import 'package:react/react.dart'; import 'package:react/react_client/js_interop_helpers.dart'; import 'package:react/react_dom.dart'; import 'package:react/react_test_utils.dart'; -import 'package:react/src/react_client/event_helpers.dart'; import 'package:test/test.dart'; import 'package:mockito/mockito.dart'; diff --git a/test/react_client_test.dart b/test/react_client_test.dart index f612f649..ef540a23 100644 --- a/test/react_client_test.dart +++ b/test/react_client_test.dart @@ -11,7 +11,6 @@ import 'package:test/test.dart'; import 'package:react/react.dart' as react; import 'package:react/react_client.dart'; -import 'package:react/react_client/component_factory.dart'; import 'package:react/react_client/react_interop.dart' show React, ReactComponent; import 'package:react/react_client/js_interop_helpers.dart'; import 'package:react/react_dom.dart' as react_dom; From 82c5d9e1ed73bcfdb0318d31595ca1c229720aaf Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 16:05:18 -0700 Subject: [PATCH 20/31] Fix miscellaneous remaining lints (dart fix --apply) --- example/test/get_dom_node_test.dart | 5 +++-- example/test/react_test_components.dart | 2 +- lib/react.dart | 2 +- lib/react_client/react_interop.dart | 4 ++-- lib/src/react_client/dart_interop_statics.dart | 16 +++++++--------- test/hooks_test.dart | 8 ++------ test/js_builds/shared_tests.dart | 4 +--- test/lifecycle_test.dart | 12 ++++++------ test/lifecycle_test/util.dart | 6 +++--- test/react_client/js_interop_helpers_test.dart | 2 +- test/shared_type_tester.dart | 12 ++++++------ test/util.dart | 6 +++--- tool/run_consumer_tests.dart | 2 +- 13 files changed, 37 insertions(+), 44 deletions(-) diff --git a/example/test/get_dom_node_test.dart b/example/test/get_dom_node_test.dart index 5dca8d86..1bafad36 100644 --- a/example/test/get_dom_node_test.dart +++ b/example/test/get_dom_node_test.dart @@ -5,10 +5,11 @@ import 'package:react/react.dart' as react; import 'package:react/react_dom.dart' as react_dom; customAssert(text, condition) { - if (condition) + if (condition) { print('$text passed'); - else + } else { throw text; + } } var ChildComponent = react.registerComponent(() => _ChildComponent()); diff --git a/example/test/react_test_components.dart b/example/test/react_test_components.dart index e8772291..b7e3fea5 100644 --- a/example/test/react_test_components.dart +++ b/example/test/react_test_components.dart @@ -451,7 +451,7 @@ class _Component2TestComponent extends react.Component2 with react.TypedSnapshot void componentDidUpdate(prevProps, prevState, [String snapshot]) { if (snapshot != null) { print('Updated DOM and ' + snapshot); - return null; + return; } print('No Snapshot'); } diff --git a/lib/react.dart b/lib/react.dart index 0417eba3..5101e15e 100644 --- a/lib/react.dart +++ b/lib/react.dart @@ -292,7 +292,7 @@ abstract class Component { /// Public getter for [_nextState]. /// /// If `null`, then [_nextState] is equal to [state] - which is the value that will be returned. - Map get nextState => _nextState == null ? state : _nextState; + Map get nextState => _nextState ?? state; /// Reference to the value of [props] for the upcoming render cycle. /// diff --git a/lib/react_client/react_interop.dart b/lib/react_client/react_interop.dart index ecc4d877..ffac42ea 100644 --- a/lib/react_client/react_interop.dart +++ b/lib/react_client/react_interop.dart @@ -719,12 +719,12 @@ external void markChildValidated(child); /// /// ___Only for use with variadic children.___ void markChildrenValidated(List children) { - children.forEach((dynamic child) { + for (final child in children) { // Use `isValidElement` since `is ReactElement` doesn't behave as expected. if (React.isValidElement(child)) { markChildValidated(child); } - }); + } } /// Returns a new JS [ReactClass] for a component that uses diff --git a/lib/src/react_client/dart_interop_statics.dart b/lib/src/react_client/dart_interop_statics.dart index 2ccb788b..0ea0cae7 100644 --- a/lib/src/react_client/dart_interop_statics.dart +++ b/lib/src/react_client/dart_interop_statics.dart @@ -27,14 +27,14 @@ final ReactDartInteropStatics dartInteropStatics = (() { jsThis.setState(newObject()); } - final getRef = (name) { + getRef(name) { final ref = getProperty(jsThis.refs, name); if (ref == null) return null; if (ref is Element) return ref; if (ref is ReactComponent) return ref.dartComponent ?? ref; return ref; - }; + } final component = componentStatics.componentFactory() ..initComponentInternal(internal.props, jsRedraw, getRef, jsThis, unjsifyContext(context)) @@ -86,19 +86,19 @@ final ReactDartInteropStatics dartInteropStatics = (() { final callbacks = component.setStateCallbacks.toList(); // Prevent concurrent modification during iteration component.setStateCallbacks.clear(); - callbacks.forEach((callback) { + for (final callback in callbacks) { callback(); - }); + } } void _callSetStateTransactionalCallbacks(Component component) { final nextState = component.nextState; final props = UnmodifiableMapView(component.props); - component.transactionalSetStateCallbacks.forEach((callback) { + for (final callback in component.transactionalSetStateCallbacks) { final stateUpdates = callback(nextState, props); if (stateUpdates != null) nextState.addAll(stateUpdates); - }); + } component.transactionalSetStateCallbacks.clear(); } @@ -125,9 +125,7 @@ final ReactDartInteropStatics dartInteropStatics = (() { var shouldUpdate = component.shouldComponentUpdateWithContext(component.nextProps, component.nextState, component.nextContext); - if (shouldUpdate == null) { - shouldUpdate = component.shouldComponentUpdate(component.nextProps, component.nextState); - } + shouldUpdate ??= component.shouldComponentUpdate(component.nextProps, component.nextState); if (shouldUpdate) { return true; diff --git a/test/hooks_test.dart b/test/hooks_test.dart index 5061573b..4674899f 100644 --- a/test/hooks_test.dart +++ b/test/hooks_test.dart @@ -456,13 +456,9 @@ main() { refFromUseRef = useRef(); refFromCreateRef = react.createRef(); - if (refFromUseRef.current == null) { - refFromUseRef.current = renderIndex.value; - } + refFromUseRef.current ??= renderIndex.value; - if (refFromCreateRef.current == null) { - refFromCreateRef.current = renderIndex.value; - } + refFromCreateRef.current ??= renderIndex.value; return react.Fragment({}, [ react.input({'ref': domElementRef}), diff --git a/test/js_builds/shared_tests.dart b/test/js_builds/shared_tests.dart index c92ea006..049e7dac 100644 --- a/test/js_builds/shared_tests.dart +++ b/test/js_builds/shared_tests.dart @@ -57,9 +57,7 @@ void sharedConsoleWarnTests({@required bool expectDeduplicateSyntheticEventWarni group('console.warn wrapper (or lack thereof)', () { void clearConsoleWarnCalls() => consoleWarnCalls = []; - setUp(() { - clearConsoleWarnCalls(); - }); + setUp(clearConsoleWarnCalls); test('warns as expected with any number of arguments', () { consoleWarn('foo'); diff --git a/test/lifecycle_test.dart b/test/lifecycle_test.dart index f41d38f2..f27050ad 100644 --- a/test/lifecycle_test.dart +++ b/test/lifecycle_test.dart @@ -47,7 +47,7 @@ main() { final renderedInstance = react_dom.render(components.SetStateTest({}), mountNode); LifecycleTestHelper component = getDartComponent(renderedInstance); - expect(() => component.setState(Map()), returnsNormally); + expect(() => component.setState({}), returnsNormally); expect( () => component.setState((_, __) { return {}; @@ -135,7 +135,7 @@ main() { String consoleErrorMessage; JsFunction originalConsoleError; DivElement mountNode; - final expectedWarningPrefix = 'Warning: Failed prop type: Invalid argument(s): intProp should be int. '; + const expectedWarningPrefix = 'Warning: Failed prop type: Invalid argument(s): intProp should be int. '; setUp(() { consoleErrorCalled = false; @@ -950,7 +950,7 @@ void sharedLifecycleTests({ const Map expectedState = {}; final dynamic expectedContext = isComponent2 ? null : const {}; - const Null expectedSnapshot = null; + const void expectedSnapshot = null; final mountNode = DivElement(); final instance = react_dom.render(LifecycleTest(initialProps), mountNode); @@ -1034,7 +1034,7 @@ void sharedLifecycleTests({ Map initialProps; Map expectedProps; dynamic newContext; - Null expectedSnapshot; + void expectedSnapshot; bool updatingStateWithNull; LifecycleTestHelper component; @@ -1162,7 +1162,7 @@ void sharedLifecycleTests({ final expectedProps = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); - final Null expectedSnapshot = null; + const void expectedSnapshot = null; LifecycleTestHelper component = getDartComponent(render(LifecycleTest(initialProps))); @@ -1458,7 +1458,7 @@ void sharedLifecycleTests({ final initialPropsWithDefaults = unmodifiableMap(defaultProps, initialProps, emptyChildrenProps); final newPropsWithDefaults = unmodifiableMap(defaultProps, newProps, emptyChildrenProps); - final Map expectedContext = const {}; + const Map expectedContext = {}; final mountNode = DivElement(); final instance = react_dom.render(LifecycleTest(initialProps), mountNode); diff --git a/test/lifecycle_test/util.dart b/test/lifecycle_test/util.dart index 20eef874..965af21e 100644 --- a/test/lifecycle_test/util.dart +++ b/test/lifecycle_test/util.dart @@ -48,9 +48,9 @@ mixin LifecycleTestHelper on Component { if (lifecycleCallback != null) { return Function.apply( lifecycleCallback, - [] - ..add(this) - ..addAll(arguments)); + [this, ...arguments] + + ); } if (defaultReturnValue != null) { diff --git a/test/react_client/js_interop_helpers_test.dart b/test/react_client/js_interop_helpers_test.dart index ec9f1718..081483fc 100644 --- a/test/react_client/js_interop_helpers_test.dart +++ b/test/react_client/js_interop_helpers_test.dart @@ -67,7 +67,7 @@ main() { }); test('converts an Iterable', () { - final set = Set.from([1, 2, 3, 4, 5, 6, 7, 8]); + final set = {1, 2, 3, 4, 5, 6, 7, 8}; final array = jsifyAndAllowInterop(set); expect(array is List, isTrue); expect(array.length, equals(set.length)); diff --git a/test/shared_type_tester.dart b/test/shared_type_tester.dart index dc80f4d8..2773bea8 100644 --- a/test/shared_type_tester.dart +++ b/test/shared_type_tester.dart @@ -41,9 +41,9 @@ void sharedTypeTests( if (!skipPrimitives) { group('primitives', () { test('', () { - final stringValue = 'test'; - final boolValue = false; - final nullValue = null; + const stringValue = 'test'; + const boolValue = false; + const nullValue = null; testTypeValue(stringValue); testTypeValue(boolValue); @@ -51,9 +51,9 @@ void sharedTypeTests( }); if (!skipNumTypes) { test('num types', () { - final intValue = 1 as int; // ignore: unnecessary_cast - final doubleValue = 1.1; - final numValue = 1 as num; // ignore: unnecessary_cast + const intValue = 1 as int; // ignore: unnecessary_cast + const doubleValue = 1.1; + const numValue = 1 as num; // ignore: unnecessary_cast testTypeValue(intValue); testTypeValue(doubleValue); diff --git a/test/util.dart b/test/util.dart index ea62dc55..5384fc78 100644 --- a/test/util.dart +++ b/test/util.dart @@ -107,7 +107,7 @@ class RefTestCaseCollection { final calls = []; return RefTestCase( name: name, - ref: (value) => calls.add(value), + ref: calls.add, verifyRefWasUpdated: (actualValue) => expect(calls, [same(actualValue)], reason: _reasonMessage(name)), getCurrent: () => calls.single, ); @@ -118,7 +118,7 @@ class RefTestCaseCollection { final calls = []; return RefTestCase( name: name, - ref: (T value) => calls.add(value), + ref: calls.add, verifyRefWasUpdated: (actualValue) => expect(calls, [same(actualValue)], reason: _reasonMessage(name)), getCurrent: () => calls.single, ); @@ -140,7 +140,7 @@ class RefTestCaseCollection { final calls = []; return RefTestCase( name: name, - ref: allowInterop((value) => calls.add(value)), + ref: allowInterop(calls.add), verifyRefWasUpdated: (actualValue) => expect(calls, [same(actualValue)], reason: _reasonMessage(name)), getCurrent: () => calls.single, isJs: true, diff --git a/tool/run_consumer_tests.dart b/tool/run_consumer_tests.dart index faa2e4b4..b7314b16 100644 --- a/tool/run_consumer_tests.dart +++ b/tool/run_consumer_tests.dart @@ -2,7 +2,7 @@ import 'dart:io'; import 'package:args/args.dart'; -Future main(List args) async { +Future main(List args) async { final parser = ArgParser() ..addOption('repoName') ..addOption('orgName') From a7beb886f182427494d7e40a576bc2fe4630a63f Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 16:08:32 -0700 Subject: [PATCH 21/31] Ignore componentZone usage warnings --- lib/react_client/component_factory.dart | 2 ++ lib/react_client/react_interop.dart | 1 + lib/src/react_client/dart_interop_statics.dart | 10 ++++++++++ 3 files changed, 13 insertions(+) diff --git a/lib/react_client/component_factory.dart b/lib/react_client/component_factory.dart index d4c88cc7..b01dd712 100644 --- a/lib/react_client/component_factory.dart +++ b/lib/react_client/component_factory.dart @@ -361,6 +361,7 @@ JsFunctionComponent _wrapFunctionComponent(DartFunctionComponent dartFunctionCom // to force `null` as the return value if user returns a Dart `null`. // See: https://github.com/dart-lang/sdk/issues/27485 jsFunctionComponent(JsMap jsProps, [JsMap _legacyContext]) => + // ignore: invalid_use_of_visible_for_testing_member componentZone.run(() => dartFunctionComponent(JsBackedMap.backedBy(jsProps)) ?? jsNull); JsFunctionComponent interopFunction = allowInterop(jsFunctionComponent); if (displayName != null) { @@ -386,6 +387,7 @@ ReactClass _wrapForwardRefFunctionComponent(DartForwardRefFunctionComponent dart // to force `null` as the return value if user returns a Dart `null`. // See: https://github.com/dart-lang/sdk/issues/27485 jsFunctionComponent(JsMap props, dynamic ref) => + // ignore: invalid_use_of_visible_for_testing_member componentZone.run(() => dartFunctionComponent(JsBackedMap.backedBy(props), ref) ?? jsNull); final interopFunction = allowInterop(jsFunctionComponent); diff --git a/lib/react_client/react_interop.dart b/lib/react_client/react_interop.dart index ffac42ea..3d35c4c6 100644 --- a/lib/react_client/react_interop.dart +++ b/lib/react_client/react_interop.dart @@ -240,6 +240,7 @@ ReactJsComponentFactoryProxy forwardRef( Function(Map props, Ref ref) wrapperFunction, { String displayName = 'Anonymous', }) { + // ignore: invalid_use_of_visible_for_testing_member final wrappedComponent = allowInterop((JsMap props, JsRef ref) => componentZone.run(() { final dartProps = JsBackedMap.backedBy(props); for (final value in dartProps.values) { diff --git a/lib/src/react_client/dart_interop_statics.dart b/lib/src/react_client/dart_interop_statics.dart index 0ea0cae7..de3c54ec 100644 --- a/lib/src/react_client/dart_interop_statics.dart +++ b/lib/src/react_client/dart_interop_statics.dart @@ -202,6 +202,7 @@ abstract class ReactDartInteropStatics2 { } static Component2 initComponent(ReactComponent jsThis, ComponentStatics2 componentStatics) => // dartfmt + // ignore: invalid_use_of_visible_for_testing_member componentZone.run(() { final component = componentStatics.componentFactory(); // Return the component so that the JS proxying component can store it, @@ -222,11 +223,13 @@ abstract class ReactDartInteropStatics2 { }); static void handleComponentDidMount(Component2 component) => // dartfmt + // ignore: invalid_use_of_visible_for_testing_member componentZone.run(() { component.componentDidMount(); }); static bool handleShouldComponentUpdate(Component2 component, JsMap jsNextProps, JsMap jsNextState) => // dartfmt + // ignore: invalid_use_of_visible_for_testing_member componentZone.run(() { final value = component.shouldComponentUpdate( JsBackedMap.backedBy(jsNextProps), @@ -242,6 +245,7 @@ abstract class ReactDartInteropStatics2 { static JsMap handleGetDerivedStateFromProps( ComponentStatics2 componentStatics, JsMap jsNextProps, JsMap jsPrevState) => // dartfmt + // ignore: invalid_use_of_visible_for_testing_member componentZone.run(() { final derivedState = componentStatics.instanceForStaticMethods .getDerivedStateFromProps(JsBackedMap.backedBy(jsNextProps), JsBackedMap.backedBy(jsPrevState)); @@ -252,6 +256,7 @@ abstract class ReactDartInteropStatics2 { }); static dynamic handleGetSnapshotBeforeUpdate(Component2 component, JsMap jsPrevProps, JsMap jsPrevState) => // dartfmt + // ignore: invalid_use_of_visible_for_testing_member componentZone.run(() { final snapshotValue = component.getSnapshotBeforeUpdate( JsBackedMap.backedBy(jsPrevProps), @@ -264,6 +269,7 @@ abstract class ReactDartInteropStatics2 { static void handleComponentDidUpdate( Component2 component, ReactComponent jsThis, JsMap jsPrevProps, JsMap jsPrevState, [dynamic snapshot]) => // dartfmt + // ignore: invalid_use_of_visible_for_testing_member componentZone.run(() { component.componentDidUpdate( JsBackedMap.backedBy(jsPrevProps), @@ -273,11 +279,13 @@ abstract class ReactDartInteropStatics2 { }); static void handleComponentWillUnmount(Component2 component) => // dartfmt + // ignore: invalid_use_of_visible_for_testing_member componentZone.run(() { component.componentWillUnmount(); }); static void handleComponentDidCatch(Component2 component, dynamic error, ReactErrorInfo info) => // dartfmt + // ignore: invalid_use_of_visible_for_testing_member componentZone.run(() { // Due to the error object being passed in from ReactJS it is a javascript object that does not get dartified. // To fix this we throw the error again from Dart to the JS side and catch it Dart side which re-dartifies it. @@ -291,6 +299,7 @@ abstract class ReactDartInteropStatics2 { }); static JsMap handleGetDerivedStateFromError(ComponentStatics2 componentStatics, dynamic error) => // dartfmt + // ignore: invalid_use_of_visible_for_testing_member componentZone.run(() { // Due to the error object being passed in from ReactJS it is a javascript object that does not get dartified. // To fix this we throw the error again from Dart to the JS side and catch it Dart side which re-dartifies it. @@ -304,6 +313,7 @@ abstract class ReactDartInteropStatics2 { }); static dynamic handleRender(Component2 component, JsMap jsProps, JsMap jsState, dynamic jsContext) => // dartfmt + // ignore: invalid_use_of_visible_for_testing_member componentZone.run(() { _updatePropsAndStateWithJs(component, jsProps, jsState); _updateContextWithJs(component, jsContext); From 1a6d5346487435182be75459699c32d79ec9a928 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 16:09:35 -0700 Subject: [PATCH 22/31] Remove unused code --- lib/react.dart | 204 ---------------------------- lib/react_client/js_backed_map.dart | 1 - 2 files changed, 205 deletions(-) diff --git a/lib/react.dart b/lib/react.dart index 5101e15e..a106e994 100644 --- a/lib/react.dart +++ b/lib/react.dart @@ -2116,207 +2116,3 @@ dynamic view = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('view /// The SVG `` [VkernElement]. dynamic vkern = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('vkern')); - -/// Create React DOM `Component`s by calling the specified [creator]. -_createDOMComponents(creator) { - a = creator('a'); - abbr = creator('abbr'); - address = creator('address'); - area = creator('area'); - article = creator('article'); - aside = creator('aside'); - audio = creator('audio'); - b = creator('b'); - base = creator('base'); - bdi = creator('bdi'); - bdo = creator('bdo'); - big = creator('big'); - blockquote = creator('blockquote'); - body = creator('body'); - br = creator('br'); - button = creator('button'); - canvas = creator('canvas'); - caption = creator('caption'); - cite = creator('cite'); - code = creator('code'); - col = creator('col'); - colgroup = creator('colgroup'); - data = creator('data'); - datalist = creator('datalist'); - dd = creator('dd'); - del = creator('del'); - details = creator('details'); - dfn = creator('dfn'); - dialog = creator('dialog'); - div = creator('div'); - dl = creator('dl'); - dt = creator('dt'); - em = creator('em'); - embed = creator('embed'); - fieldset = creator('fieldset'); - figcaption = creator('figcaption'); - figure = creator('figure'); - footer = creator('footer'); - form = creator('form'); - h1 = creator('h1'); - h2 = creator('h2'); - h3 = creator('h3'); - h4 = creator('h4'); - h5 = creator('h5'); - h6 = creator('h6'); - head = creator('head'); - header = creator('header'); - hr = creator('hr'); - html = creator('html'); - i = creator('i'); - iframe = creator('iframe'); - img = creator('img'); - input = creator('input'); - ins = creator('ins'); - kbd = creator('kbd'); - keygen = creator('keygen'); - label = creator('label'); - legend = creator('legend'); - li = creator('li'); - link = creator('link'); - main = creator('main'); - map = creator('map'); - mark = creator('mark'); - menu = creator('menu'); - menuitem = creator('menuitem'); - meta = creator('meta'); - meter = creator('meter'); - nav = creator('nav'); - noscript = creator('noscript'); - object = creator('object'); - ol = creator('ol'); - optgroup = creator('optgroup'); - option = creator('option'); - output = creator('output'); - p = creator('p'); - param = creator('param'); - picture = creator('picture'); - pre = creator('pre'); - progress = creator('progress'); - q = creator('q'); - rp = creator('rp'); - rt = creator('rt'); - ruby = creator('ruby'); - s = creator('s'); - samp = creator('samp'); - script = creator('script'); - section = creator('section'); - select = creator('select'); - small = creator('small'); - source = creator('source'); - span = creator('span'); - strong = creator('strong'); - style = creator('style'); - sub = creator('sub'); - summary = creator('summary'); - sup = creator('sup'); - table = creator('table'); - tbody = creator('tbody'); - td = creator('td'); - textarea = creator('textarea'); - tfoot = creator('tfoot'); - th = creator('th'); - thead = creator('thead'); - time = creator('time'); - title = creator('title'); - tr = creator('tr'); - track = creator('track'); - u = creator('u'); - ul = creator('ul'); - variable = creator('var'); - video = creator('video'); - wbr = creator('wbr'); - - // SVG Elements - altGlyph = creator('altGlyph'); - altGlyphDef = creator('altGlyphDef'); - altGlyphItem = creator('altGlyphItem'); - animate = creator('animate'); - animateColor = creator('animateColor'); - animateMotion = creator('animateMotion'); - animateTransform = creator('animateTransform'); - circle = creator('circle'); - clipPath = creator('clipPath'); - colorProfile = creator('color-profile'); - cursor = creator('cursor'); - defs = creator('defs'); - desc = creator('desc'); - discard = creator('discard'); - ellipse = creator('ellipse'); - feBlend = creator('feBlend'); - feColorMatrix = creator('feColorMatrix'); - feComponentTransfer = creator('feComponentTransfer'); - feComposite = creator('feComposite'); - feConvolveMatrix = creator('feConvolveMatrix'); - feDiffuseLighting = creator('feDiffuseLighting'); - feDisplacementMap = creator('feDisplacementMap'); - feDistantLight = creator('feDistantLight'); - feDropShadow = creator('feDropShadow'); - feFlood = creator('feFlood'); - feFuncA = creator('feFuncA'); - feFuncB = creator('feFuncB'); - feFuncG = creator('feFuncG'); - feFuncR = creator('feFuncR'); - feGaussianBlur = creator('feGaussianBlur'); - feImage = creator('feImage'); - feMerge = creator('feMerge'); - feMergeNode = creator('feMergeNode'); - feMorphology = creator('feMorphology'); - feOffset = creator('feOffset'); - fePointLight = creator('fePointLight'); - feSpecularLighting = creator('feSpecularLighting'); - feSpotLight = creator('feSpotLight'); - feTile = creator('feTile'); - feTurbulence = creator('feTurbulence'); - filter = creator('filter'); - font = creator('font'); - fontFace = creator('font-face'); - fontFaceFormat = creator('font-face-format'); - fontFaceName = creator('font-face-name'); - fontFaceSrc = creator('font-face-src'); - fontFaceUri = creator('font-face-uri'); - foreignObject = creator('foreignObject'); - g = creator('g'); - glyph = creator('glyph'); - glyphRef = creator('glyphRef'); - hatch = creator('hatch'); - hatchpath = creator('hatchpath'); - hkern = creator('hkern'); - image = creator('image'); - line = creator('line'); - linearGradient = creator('linearGradient'); - marker = creator('marker'); - mask = creator('mask'); - mesh = creator('mesh'); - meshgradient = creator('meshgradient'); - meshpatch = creator('meshpatch'); - meshrow = creator('meshrow'); - metadata = creator('metadata'); - missingGlyph = creator('missing-glyph'); - mpath = creator('mpath'); - path = creator('path'); - pattern = creator('pattern'); - polygon = creator('polygon'); - polyline = creator('polyline'); - radialGradient = creator('radialGradient'); - rect = creator('rect'); - svgSet = creator('set'); - solidcolor = creator('solidcolor'); - stop = creator('stop'); - svg = creator('svg'); - svgSwitch = creator('switch'); - symbol = creator('symbol'); - text = creator('text'); - textPath = creator('textPath'); - tref = creator('tref'); - tspan = creator('tspan'); - unknown = creator('unknown'); - use = creator('use'); - view = creator('view'); - vkern = creator('vkern'); -} diff --git a/lib/react_client/js_backed_map.dart b/lib/react_client/js_backed_map.dart index f05969cc..717af30d 100644 --- a/lib/react_client/js_backed_map.dart +++ b/lib/react_client/js_backed_map.dart @@ -158,7 +158,6 @@ JsMap jsBackingMapOrJsCopy(Map map) { abstract class _Object { external static void assign(JsMap to, JsMap from); external static List keys(JsMap object); - external static List values(JsMap object); } @JS('Reflect') From 9949639e42cd870832c69d85cf8c153e00837b07 Mon Sep 17 00:00:00 2001 From: Greg Littlefield Date: Wed, 9 Aug 2023 16:11:19 -0700 Subject: [PATCH 23/31] Fix warnings by hand --- example/test/function_component_test.dart | 2 +- lib/react_client/component_factory.dart | 10 ++++------ lib/react_client/react_interop.dart | 5 ++--- test/factory/common_factory_tests.dart | 9 +++++---- test/forward_ref_test.dart | 1 - test/lifecycle_test/component2.dart | 2 +- test/util.dart | 4 ++-- 7 files changed, 15 insertions(+), 18 deletions(-) diff --git a/example/test/function_component_test.dart b/example/test/function_component_test.dart index 5a57d551..341ebe63 100644 --- a/example/test/function_component_test.dart +++ b/example/test/function_component_test.dart @@ -467,7 +467,7 @@ UseImperativeHandleTestComponent2(Map props) { class ChatAPI { static void subscribeToFriendStatus(int id, Function handleStatusChange) => - handleStatusChange({'isOnline': id % 2 == 0 ? true : false}); + handleStatusChange({'isOnline': id % 2 == 0}); static void unsubscribeFromFriendStatus(int id, Function handleStatusChange) => handleStatusChange({'isOnline': false}); diff --git a/lib/react_client/component_factory.dart b/lib/react_client/component_factory.dart index b01dd712..8d28c8cb 100644 --- a/lib/react_client/component_factory.dart +++ b/lib/react_client/component_factory.dart @@ -87,9 +87,8 @@ class ReactDartComponentFactoryProxy extends React /// into [generateExtendedJsProps] upon [ReactElement] creation. final Map defaultProps; - ReactDartComponentFactoryProxy(ReactClass reactClass) - : reactClass = reactClass, - defaultProps = reactClass.dartDefaultProps; + ReactDartComponentFactoryProxy(this.reactClass) + : defaultProps = reactClass.dartDefaultProps; @override ReactClass get type => reactClass; @@ -182,9 +181,8 @@ class ReactDartComponentFactoryProxy2 extends Rea @override final Map defaultProps; - ReactDartComponentFactoryProxy2(ReactClass reactClass) - : reactClass = reactClass, - defaultProps = JsBackedMap.fromJs(reactClass.defaultProps); + ReactDartComponentFactoryProxy2(this.reactClass) + : defaultProps = JsBackedMap.fromJs(reactClass.defaultProps); @override ReactClass get type => reactClass; diff --git a/lib/react_client/react_interop.dart b/lib/react_client/react_interop.dart index 3d35c4c6..a48a67fb 100644 --- a/lib/react_client/react_interop.dart +++ b/lib/react_client/react_interop.dart @@ -1,4 +1,3 @@ -// ignore_for_file: deprecated_member_use_from_same_package /// JS interop classes for main React JS APIs and react-dart internals. /// /// For use in `react_client.dart` and by advanced react-dart users. @@ -855,10 +854,10 @@ class JsComponentConfig { @anonymous class JsComponentConfig2 { external factory JsComponentConfig2({ + @required List skipMethods, dynamic contextType, JsMap defaultProps, JsMap propTypes, - @required List skipMethods, }); } @@ -874,5 +873,5 @@ class ReactErrorInfo { /// The dart stack trace associated with this error. external StackTrace get dartStackTrace; - external set dartStackTrace(StackTrace); + external set dartStackTrace(StackTrace value); } diff --git a/test/factory/common_factory_tests.dart b/test/factory/common_factory_tests.dart index cfa319e3..8d273543 100644 --- a/test/factory/common_factory_tests.dart +++ b/test/factory/common_factory_tests.dart @@ -405,7 +405,6 @@ void refTests( test('string refs', () { final renderedInstance = _renderWithStringRefSupportingOwner(() => factory({'ref': 'test'})); - // ignore: deprecated_member_use_from_same_package verifyRefValue(renderedInstance.dartComponent.ref('test')); }); }); @@ -645,9 +644,7 @@ class EventTestCase { description = 'JS handler $description'; String get _camelCaseEventName { - var name = eventPropKey.replaceFirst(RegExp(r'^on'), ''); - name = name.substring(0, 1).toLowerCase() + name.substring(1); - return name; + return eventPropKey.replaceFirst(RegExp(r'^on'), '').capitalize(); } void simulate(Element node) => callMethod(_Simulate, _camelCaseEventName, [node]); @@ -656,5 +653,9 @@ class EventTestCase { String toString() => 'EventHelper: ($eventPropKey) $description'; } +extension on String { + String capitalize() => substring(0, 1).toLowerCase() + substring(1); +} + @JS('React.addons.TestUtils.Simulate') external dynamic get _Simulate; diff --git a/test/forward_ref_test.dart b/test/forward_ref_test.dart index 4097043e..011ed576 100644 --- a/test/forward_ref_test.dart +++ b/test/forward_ref_test.dart @@ -13,7 +13,6 @@ import 'factory/common_factory_tests.dart'; main() { group('forwardRef', () { group('- common factory behavior -', () { - // ignore: deprecated_member_use_from_same_package final ForwardRefTest = react.forwardRef((props, ref) { props['onDartRender']?.call(props); return react.div({...props, 'ref': ref}); diff --git a/test/lifecycle_test/component2.dart b/test/lifecycle_test/component2.dart index 1bca228b..926bbdb4 100644 --- a/test/lifecycle_test/component2.dart +++ b/test/lifecycle_test/component2.dart @@ -220,7 +220,7 @@ class _ErrorComponent extends react.Component2 { } @override - void render() { + render() { _throwError(); return react.div({'key': 'defaultMessage'}, 'Error'); } diff --git a/test/util.dart b/test/util.dart index 5384fc78..9e1ddf1c 100644 --- a/test/util.dart +++ b/test/util.dart @@ -124,7 +124,7 @@ class RefTestCaseCollection { ); } - RefTestCase createRefObjectCase() { + RefTestCase createRefObjectCase() { const name = 'ref object'; final ref = createRef(); return RefTestCase( @@ -175,7 +175,7 @@ class RefTestCaseCollection { createJsRefObjectCase(), ]; - RefTestCase createCaseByName(String name) => createAllCases().singleWhere((c) => c.name == name); + RefTestCase createCaseByName(String name) => createAllCases().singleWhere((c) => c.name == name); List get allTestCaseNames => createAllCases().map((c) => c.name).toList(); } From 5344c86f9a57fe993ed7a8ec8e74356bb6403b0a Mon Sep 17 00:00:00 2001 From: Aaron Lademann Date: Wed, 9 Aug 2023 16:25:50 -0700 Subject: [PATCH 24/31] Fix comment references and links - all credit to @aaronlademann-wf --- example/geocodes/geocodes.dart | 50 +- example/geocodes/geocodes.html | 2 +- lib/hooks.dart | 10 +- lib/react.dart | 480 +++++++++--------- lib/react_client/bridge.dart | 2 +- lib/react_client/component_factory.dart | 2 +- lib/react_client/js_interop_helpers.dart | 4 +- lib/react_client/react_interop.dart | 16 +- lib/react_dom.dart | 8 +- lib/react_test_utils.dart | 4 +- lib/src/ddc_emulated_function_name_bug.dart | 8 +- .../react_client/component_registration.dart | 8 +- .../synthetic_event_wrappers.dart | 6 +- lib/src/typedefs.dart | 2 +- test/lifecycle_test/util.dart | 6 +- test/util.dart | 2 +- 16 files changed, 304 insertions(+), 306 deletions(-) diff --git a/example/geocodes/geocodes.dart b/example/geocodes/geocodes.dart index 3ca39da4..0235f483 100644 --- a/example/geocodes/geocodes.dart +++ b/example/geocodes/geocodes.dart @@ -6,32 +6,30 @@ import 'dart:html'; import 'package:react/react.dart' as react; import 'package:react/react_dom.dart' as react_dom; -/** - * Hello, - * - * This is the Dart portion of the tutorial for the Dart react package. - * - * We'll go through a simple app that queries the Google Maps API and shows the result to the user. - * It also stores the search history and allows the user to reload past queries. - * - * In this file you'll find the structure and the logic of the app. There is also a `geocodes.html` file which contains - * the mount point. - * - * Be sure that you understand the basic concepts of [React](http://facebook.github.io/react/) before reading this - * tutorial. - * - * Enjoy! - */ +/// Hello, +/// +/// This is the Dart portion of the tutorial for the Dart react package. +/// +/// We'll go through a simple app that queries the Google Maps API and shows the result to the user. +/// It also stores the search history and allows the user to reload past queries. +/// +/// In this file you'll find the structure and the logic of the app. There is also a `geocodes.html` file which contains +/// the mount point. +/// +/// Be sure that you understand the basic concepts of [React](https://reactjs.org/) before reading this +/// tutorial. +/// +/// Enjoy! /// Divide your app into components and conquer! /// -/// This is the first custom [Component]. +/// This is the first custom `Component`. /// /// It is just an HTML `
  • ` element displaying a single API response to the user. class _GeocodesResultItem extends react.Component { /// The only function you must implement in the custom component is [render]. /// - /// Every [Component] has a map of properties called [Component.props]. It can be specified during creation. + /// Every `Component` has a map of properties called `props`. It can be specified during creation. @override render() { return react.tr({}, [ @@ -42,12 +40,12 @@ class _GeocodesResultItem extends react.Component { } } -/// Now we need to tell ReactJS that our custom [Component] exists by calling [registerComponent]. +/// Now we need to tell ReactJS that our custom `Component` exists by calling `registerComponent`. /// /// As a reward, it gives us a function, that takes the properties and returns our element. You'll see it in action /// shortly. /// -/// This is the only correct way to create a [Component]. Do not use the constructor! +/// This is the only correct way to create a `Component`. Do not use the constructor! var geocodesResultItem = react.registerComponent(() => _GeocodesResultItem()); /// In this component we'll build an HTML `
    ` element full of the `` elements generated by @@ -97,11 +95,11 @@ class _GeocodesResultList extends react.Component { var geocodesResultList = react.registerComponent(() => _GeocodesResultList()); -/// In this [Component] we'll build a search form. +/// In this `Component` we'll build a search form. /// -/// This [Component] illustrates that: +/// This `Component` illustrates that: /// -/// > The functions can be [Component] parameters _(handy for callbacks)_ +/// > The functions can be `Component` parameters _(handy for callbacks)_ /// /// > The DOM [Element]s can be accessed using `ref`s. class _GeocodesForm extends react.Component { @@ -216,9 +214,9 @@ class _GeocodesHistoryList extends react.Component { var geocodesHistoryList = react.registerComponent(() => _GeocodesHistoryList()); -/// The root [Component] of our application. +/// The root `Component` of our application. /// -/// Introduces [state]. Both [state] and [props] are valid locations to store [Component] data. +/// Introduces [state]. Both [state] and [props] are valid locations to store `Component` data. /// /// However, there are some key differences to note: /// @@ -228,7 +226,7 @@ var geocodesHistoryList = react.registerComponent(() => _GeocodesHistoryList()); /// /// > When [state] is changed, the component will re-render. /// -/// It's a common practice to store the application data in the [state] of the root [Component]. It will re-render +/// It's a common practice to store the application data in the [state] of the root `Component`. It will re-render /// every time the state is changed. However, it is not required - you can also use normal variables and re-render /// manually if you wish. /// diff --git a/example/geocodes/geocodes.html b/example/geocodes/geocodes.html index 453ead1f..fef1312c 100644 --- a/example/geocodes/geocodes.html +++ b/example/geocodes/geocodes.html @@ -12,7 +12,7 @@ * In this file you'll find the mount point of the app. There is also a `geocodes.dart` file which contains the * structure and the application logic. * - * Be sure that you understand the basic concepts of [React](http://facebook.github.io/react/) before reading this + * Be sure that you understand the basic concepts of [React](https://reactjs.org/) before reading this * tutorial. * * Enjoy! diff --git a/lib/hooks.dart b/lib/hooks.dart index 0f61c449..cd9947ef 100644 --- a/lib/hooks.dart +++ b/lib/hooks.dart @@ -165,10 +165,10 @@ void useEffect(dynamic Function() sideEffect, [List dependencies]) { /// /// Learn more: . class ReducerHook { - /// The first item of the pair returned by [React.userReducer]. + /// The first item of the pair returned by [React.useReducer]. TState _state; - /// The second item in the pair returned by [React.userReducer]. + /// The second item in the pair returned by [React.useReducer]. void Function(TAction) _dispatch; ReducerHook(TState Function(TState state, TAction action) reducer, TState initialState) { @@ -201,7 +201,7 @@ class ReducerHook { void dispatch(TAction action) => _dispatch(action); } -/// Initializes state of a [DartFunctionComponent] to [initialState] and creates [dispatch] method. +/// Initializes state of a [DartFunctionComponent] to [initialState] and creates a `dispatch` method. /// /// __Example__: /// @@ -241,7 +241,7 @@ ReducerHook useReducer( TState Function(TState state, TAction action) reducer, TState initialState) => ReducerHook(reducer, initialState); -/// Initializes state of a [DartFunctionComponent] to [init(initialArg)] and creates [dispatch] method. +/// Initializes state of a [DartFunctionComponent] to `init(initialArg)` and creates `dispatch` method. /// /// __Example__: /// @@ -581,7 +581,7 @@ void useImperativeHandle(dynamic ref, dynamic Function() createHandle, [List = Error Function(TProps props, PropValidatorInfo i /// A React component declared using a function that takes in [props] and returns rendered output. /// -/// See . +/// See . /// /// [props] is typed as [JsBackedMap] so that dart2js can optimize props accesses. typedef DartFunctionComponent = dynamic Function(JsBackedMap props); @@ -66,7 +66,7 @@ var Fragment = ReactJsComponentFactoryProxy(React.Fragment); /// [Suspense] lets you display a fallback UI until its children have finished loading. /// -/// Like [react.Fragment], [Suspense] does not render any visible UI. +/// Like [Fragment], [Suspense] does not render any visible UI. /// It lets you specify a loading indicator in case some components in /// the tree below it are not yet ready to render. /// [Suspense] currently works with: @@ -103,8 +103,8 @@ var Suspense = ReactJsComponentFactoryProxy(React.Suspense); /// See: var StrictMode = ReactJsComponentFactoryProxy(React.StrictMode); -/// Top-level ReactJS [Component class](https://facebook.github.io/react/docs/react-component.html) -/// which provides the [ReactJS Component API](https://facebook.github.io/react/docs/react-component.html#reference) +/// Top-level ReactJS [Component class](https://reactjs.org/docs/react-component.html) +/// which provides the [ReactJS Component API](https://reactjs.org/docs/react-component.html#reference) /// /// __Deprecated. Use [Component2] instead.__ @Deprecated('7.0.0') @@ -208,11 +208,11 @@ abstract class Component { /// The List of transactional `setState` callbacks to be called before the component updates. List get transactionalSetStateCallbacks => _transactionalSetStateCallbacks; - /// The JavaScript [`ReactComponent`](https://facebook.github.io/react/docs/top-level-api.html#reactdom.render) + /// The JavaScript [`ReactComponent`](https://reactjs.org/docs/react-api.html#reactdom.render) /// instance of this `Component` returned by [render]. dynamic get jsThis => _jsThis; - /// Allows the [ReactJS `displayName` property](https://facebook.github.io/react/docs/react-component.html#displayname) + /// Allows the [ReactJS `displayName` property](https://reactjs.org/docs/react-component.html#displayname) /// to be set for debugging purposes. String get displayName => runtimeType.toString(); @@ -331,7 +331,7 @@ abstract class Component { /// /// Also allows [newState] to be used as a transactional `setState` callback. /// - /// See: + /// See: void setState(covariant dynamic newState, [Function() callback]) { if (newState is Map) { _nextState.addAll(newState); @@ -351,7 +351,7 @@ abstract class Component { /// /// Optionally accepts a callback that gets called after the component updates. /// - /// See: + /// See: /// /// > __DEPRECATED.__ /// > @@ -371,17 +371,17 @@ abstract class Component { /// If you call [setState] within this method, [render] will see the updated state and will be executed only once /// despite the [state] value change. /// - /// See: + /// See: void componentWillMount() {} /// ReactJS lifecycle method that is invoked once, only on the client _(not on the server)_, immediately after the /// initial rendering occurs. /// - /// At this point in the lifecycle, you can access any [ref]s to the children of [rootNode]. + /// At this point in the lifecycle, you can access any [ref]s to the children of the root node. /// /// The [componentDidMount] method of child `Component`s is invoked _before_ that of parent `Component`. /// - /// See: + /// See: void componentDidMount() {} /// ReactJS lifecycle method that is invoked when a `Component` is receiving [newProps]. @@ -393,7 +393,7 @@ abstract class Component { /// /// Calling [setState] within this function will not trigger an additional [render]. /// - /// See: + /// See: /// > __UNSUPPORTED IN COMPONENT2__ /// > /// > This will be removed once 7.0.0 releases; switching to [Component2.getDerivedStateFromProps] is the path forward. @@ -414,7 +414,7 @@ abstract class Component { /// Use this as an opportunity to return `false` when you're certain that the transition to the new props and state /// will not require a component update. /// - /// See: + /// See: bool shouldComponentUpdate(Map nextProps, Map nextState) => true; /// > __DEPRECATED - DO NOT USE__ @@ -437,7 +437,7 @@ abstract class Component { /// __Note__: Choose either this method or [componentWillUpdateWithContext]. They are both called at the same time so /// using both provides no added benefit. /// - /// See: + /// See: /// /// > __UNSUPPORTED IN COMPONENT2__ /// > @@ -463,18 +463,18 @@ abstract class Component { /// /// This method is not called for the initial [render]. /// - /// Use this as an opportunity to operate on the [rootNode] (DOM) when the `Component` has been updated as a result + /// Use this as an opportunity to operate on the root node (DOM) when the `Component` has been updated as a result /// of the values of [prevProps] / [prevState]. /// - /// See: + /// See: void componentDidUpdate(Map prevProps, Map prevState) {} /// ReactJS lifecycle method that is invoked immediately before a `Component` is unmounted from the DOM. /// - /// Perform any necessary cleanup in this method, such as invalidating timers or cleaning up any DOM [Element]s that + /// Perform any necessary cleanup in this method, such as invalidating timers or cleaning up any DOM `Element`s that /// were created in [componentDidMount]. /// - /// See: + /// See: void componentWillUnmount() {} /// Returns a Map of context to be passed to descendant components. @@ -518,25 +518,25 @@ abstract class Component { /// Invoked once before the `Component` is mounted. The return value will be used as the initial value of [state]. /// - /// See: + /// See: Map getInitialState() => {}; - /// Invoked once and cached when [reactComponentClass] is called. Values in the mapping will be set on [props] + /// Invoked once and cached when [registerComponent] is called. Values in the mapping will be set on [props] /// if that prop is not specified by the parent component. /// /// This method is invoked before any instances are created and thus cannot rely on [props]. In addition, be aware /// that any complex objects returned by `getDefaultProps` will be shared across instances, not copied. /// - /// See: + /// See: Map getDefaultProps() => {}; /// __Required.__ /// - /// When called, it should examine [props] and [state] and return a single child [Element]. This child [Element] can - /// be either a virtual representation of a native DOM component (such as [DivElement]) or another composite + /// When called, it should examine [props] and [state] and return a single child `Element`. This child `Element` can + /// be either a virtual representation of a native DOM component (such as `DivElement`) or another composite /// `Component` that you've defined yourself. /// - /// See: + /// See: dynamic render(); } @@ -568,7 +568,7 @@ abstract class Component { /// 4. Supports React 16 [context] abstract class Component2 implements Component { /// Accessed once and cached when instance is created. The [contextType] property on a class can be assigned - /// a [ReactDartContext] object created by [React.createContext]. This lets you consume the nearest current value of + /// a [ReactContext] object created by [React.createContext]. This lets you consume the nearest current value of /// that Context using [context]. /// /// __Example__: @@ -589,7 +589,7 @@ abstract class Component2 implements Component { /// See: Context get contextType => null; - /// Invoked once and cached when [reactComponentClass] is called. Values in the mapping will be set on [props] + /// Invoked once and cached when [registerComponent] is called. Values in the mapping will be set on [props] /// if that prop is not specified by the parent component. /// /// This method is invoked before any instances are created and thus cannot rely on [props]. In addition, be aware @@ -668,12 +668,12 @@ abstract class Component2 implements Component { @Deprecated('7.0.0') set _jsThis(_) => throw _unsupportedError('_jsThis'); - /// The JavaScript [`ReactComponent`](https://facebook.github.io/react/docs/top-level-api.html#reactdom.render) + /// The JavaScript [`ReactComponent`](https://reactjs.org/docs/react-api.html#reactdom.render) /// instance of this `Component` returned by [render]. @override ReactComponent jsThis; - /// Allows the [ReactJS `displayName` property](https://facebook.github.io/react/docs/react-component.html#displayname) + /// Allows the [ReactJS `displayName` property](https://reactjs.org/docs/react-component.html#displayname) /// to be set for debugging purposes. /// /// In DDC, this will be the class name, but in dart2js it will be null unless @@ -725,11 +725,11 @@ abstract class Component2 implements Component { /// ReactJS lifecycle method that is invoked once, only on the client _(not on the server)_, immediately after the /// initial rendering occurs. /// - /// At this point in the lifecycle, you can access any [ref]s to the children of [rootNode]. + /// At this point in the lifecycle, you can access any [ref]s to the children of the root node. /// /// The [componentDidMount] method of child `Component`s is invoked _before_ that of parent `Component`. /// - /// See: + /// See: @override void componentDidMount() {} @@ -827,7 +827,7 @@ abstract class Component2 implements Component { /// /// This method is not called for the initial [render]. /// - /// Use this as an opportunity to operate on the [rootNode] (DOM) when the `Component` has been updated as a result + /// Use this as an opportunity to operate on the root node (DOM) when the `Component` has been updated as a result /// of the values of [prevProps] / [prevState]. /// /// __Note__: React 16 added a third parameter to `componentDidUpdate`, which @@ -841,7 +841,7 @@ abstract class Component2 implements Component { /// ReactJS lifecycle method that is invoked immediately before a `Component` is unmounted from the DOM. /// - /// Perform any necessary cleanup in this method, such as invalidating timers or cleaning up any DOM [Element]s that + /// Perform any necessary cleanup in this method, such as invalidating timers or cleaning up any DOM `Element`s that /// were created in [componentDidMount]. /// /// See: @@ -978,7 +978,7 @@ abstract class Component2 implements Component { /// Invoked once before the `Component` is mounted. The return value will be used as the initial value of [state]. /// - /// See: + /// See: /// /// > __DEPRECATED - DO NOT USE__ /// > @@ -988,13 +988,13 @@ abstract class Component2 implements Component { @Deprecated('7.0.0') Map getInitialState() => throw _unsupportedLifecycleError('getInitialState'); - /// Invoked once and cached when [reactComponentClass] is called. Values in the mapping will be set on [props] + /// Invoked once and cached when [registerComponent] is called. Values in the mapping will be set on [props] /// if that prop is not specified by the parent component. /// /// This method is invoked before any instances are created and thus cannot rely on [props]. In addition, be aware /// that any complex objects returned by `getDefaultProps` will be shared across instances, not copied. /// - /// See: + /// See: /// /// > __DEPRECATED - DO NOT USE__ /// > @@ -1359,12 +1359,12 @@ mixin TypedSnapshot { void componentDidUpdate(Map prevProps, Map prevState, [covariant TSnapshot snapshot]); } -/// Creates a ReactJS virtual DOM instance (`ReactElement` on the client). +/// Creates a ReactJS virtual DOM instance ([ReactElement] on the client). abstract class ReactComponentFactoryProxy implements Function { /// The type of component created by this factory. get type; - /// Returns a new rendered component instance with the specified [props] and [children]. + /// Returns a new rendered component instance with the specified [props] and [childrenArgs]. /// /// Necessary to work around DDC `dart.dcall` issues in , /// since invoking the function directly doesn't work. @@ -1489,25 +1489,25 @@ class NotSpecified { const NotSpecified(); } -/// Registers [componentFactory] on both client and server. +/// Registers a component factory on both client and server. @Deprecated('Use registerComponent2 after migrating your components from Component to Component2.') /*ComponentRegistrar*/ Function registerComponent = validateJsApiThenReturn(() => registration_utils.registerComponent); -/// Registers [componentFactory] on both client and server. +/// Registers a component factory on both client and server. ComponentRegistrar2 registerComponent2 = validateJsApiThenReturn(() => registration_utils.registerComponent2); -/// Registers [componentFactory] on client. +/// Registers a function component on the client. /// /// Example: /// ``` -/// var myFunctionComponent = registerFunctionComponent((Map props) { +/// var myFunctionComponent = registerFunctionComponent((props) { /// return ['I am a function component', ...props.children]; /// }); /// ``` /// /// Example with display name: /// ``` -/// var myFunctionComponent = registerFunctionComponent((Map props) { +/// var myFunctionComponent = registerFunctionComponent((props) { /// return ['I am a function component', ...props.children]; /// }, displayName: 'myFunctionComponent'); /// ``` @@ -1521,598 +1521,598 @@ ComponentRegistrar2 registerComponent2 = validateJsApiThenReturn(() => registrat FunctionComponentRegistrar registerFunctionComponent = validateJsApiThenReturn(() => registration_utils.registerFunctionComponent); -/// The HTML `` [AnchorElement]. +/// The HTML `` `AnchorElement`. dynamic a = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('a')); -/// The HTML `` [Element]. +/// The HTML `` `Element`. dynamic abbr = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('abbr')); -/// The HTML `
    ` [Element]. +/// The HTML `
    ` `Element`. dynamic address = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('address')); -/// The HTML `` [AreaElement]. +/// The HTML `` `AreaElement`. dynamic area = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('area')); -/// The HTML `
    ` [Element]. +/// The HTML `
    ` `Element`. dynamic article = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('article')); -/// The HTML `
    ` [Element]. +/// The HTML `` `Element`. dynamic col = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('col')); -/// The HTML `` [Element]. +/// The HTML `` `Element`. dynamic colgroup = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('colgroup')); -/// The HTML `` [Element]. +/// The HTML `` `Element`. dynamic data = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('data')); -/// The HTML `` [DataListElement]. +/// The HTML `` `DataListElement`. dynamic datalist = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('datalist')); -/// The HTML `
    ` [Element]. +/// The HTML `
    ` `Element`. dynamic dd = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('dd')); -/// The HTML `` [Element]. +/// The HTML `` `Element`. dynamic del = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('del')); -/// The HTML `
    ` [DetailsElement]. +/// The HTML `
    ` `DetailsElement`. dynamic details = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('details')); -/// The HTML `` [Element]. +/// The HTML `` `Element`. dynamic dfn = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('dfn')); -/// The HTML `` [DialogElement]. +/// The HTML `` `DialogElement`. dynamic dialog = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('dialog')); -/// The HTML `
    ` [DivElement]. +/// The HTML `
    ` `DivElement`. dynamic div = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('div')); -/// The HTML `
    ` [DListElement]. +/// The HTML `
    ` `DListElement`. dynamic dl = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('dl')); -/// The HTML `
    ` [Element]. +/// The HTML `
    ` `Element`. dynamic dt = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('dt')); -/// The HTML `` [Element]. +/// The HTML `` `Element`. dynamic em = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('em')); -/// The HTML `` [EmbedElement]. +/// The HTML `` `EmbedElement`. dynamic embed = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('embed')); -/// The HTML `
    ` [FieldSetElement]. +/// The HTML `
    ` `FieldSetElement`. dynamic fieldset = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('fieldset')); -/// The HTML `
    ` [Element]. +/// The HTML `
    ` `Element`. dynamic figcaption = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('figcaption')); -/// The HTML `
    ` [Element]. +/// The HTML `
    ` `Element`. dynamic figure = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('figure')); -/// The HTML `
    ` [Element]. +/// The HTML `
    ` `Element`. dynamic footer = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('footer')); -/// The HTML `
    ` [FormElement]. +/// The HTML `` `FormElement`. dynamic form = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('form')); -/// The HTML `

    ` [HeadingElement]. +/// The HTML `

    ` `HeadingElement`. dynamic h1 = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('h1')); -/// The HTML `

    ` [HeadingElement]. +/// The HTML `

    ` `HeadingElement`. dynamic h2 = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('h2')); -/// The HTML `

    ` [HeadingElement]. +/// The HTML `

    ` `HeadingElement`. dynamic h3 = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('h3')); -/// The HTML `

    ` [HeadingElement]. +/// The HTML `

    ` `HeadingElement`. dynamic h4 = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('h4')); -/// The HTML `

    ` [HeadingElement]. +/// The HTML `
    ` `HeadingElement`. dynamic h5 = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('h5')); -/// The HTML `
    ` [HeadingElement]. +/// The HTML `
    ` `HeadingElement`. dynamic h6 = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('h6')); -/// The HTML `` [HeadElement]. +/// The HTML `` `HeadElement`. dynamic head = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('head')); -/// The HTML `
    ` [Element]. +/// The HTML `
    ` `Element`. dynamic header = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('header')); -/// The HTML `
    ` [HRElement]. +/// The HTML `
    ` `HRElement`. dynamic hr = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('hr')); -/// The HTML `` [HtmlHtmlElement]. +/// The HTML `` `HtmlHtmlElement`. dynamic html = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('html')); -/// The HTML `` [Element]. +/// The HTML `` `Element`. dynamic i = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('i')); -/// The HTML `
    ` [Element]. +/// The HTML `` `Element`. dynamic caption = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('caption')); -/// The HTML `` [Element]. +/// The HTML `` `Element`. dynamic cite = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('cite')); -/// The HTML `` [Element]. +/// The HTML `` `Element`. dynamic code = validateJsApiThenReturn(() => ReactDomComponentFactoryProxy('code')); -/// The HTML `