Skip to content

refactor(genui): have CatalogItem implement core.ComponentApi#984

Draft
andrewkolos wants to merge 1 commit into
flutter:mainfrom
andrewkolos:genui-catalogitem-componentapi
Draft

refactor(genui): have CatalogItem implement core.ComponentApi#984
andrewkolos wants to merge 1 commit into
flutter:mainfrom
andrewkolos:genui-catalogitem-componentapi

Conversation

@andrewkolos

Copy link
Copy Markdown
Collaborator

Towards #811.

Implements suggestion made in #974 (comment)

CatalogItem now satisfies core.ComponentApi directly, so coreCatalogFor
passes catalog items straight to core.Catalog. Removes the per-item
_CatalogItemComponentApi adapter.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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>.

Suggested change
components: catalog.items.toList(growable: false),
components: catalog.items.cast<core.ComponentApi>().toList(growable: false),

@github-actions

Copy link
Copy Markdown

Package publishing

If you have publishing permissions, you can use the links below to publish the changes after merging this PR.

Package Version Status Publish tag (post-merge)
package:a2ui_core 0.0.1-wip002 ready to publish a2ui_core-v0.0.1-wip002
package:genai_primitives 0.2.4 ready to publish genai_primitives-v0.2.4
package:genui 0.9.2 (error) pubspec version (0.9.2) and changelog (0.10.0) don't agree
package:genui_a2a 0.9.0 (error) pubspec version (0.9.0) and changelog (0.10.0) don't agree
package:json_schema_builder 0.1.5 already published at pub.dev

Documentation at https://github.com/dart-lang/ecosystem/wiki/Publishing-automation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant