Skip to content

Conversation

@TimPurdum
Copy link
Collaborator

Summary

This PR refactors the LogicComponent base class and its subclasses to use the new JsSyncManager infrastructure. It is a stacked PR that builds on top of #495 (protobuf implementation) and should be merged after that PR is completed.

Depends on: #495 (Implement protobuf serialization and component updates)

Related Pro PR: https://github.com/dymaptic/GeoBlazor.Pro/pull/220 - These PRs should be reviewed together as they contain coordinated changes across both repositories.

What's Included

LogicComponent Refactoring

  • LogicComponent.cs - Major refactoring:
    • New primary constructor with IAppValidator, IJSRuntime, JsModuleManager, AuthenticationManager
    • Removed IDisposable pattern in favor of managed lifecycle
    • New InvokeAsync<T> and InvokeVoidAsync methods using JsSyncManager extension methods
    • Added [CallerMemberName] for automatic method name resolution
    • Added IsServer property for runtime detection

JsModuleManager Updates

  • Added GetLogicComponent method to retrieve/create JavaScript wrappers for logic components
  • Added GetProLogicComponent method for Pro components

StringExtensions

  • Added ToUpperFirstChar extension method (mirrors existing ToLowerFirstChar)

GeometryEngine Updates

  • Updated constructor to use new LogicComponent signature
  • Updated all InvokeAsync calls to use new signature with className and parameters: array
  • Added [SerializedMethod] attributes for protobuf serialization support

ProjectionEngine Updates

  • Updated constructor to use new LogicComponent signature
  • Updated all method calls to use new pattern
  • Added [SerializedMethod] attributes

LocationService Updates

  • Updated constructor to use new LogicComponent signature
  • Updated all method calls to use new pattern
  • Added [SerializedMethod] attributes

TypeScript Updates

  • geoBlazorCore.ts - Added wrapper getter functions for logic components
  • geometryEngine.ts - Updated wrapper implementation
  • projectionEngine.ts - Renamed from projection.ts, updated wrapper
  • locationService.ts - Updated wrapper implementation
  • geometry.ts, polygon.ts, polyline.ts - Geometry serialization updates

Test Updates

  • GeometryEngineTests.cs - Additional comprehensive tests (~161 lines)

Breaking Changes

  • Constructor signature changed for all LogicComponents (GeometryEngine, ProjectionEngine, LocationService)
  • DI registration automatically handles these via AddGeoBlazor() extension method
  • Existing code using these components via DI will continue to work unchanged

Key Pattern Changes

Before:

public class GeometryEngine : LogicComponent
{
    public GeometryEngine(AuthenticationManager authManager) : base(authManager) { }
    
    public async Task<Polygon[]> Buffer(...)
    {
        return await InvokeAsync<Polygon[]>("buffer", geometries, distances);
    }
}

After:

public class GeometryEngine : LogicComponent
{
    public GeometryEngine(IAppValidator appValidator, IJSRuntime jsRuntime, 
        JsModuleManager jsModuleManager, AuthenticationManager authManager) 
        : base(appValidator, jsRuntime, jsModuleManager, authManager) { }
    
    [SerializedMethod]
    public async Task<Polygon[]> Buffer(...)
    {
        return await InvokeAsync<Polygon[]>(nameof(GeometryEngine), parameters: [geometries, distances]);
    }
}

Relationship to PR Series

This PR is part of a planned series to merge changes from feature/478-multipart-operator incrementally (see BRANCH_DIVERGENCE_ANALYSIS.md):

  1. PR Add protobuf serialization infrastructure #493: Protobuf Infrastructure ← Must be merged first
  2. PR Implement protobuf serialization and component updates #495: Protobuf Implementation ← Must be merged second
  3. This PR: LogicComponent Refactoring ← Current
  4. GeometryEngine Enhancements (future - PR 3)
  5. Additional feature PRs...

Statistics

  • 17 files changed
  • ~710 lines added
  • ~436 lines removed

Test Plan

  • Verified Core project builds successfully
  • Ran existing unit tests
  • Added new GeometryEngine tests
  • Verify logic components work correctly in Blazor Server
  • Verify logic components work correctly in WebAssembly

🤖 Generated with Claude Code

TimPurdum and others added 13 commits December 9, 2025 16:54
- Add protobuf-net package for binary serialization support
- Add ProtobufSerializationBase.cs with base records for serialization
- Add IProtobufSerializable interface for type contracts
- Add ProtobufSerializableAttribute and SerializedMethodAttribute
- Add JsSyncManager stub for JS interop with protobuf support
- Add ProtobufSourceGenerator skeleton for future serialization code generation
- Update ESBuildGenerator to use new shared project structure
- Add SourceGenerator.Shared project with ProcessHelper and extension methods
- Update Directory.Build.props with CoreProjectPath for source generators

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add TODO comments to placeholder implementations (SerializationExtensions,
  JsSyncManager, ProtobufSourceGenerator) documenting future work
- Document ProtoMember(1000) magic number - reserved for base class properties
  to avoid conflicts with derived class tags (1-999)
- Improve GeoBlazorMetaData exception handling - catch FileNotFoundException
  specifically instead of bare catch
- Add XML documentation to GeoBlazorMetaData class and properties
- Fix duplicate logging bug in ProcessHelper - output was being logged in
  ExitedCommandEvent then cleared, making error diagnostics empty

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

2 participants