Skip to content

Commit

Permalink
refactor: Use variable name on toString in component_test.dart (#2377)
Browse files Browse the repository at this point in the history
This is a cleanup identified on this issue: #2308
Using an amazing unused-code tooling
Now, since Flame is a public API, unused code might not be trivial - it might just mean untested code.

In this case, the unused code is in the tests, which likely means it is indeed necessary.
I tried to infer the intent of the author here, and even considered adding the names of the components to the events, but the events are already always per component, so that was meaningless. I also thought it might be a missing toString, that they would wish to show the component name for debugging purposes, but I didn't see any asserts/logs on the component objects themselves (just the events).
So I concluded there is no reason to keep this field, but lmk if anyone disagrees and I can bring it back and add some function to it.
  • Loading branch information
luanpotter committed Mar 1, 2023
1 parent 79db971 commit f5c0e5e
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/flame/test/components/component_test.dart
Expand Up @@ -33,7 +33,7 @@ void main() {
testWithFlameGame(
'component.removed completes if obtained before the game was ready',
(game) async {
final component = LifecycleComponent('component');
final component = LifecycleComponent();
final removed = component.removed;
await game.add(component);
await game.ready();
Expand All @@ -48,7 +48,7 @@ void main() {
testWithFlameGame(
'component removed completes when set after game is ready',
(game) async {
final component = LifecycleComponent('component');
final component = LifecycleComponent();
await game.add(component);
await game.ready();
final removed = component.removed;
Expand Down Expand Up @@ -1149,9 +1149,9 @@ class TwoChildrenComponent extends Component {

class LifecycleComponent extends Component {
final List<String> events = [];
final String? name;
final String name;

LifecycleComponent([this.name]);
LifecycleComponent([this.name = '']);

int countEvents(String event) {
return events.where((e) => e == event).length;
Expand Down Expand Up @@ -1188,6 +1188,9 @@ class LifecycleComponent extends Component {
super.onGameResize(size);
events.add('onGameResize $size');
}

@override
String toString() => 'LifecycleComponent($name)';
}

class _SlowLoadingComponent extends Component {
Expand Down

0 comments on commit f5c0e5e

Please sign in to comment.