Skip to content

Commit e1e3f7f

Browse files
Fix implicit casts, clean up variable types and final
1 parent 5344c86 commit e1e3f7f

40 files changed

+405
-381
lines changed

example/geocodes/geocodes.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class _GeocodesForm extends react.Component {
156156
/// Handle form submission via `props.onSubmit`
157157
onFormSubmit(react.SyntheticEvent event) {
158158
event.preventDefault();
159-
InputElement inputElement = react_dom.findDOMNode(searchInputInstance);
159+
final inputElement = react_dom.findDOMNode(searchInputInstance);
160160
// The input's value is accessed.
161161
final address = inputElement.value;
162162
inputElement.value = '';
@@ -201,7 +201,7 @@ class _GeocodesHistoryList extends react.Component {
201201
{
202202
'key': 'list',
203203
},
204-
List.from(props['data'].keys.map((key) => geocodesHistoryItem({
204+
List.from((props['data'] as Map).keys.map((key) => geocodesHistoryItem({
205205
'key': key,
206206
'query': props['data'][key]['query'],
207207
'status': props['data'][key]['status'],

example/js_components/js_components.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class _IndexComponent extends react.Component2 {
4747
SimpleCustom({
4848
'foo': 'Foo Prop from dart... IN A JAVASCRIPT COMPONENT!',
4949
'ref': (ref) {
50-
simpleRef = ref;
50+
simpleRef = ref as SimpleCustomComponent;
5151
}
5252
}),
5353
CssBaseline({}),

example/test/error_boundary_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class _ErrorBoundaryComponent extends react.Component2 {
5454

5555
@override
5656
render() {
57-
return state['hasError'] ? 'Error boundary caught an error' : props['children'];
57+
return (state['hasError'] as bool) ? 'Error boundary caught an error' : props['children'];
5858
}
5959
}
6060

@@ -66,7 +66,7 @@ class _ThrowingComponentComponent2 extends react.Component2 {
6666

6767
@override
6868
render() {
69-
if (state['shouldThrow']) {
69+
if (state['shouldThrow'] as bool) {
7070
throw Exception();
7171
}
7272

example/test/function_component_test.dart

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import 'dart:math';
33

44
import 'package:react/hooks.dart';
55
import 'package:react/react.dart' as react;
6-
import 'package:react/react_client/react_interop.dart';
76
import 'package:react/react_dom.dart' as react_dom;
87

98
var hookTestFunctionComponent = react.registerFunctionComponent(HookTestComponent, displayName: 'useStateTest');
@@ -107,14 +106,15 @@ Map reducer(Map state, Map action) {
107106
case 'decrement':
108107
return {...state, 'count': state['count'] - 1};
109108
case 'reset':
110-
return initializeCount(action['payload']);
109+
return initializeCount(action['payload'] as int);
111110
default:
112111
return state;
113112
}
114113
}
115114

116115
UseReducerTestComponent(Map props) {
117-
final state = useReducerLazy(reducer, props['initialCount'] as int, initializeCount);
116+
final initialCount = props['initialCount'] as int;
117+
final state = useReducerLazy(reducer, initialCount, initializeCount);
118118

119119
return react.Fragment({}, [
120120
state.state['count'],
@@ -134,7 +134,7 @@ UseReducerTestComponent(Map props) {
134134
'key': 'urt3',
135135
'onClick': (_) => state.dispatch({
136136
'type': 'reset',
137-
'payload': props['initialCount'],
137+
'payload': initialCount,
138138
})
139139
}, [
140140
'reset'
@@ -297,7 +297,7 @@ final randomUseLayoutEffectTestComponent =
297297
react.registerFunctionComponent(RandomUseLayoutEffectTestComponent, displayName: 'randomUseLayoutEffectTest');
298298

299299
RandomUseLayoutEffectTestComponent(Map props) {
300-
final value = useState<num>(0);
300+
final value = useState<double>(0);
301301

302302
useLayoutEffect(() {
303303
if (value.value == 0) {
@@ -317,7 +317,7 @@ final randomUseEffectTestComponent =
317317
react.registerFunctionComponent(RandomUseEffectTestComponent, displayName: 'randomUseEffectTest');
318318

319319
RandomUseEffectTestComponent(Map props) {
320-
final value = useState<num>(0);
320+
final value = useState<double>(0);
321321

322322
useEffect(() {
323323
if (value.value == 0) {
@@ -357,7 +357,7 @@ final FancyInput = react.forwardRef2((props, ref) {
357357
'value': props['value'],
358358
'onChange': (e) => props['update'](e.target.value),
359359
'placeholder': props['placeholder'],
360-
'style': {'borderColor': props['hasError'] ? 'crimson' : '#999'},
360+
'style': {'borderColor': (props['hasError'] as bool) ? 'crimson' : '#999'},
361361
});
362362
});
363363

@@ -370,8 +370,8 @@ UseImperativeHandleTestComponent(Map props) {
370370
final error = useState('');
371371
final message = useState('');
372372

373-
Ref cityRef = useRef<FancyInputApi>();
374-
Ref stateRef = useRef<FancyInputApi>();
373+
final cityRef = useRef<FancyInputApi>();
374+
final stateRef = useRef<FancyInputApi>();
375375

376376
validate(_) {
377377
if (!RegExp(r'^[a-zA-Z]+$').hasMatch(city.value)) {
@@ -415,21 +415,23 @@ UseImperativeHandleTestComponent(Map props) {
415415
}
416416

417417
final FancyCounter = react.forwardRef2((props, ref) {
418-
final count = useState(0);
418+
final diff = props['diff'] as num;
419+
420+
final count = useState<num>(0);
419421

420422
useImperativeHandle(
421423
ref,
422424
() {
423425
print('FancyCounter: useImperativeHandle re-assigns ref.current');
424426
return {
425-
'increment': () => count.setWithUpdater((prev) => prev + props['diff']),
426-
'decrement': () => count.setWithUpdater((prev) => prev - props['diff']),
427+
'increment': () => count.setWithUpdater((prev) => prev + diff),
428+
'decrement': () => count.setWithUpdater((prev) => prev - diff),
427429
};
428430
},
429431

430432
/// This dependency prevents unnecessary calls of createHandle, by only re-assigning
431-
/// ref.current when `props['diff']` changes.
432-
[props['diff']],
433+
/// ref.current when `diff` changes.
434+
[diff],
433435
);
434436

435437
return react.div({}, count.value);
@@ -478,7 +480,7 @@ StateHook<bool> useFriendStatus(int friendID) {
478480
final isOnline = useState(false);
479481

480482
void handleStatusChange(Map status) {
481-
isOnline.set(status['isOnline']);
483+
isOnline.set(status['isOnline'] as bool);
482484
}
483485

484486
useEffect(() {
@@ -494,8 +496,8 @@ StateHook<bool> useFriendStatus(int friendID) {
494496
return isOnline;
495497
}
496498

497-
final FriendListItem = react.registerFunctionComponent((Map props) {
498-
final isOnline = useFriendStatus(props['friend']['id']);
499+
final FriendListItem = react.registerFunctionComponent((props) {
500+
final isOnline = useFriendStatus(props['friend']['id'] as int);
499501

500502
return react.li({
501503
'style': {'color': isOnline.value ? 'green' : 'black'}
@@ -505,7 +507,7 @@ final FriendListItem = react.registerFunctionComponent((Map props) {
505507
}, displayName: 'FriendListItem');
506508

507509
final UseDebugValueTestComponent = react.registerFunctionComponent(
508-
(Map props) => react.Fragment({}, [
510+
(props) => react.Fragment({}, [
509511
FriendListItem({
510512
'key': 'friend1',
511513
'friend': {'id': 1, 'name': 'user 1'},

example/test/get_dom_node_test.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import 'dart:html';
44
import 'package:react/react.dart' as react;
55
import 'package:react/react_dom.dart' as react_dom;
66

7-
customAssert(text, condition) {
7+
// ignore: avoid_positional_boolean_parameters
8+
void customAssert(String text, bool condition) {
89
if (condition) {
910
print('$text passed');
1011
} else {
11-
throw text;
12+
throw Exception(text);
1213
}
1314
}
1415

0 commit comments

Comments
 (0)