Skip to content

Conversation

@plajdo
Copy link
Contributor

@plajdo plajdo commented Oct 1, 2025

Type-erasure now erases Mutation type as well as original concrete Reactor class type.

@plajdo plajdo requested a review from MatusMistrik October 1, 2025 12:30
@plajdo plajdo self-assigned this Oct 1, 2025
@plajdo plajdo added the enhancement New feature or request label Oct 1, 2025
@andrej-jasso andrej-jasso requested a review from Copilot October 2, 2025 11:16
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements type-erased mutations in the GoodReactor framework by introducing an AnyReactor wrapper that erases both the concrete Reactor type and its Mutation type. This allows views to work with different reactor implementations that share the same action/state interface but have different internal mutation types.

  • Introduces AnyMutation struct for type-erased mutations
  • Implements AnyReactor with dynamic member lookup for state access
  • Adds comprehensive test coverage for the new type-erased functionality

Reviewed Changes

Copilot reviewed 12 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
Tests/GoodReactorTests/GoodReactorTests.swift Updates test assertions to use direct property access instead of .state property
Tests/GoodReactorTests/AnyReactorTests.swift New comprehensive test suite for AnyReactor functionality
Sources/GoodReactor/Utils/EventTaskCounter.swift Extracts EventTaskCounter into separate file, removes unrelated Event code
Sources/GoodReactor/Core/Reactor.swift Removes deprecated currentState property
Sources/GoodReactor/Core/Identifier.swift Moves EventIdentifier to Event.swift file
Sources/GoodReactor/Core/Event.swift New file containing Event class and type-erasure utilities
Sources/GoodReactor/Core/Erased/AnyReactorBoxProtocol.swift Protocol defining interface for type-erased reactor boxes
Sources/GoodReactor/Core/Erased/AnyReactorBox.swift Implementation of reactor box that forwards calls to concrete reactor
Sources/GoodReactor/Core/Erased/AnyReactor.swift Main AnyReactor class with dynamic member lookup and type erasure
Sources/GoodReactor/Core/Erased/AnyMutation.swift Type-erased mutation wrapper
Sources/GoodReactor/AnyReactor.swift Removes old AnyReactor implementation
README.md Updates test coverage percentage from 69% to 83%

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@@ -0,0 +1,20 @@
//
// Mutation.swift
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

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

The filename comment should be 'AnyMutation.swift' to match the actual filename, not 'Mutation.swift'.

Suggested change
// Mutation.swift
// AnyMutation.swift

Copilot uses AI. Check for mistakes.
func reduceAny(state: inout Base.State, event: Event<Base.Action, AnyMutation, Base.Destination>) {
let concreteEvent = event.castMutation { anyMutation in
guard let concreteMutation = anyMutation.as(Base.Mutation.self) else {
fatalError("Unexpected mutation type: \(type(of: anyMutation)), expected \(Base.Mutation.self)")
Copy link

Copilot AI Oct 2, 2025

Choose a reason for hiding this comment

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

The error message refers to type(of: anyMutation) which will show the type of AnyMutation rather than the actual underlying mutation type. Consider using type(of: anyMutation.enum) to show the concrete mutation type that failed to cast.

Suggested change
fatalError("Unexpected mutation type: \(type(of: anyMutation)), expected \(Base.Mutation.self)")
fatalError("Unexpected mutation type: \(type(of: anyMutation.enum)), expected \(Base.Mutation.self)")

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants