refactor(genui): have CatalogItem implement core.ComponentApi#984
refactor(genui): have CatalogItem implement core.ComponentApi#984andrewkolos wants to merge 1 commit into
Conversation
CatalogItem now satisfies core.ComponentApi directly, so coreCatalogFor passes catalog items straight to core.Catalog. Removes the per-item _CatalogItemComponentApi adapter.
There was a problem hiding this comment.
Code Review
This pull request simplifies the codebase by having CatalogItem directly implement core.ComponentApi instead of using an intermediate wrapper class (_CatalogItemComponentApi). This allows coreCatalogFor to directly map catalog.items to the components list. A test was also added to verify this implementation. The reviewer suggested explicitly casting the list of items to core.ComponentApi to prevent potential runtime type errors due to covariance.
| components: catalog.items | ||
| .map<core.ComponentApi>(_CatalogItemComponentApi.new) | ||
| .toList(growable: false), | ||
| components: catalog.items.toList(growable: false), |
There was a problem hiding this comment.
While List<CatalogItem> is covariant and can be assigned to List<core.ComponentApi>, it is safer and more idiomatic to explicitly cast the iterable to ensure the runtime type of the list matches the expected List<core.ComponentApi>. This prevents potential runtime type errors if the receiving class performs operations that expect a List<core.ComponentApi> rather than a List<CatalogItem>.
| components: catalog.items.toList(growable: false), | |
| components: catalog.items.cast<core.ComponentApi>().toList(growable: false), |
Package publishingIf you have publishing permissions, you can use the links below to publish the changes after merging this PR.
Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation. |
Towards #811.
Implements suggestion made in #974 (comment)