Skip to content

Commit 2f596d8

Browse files
committed
Small refactor
1 parent 09cf046 commit 2f596d8

File tree

5 files changed

+17
-13
lines changed

5 files changed

+17
-13
lines changed

pkgs/hooks_runner/test_data/flag_enthusiast_1/hook/link.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ import 'package:hooks/hooks.dart';
99
// it lands on stable https://github.com/dart-lang/sdk/issues/61166.
1010
void main(List<String> args) async {
1111
await link(args, (input, output) async {
12-
output.registerFlagUse(input.packageName, ['de']);
12+
output.registerCountryUse(input.packageName, ['de']);
1313
});
1414
}

pkgs/hooks_runner/test_data/flag_enthusiast_2/hook/link.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ import 'package:hooks/hooks.dart';
99
// it lands on stable https://github.com/dart-lang/sdk/issues/61166.
1010
void main(List<String> args) async {
1111
await link(args, (input, output) async {
12-
output.registerFlagUse(input.packageName, ['fr']);
12+
output.registerCountryUse(input.packageName, ['fr']);
1313
});
1414
}

pkgs/hooks_runner/test_data/fun_with_flags/hook/link.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ import 'package:hooks/hooks.dart';
99
void main(List<String> args) {
1010
link(args, (input, output) async {
1111
print('Metadata: ${input.metadata}');
12-
final usedFlags = input.metadata.entries
13-
.where((entry) => entry.key.startsWith(prefix))
14-
.expand((e) => e.value as List)
15-
.map((e) => e as String)
12+
final usedFlags = input.fetchUsedCountries
1613
.map((country) => 'package:fun_with_flags/assets/$country.txt')
1714
.toSet();
1815

pkgs/hooks_runner/test_data/fun_with_flags/lib/hook.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
export 'src/hook.dart' show FlagsUsed;
5+
export 'src/hook.dart' show FlagsUsedWrite;

pkgs/hooks_runner/test_data/fun_with_flags/lib/src/hook.dart

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
import 'package:hooks/hooks.dart' show LinkOutputBuilder;
5+
import 'package:hooks/hooks.dart' show LinkInput, LinkOutputBuilder;
66

7-
const prefix = 'used_flags_';
7+
const _prefix = 'used_flags_';
88

9-
extension FlagsUsed on LinkOutputBuilder {
9+
extension FlagsUsedWrite on LinkOutputBuilder {
1010
/// Register a list of flags to be kept from treeshaking.
1111
///
12-
/// This uses the [callerPackageName] with the [prefix] to make a unique
12+
/// This uses the [callerPackageName] with the [_prefix] to make a unique
1313
/// identifier for this list - that's how we avoid overwriting other
1414
/// packages flags.
15-
void registerFlagUse(String callerPackageName, List<String> countries) =>
16-
metadata.add('fun_with_flags', '$prefix$callerPackageName', countries);
15+
void registerCountryUse(String callerPackageName, List<String> countries) =>
16+
metadata.add('fun_with_flags', '$_prefix$callerPackageName', countries);
17+
}
18+
19+
extension FlagsUsedRead on LinkInput {
20+
Iterable<String> get fetchUsedCountries => metadata.entries
21+
.where((entry) => entry.key.startsWith(_prefix))
22+
.expand((e) => e.value as List)
23+
.map((e) => e as String);
1724
}

0 commit comments

Comments
 (0)