@@ -61,6 +61,11 @@ public final class ViewStore<State, Action>: ObservableObject {
6161 // won't be synthesized automatically. To work around issues on iOS 13 we explicitly declare it.
6262 public private( set) lazy var objectWillChange = ObservableObjectPublisher ( )
6363
64+ /// The current state.
65+ public var state : State { self . store. state. value }
66+
67+ private let store : Store < State , Action >
68+
6469 /// Initializes a view store from a store.
6570 ///
6671 /// - Parameters:
@@ -72,20 +77,13 @@ public final class ViewStore<State, Action>: ObservableObject {
7277 removeDuplicates isDuplicate: @escaping ( State , State ) -> Bool
7378 ) {
7479 self . publisher = StorePublisher ( store. state, removeDuplicates: isDuplicate)
75- self . _state = { store. state. value }
76- self . _send = store. send
80+ self . store = store
7781 self . viewCancellable = store. state
7882 . dropFirst ( )
7983 . removeDuplicates ( by: isDuplicate)
8084 . sink { [ weak self] _ in self ? . objectWillChange. send ( ) }
8185 }
8286
83- let _state : ( ) -> State
84- let _send : ( Action ) -> Void
85-
86- /// The current state.
87- public var state : State { _state ( ) }
88-
8987 /// Returns the resulting value of a given key path.
9088 public subscript< LocalState> ( dynamicMember keyPath: KeyPath < State , LocalState > ) -> LocalState {
9189 self . state [ keyPath: keyPath]
@@ -101,7 +99,7 @@ public final class ViewStore<State, Action>: ObservableObject {
10199 ///
102100 /// - Parameter action: An action.
103101 public func send( _ action: Action ) {
104- self . _send ( action)
102+ self . store . send ( action)
105103 }
106104
107105 /// Derives a binding from the store that prevents direct writes to state and instead sends
0 commit comments