Skip to content

Commit 21f7c3d

Browse files
authored
[native_assets_cli] Cleanup List from API (#1342)
Use `Iterable` over `List` in the public API: * Immediately assigning lists into our own fields is dangerous, users might modify the list later instead of using methods on the API. * Only giving `Iterable`s to users prevents us having to copy the list on returning a list. (Or we'd risk users modifying the internal list). For `Map` we don't really have a different API type to signify this difference unfortunately. What we do in most of the API is: * Have an `add(param1, param2)` method instead of using an `addAll(Map)`. * Have a `lookupParam2(param1)` method instead of exposing a `Map`. * But our constructors often still take maps, and we need to ensure we do a copyAll/addAll on those entries.
1 parent 3bc5454 commit 21f7c3d

File tree

4 files changed

+8
-6
lines changed

4 files changed

+8
-6
lines changed

pkgs/native_assets_cli/lib/src/api/build_output.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ abstract final class BuildOutput {
6161
///
6262
/// In dry runs, the assets for all [Architecture]s for the [OS] specified in
6363
/// the dry run must be provided.
64-
Map<String, List<Asset>> get assetsForLinking;
64+
Map<String, Iterable<Asset>> get assetsForLinking;
6565

6666
/// The files used by this build.
6767
///

pkgs/native_assets_cli/lib/src/api/link_config.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ abstract class LinkConfig implements HookConfig {
4646
int? targetMacOSVersion,
4747
CCompilerConfig? cCompiler,
4848
BuildMode? buildMode,
49-
List<String>? supportedAssetTypes,
49+
Iterable<String>? supportedAssetTypes,
5050
int? targetAndroidNdkApi,
5151
required Iterable<Asset> assets,
5252
required LinkModePreference linkModePreference,
@@ -77,7 +77,7 @@ abstract class LinkConfig implements HookConfig {
7777
required String packageName,
7878
required Uri packageRoot,
7979
required OS targetOS,
80-
List<String>? supportedAssetTypes,
80+
Iterable<String>? supportedAssetTypes,
8181
required Iterable<Asset> assets,
8282
required LinkModePreference linkModePreference,
8383
Version? version,

pkgs/native_assets_cli/lib/src/api/link_output.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ abstract final class LinkOutput {
5454
void addAssets(Iterable<Asset> assets);
5555

5656
factory LinkOutput({
57-
List<AssetImpl>? assets,
57+
Iterable<AssetImpl>? assets,
5858
Dependencies? dependencies,
5959
DateTime? timestamp,
6060
}) =>

pkgs/native_assets_cli/lib/src/model/hook_output.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ final class HookOutputImpl implements BuildOutput, LinkOutput {
2929

3030
HookOutputImpl({
3131
DateTime? timestamp,
32-
List<AssetImpl>? assets,
32+
Iterable<AssetImpl>? assets,
3333
Map<String, List<AssetImpl>>? assetsForLinking,
3434
Dependencies? dependencies,
3535
Metadata? metadata,
3636
}) : timestamp = (timestamp ?? DateTime.now()).roundDownToSeconds(),
37-
_assets = assets ?? [],
37+
_assets = [
38+
...?assets,
39+
],
3840
_assetsForLinking = assetsForLinking ?? {},
3941
// ignore: prefer_const_constructors
4042
_dependencies = dependencies ?? Dependencies([]),

0 commit comments

Comments
 (0)