Conversation
There was a problem hiding this comment.
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
AnyMutationstruct for type-erased mutations - Implements
AnyReactorwith 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 | |||
There was a problem hiding this comment.
The filename comment should be 'AnyMutation.swift' to match the actual filename, not 'Mutation.swift'.
| // Mutation.swift | |
| // AnyMutation.swift |
| 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)") |
There was a problem hiding this comment.
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.
| fatalError("Unexpected mutation type: \(type(of: anyMutation)), expected \(Base.Mutation.self)") | |
| fatalError("Unexpected mutation type: \(type(of: anyMutation.enum)), expected \(Base.Mutation.self)") |
Type-erasure now erases
Mutationtype as well as original concreteReactorclass type.