Skip to content

Rename internal SurfaceRegistry events to resolve name clashes in package exports #901

@yjbanov

Description

@yjbanov

Context

Currently in genui.dart:L16-17, we have to hide two classes in our exports due to name clashes:

export 'src/engine.dart' hide SurfaceAdded, SurfaceRemoved;

The classes are defined in two places:

  1. SurfaceUpdate events (Public UI-level updates for facades/consumers):
    • Location: ui_models.dart:L402-438
    • Classes: SurfaceAdded, ComponentsUpdated, and SurfaceRemoved (subclasses of SurfaceUpdate).
  2. RegistryEvent events (Internal engine-level registry updates):

Proposed Solution

To make the API clean, robust, and unambiguous without needing hide clauses, we should prefix the event classes in surface_registry.dart to associate them explicitly with the registry.

1. Rename classes

In surface_registry.dart:

  • RegistryEvent $\rightarrow$ SurfaceRegistryEvent
  • SurfaceAdded $\rightarrow$ SurfaceRegistryAdded
  • SurfaceRemoved $\rightarrow$ SurfaceRegistryRemoved
  • SurfaceUpdated $\rightarrow$ SurfaceRegistryUpdated

2. Update surface controller

In surface_controller.dart
Update the mapping logic in surfaceUpdates (around L57-67) to match the new class names:

  @override
  Stream<SurfaceUpdate> get surfaceUpdates => _registry.events.map(
    (e) => switch (e) {
      surface_reg.SurfaceRegistryAdded(:final surfaceId, :final definition) =>
        SurfaceAdded(surfaceId, definition),
      surface_reg.SurfaceRegistryUpdated(:final surfaceId, :final definition) =>
        ComponentsUpdated(surfaceId, definition),
      surface_reg.SurfaceRegistryRemoved(:final surfaceId) => 
        SurfaceRemoved(surfaceId),
    },
  );

Benefits

  • Cleaner Exports: No need to hide classes in the main package entrypoint.
  • Unambiguous Code: Developers importing internal libraries or both files directly won't run into naming collisions.
  • Stronger Semantics: Clearly distinguishes between engine-internal registry state events (SurfaceRegistryAdded) and public UI-level state events (SurfaceAdded).

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2An issue we'd like to fix eventually, but it's not being actively worked on.front-line-handledCan wait until the second-line triage. The front-line triage already checked if it's a P0.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions