@@ -63,7 +63,8 @@ public final class ViewStore<State, Action> {
63
63
#endif
64
64
65
65
private let _send : ( Action ) -> Void
66
- fileprivate let _state : MutableProperty < State >
66
+ private var _state : State
67
+ fileprivate let _stateSubject = Signal < State , Never > . pipe ( )
67
68
private var viewDisposable : Disposable ?
68
69
69
70
/// Initializes a view store from a store.
@@ -76,7 +77,7 @@ public final class ViewStore<State, Action> {
76
77
_ store: Store < State , Action > ,
77
78
removeDuplicates isDuplicate: @escaping ( State , State ) -> Bool
78
79
) {
79
- self . _state = MutableProperty ( store. $state. value)
80
+ self . _state = store. $state. value
80
81
self . _send = store. send
81
82
82
83
self . viewDisposable = store. $state. producer
@@ -88,7 +89,8 @@ public final class ViewStore<State, Action> {
88
89
self . objectWillChange. send ( )
89
90
}
90
91
#endif
91
- self . _state. value = $0
92
+ self . _state = $0
93
+ self . _stateSubject. input. send ( value: $0)
92
94
}
93
95
}
94
96
@@ -99,12 +101,12 @@ public final class ViewStore<State, Action> {
99
101
100
102
/// The current state.
101
103
public var state : State {
102
- self . _state. value
104
+ self . _state
103
105
}
104
106
105
107
/// Returns the resulting value of a given key path.
106
108
public subscript< LocalState> ( dynamicMember keyPath: KeyPath < State , LocalState > ) -> LocalState {
107
- self . _state. value [ keyPath: keyPath]
109
+ self . _state [ keyPath: keyPath]
108
110
}
109
111
110
112
/// Sends an action to the store.
@@ -155,7 +157,7 @@ public final class ViewStore<State, Action> {
155
157
send localStateToViewAction: @escaping ( LocalState ) -> Action
156
158
) -> Binding < LocalState > {
157
159
Binding (
158
- get: { get ( self . _state. value ) } ,
160
+ get: { get ( self . _state) } ,
159
161
set: { newLocalState, transaction in
160
162
if transaction. animation != nil {
161
163
withTransaction ( transaction) {
@@ -295,7 +297,10 @@ public struct StoreProducer<State>: SignalProducerConvertible {
295
297
296
298
fileprivate init < Action> ( viewStore: ViewStore < State , Action > ) {
297
299
self . viewStore = viewStore
298
- self . upstream = viewStore. _state. producer
300
+ self . upstream = Property < State > ( initial: viewStore. state, then: viewStore. _stateSubject. output) . producer
301
+ // .on(completed: { [viewStore = self.viewStore] in
302
+ // _ = viewStore
303
+ // })
299
304
}
300
305
301
306
private init (
0 commit comments