@@ -19,7 +19,7 @@ import SwiftUI
1919
2020// MARK: - Reactor protocol
2121
22- @MainActor @dynamicMemberLookup public protocol Reactor : AnyObject , Identifiable , Hashable {
22+ @MainActor @dynamicMemberLookup public protocol Reactor : AnyObject , Identifiable {
2323
2424 /// Internal events
2525 ///
@@ -229,6 +229,30 @@ public extension Reactor {
229229
230230}
231231
232+ // MARK: - Directly writable types
233+
234+ public extension Reactor {
235+
236+ /// Opt-in writable accessor for value type paths (structs)
237+ subscript< T: __ReactorDirectWriteable > ( dynamicMember keyPath: WritableKeyPath < State , T > ) -> T {
238+ get {
239+ state [ keyPath: keyPath]
240+ }
241+ set {
242+ var s = state
243+ s [ keyPath: keyPath] = newValue
244+ state = s
245+ }
246+ }
247+
248+ /// Opt-in writable accessor for reference type paths (class members)
249+ subscript< T: __ReactorDirectWriteable > ( dynamicMember keyPath: ReferenceWritableKeyPath < State , T > ) -> T {
250+ get { state [ keyPath: keyPath] }
251+ set { state [ keyPath: keyPath] = newValue }
252+ }
253+
254+ }
255+
232256// MARK: - Default implementation
233257
234258public extension Reactor {
@@ -477,7 +501,7 @@ public extension Reactor {
477501 let mutation = await map ( value)
478502 let event = Event ( kind: . mutation( mutation) )
479503
480- guard let self else { return }
504+ guard let self else { break }
481505 _send ( event: event)
482506 }
483507
0 commit comments