diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3270b1d59948..0dfc81c50655 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,10 +15,8 @@ jobs: matrix: xcode: - 11.3 - - 11.4 - - 11.5 - 11.6 - #- 12_beta + - 12_beta steps: - uses: actions/checkout@v2 - name: Select Xcode ${{ matrix.xcode }} diff --git a/Sources/ComposableArchitecture/Store.swift b/Sources/ComposableArchitecture/Store.swift index b6950391ce1f..5b5e44ff7e2b 100644 --- a/Sources/ComposableArchitecture/Store.swift +++ b/Sources/ComposableArchitecture/Store.swift @@ -7,7 +7,7 @@ import Foundation /// You will typically construct a single one of these at the root of your application, and then use /// the `scope` method to derive more focused stores that can be passed to subviews. public final class Store { - @Published private(set) var state: State + var state: CurrentValueSubject var effectCancellables: [UUID: AnyCancellable] = [:] private var isSending = false private var parentCancellable: AnyCancellable? @@ -60,15 +60,15 @@ public final class Store { action fromLocalAction: @escaping (LocalAction) -> Action ) -> Store { let localStore = Store( - initialState: toLocalState(self.state), + initialState: toLocalState(self.state.value), reducer: { localState, localAction in self.send(fromLocalAction(localAction)) - localState = toLocalState(self.state) + localState = toLocalState(self.state.value) return .none } ) - localStore.parentCancellable = self.$state - .sink { [weak localStore] newValue in localStore?.state = toLocalState(newValue) } + localStore.parentCancellable = self.state + .sink { [weak localStore] newValue in localStore?.state.value = toLocalState(newValue) } return localStore } @@ -102,20 +102,20 @@ public final class Store { return localState } - return toLocalState(self.$state.eraseToAnyPublisher()) + return toLocalState(self.state.eraseToAnyPublisher()) .map { localState in let localStore = Store( initialState: localState, reducer: { localState, localAction in self.send(fromLocalAction(localAction)) - localState = extractLocalState(self.state) ?? localState + localState = extractLocalState(self.state.value) ?? localState return .none }) - localStore.parentCancellable = self.$state + localStore.parentCancellable = self.state .sink { [weak localStore] state in guard let localStore = localStore else { return } - localStore.state = extractLocalState(state) ?? localStore.state + localStore.state.value = extractLocalState(state) ?? localStore.state.value } return localStore } @@ -163,7 +163,7 @@ public final class Store { ) } self.isSending = true - let effect = self.reducer(&self.state, action) + let effect = self.reducer(&self.state.value, action) self.isSending = false var didComplete = false @@ -207,7 +207,7 @@ public final class Store { reducer: @escaping (inout State, Action) -> Effect ) { self.reducer = reducer - self.state = initialState + self.state = CurrentValueSubject(initialState) } } diff --git a/Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift b/Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift index 4ac399e6e125..912a914da457 100644 --- a/Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift +++ b/Sources/ComposableArchitecture/UIKit/IfLetUIKit.swift @@ -52,7 +52,7 @@ extension Store { } ) .sink { store in - if store.state == nil { `else`() } + if store.state.value == nil { `else`() } } let unwrapCancellable = diff --git a/Sources/ComposableArchitecture/ViewStore.swift b/Sources/ComposableArchitecture/ViewStore.swift index 802dfe939510..811c7d28745a 100644 --- a/Sources/ComposableArchitecture/ViewStore.swift +++ b/Sources/ComposableArchitecture/ViewStore.swift @@ -58,9 +58,9 @@ public final class ViewStore: ObservableObject { _ store: Store, removeDuplicates isDuplicate: @escaping (State, State) -> Bool ) { - let publisher = store.$state.removeDuplicates(by: isDuplicate) + let publisher = store.state.removeDuplicates(by: isDuplicate) self.publisher = StorePublisher(publisher) - self.state = store.state + self.state = store.state.value self._send = store.send self.viewCancellable = publisher.sink { [weak self] in self?.state = $0 } } diff --git a/Tests/ComposableArchitectureTests/StoreTests.swift b/Tests/ComposableArchitectureTests/StoreTests.swift index f4e24bc96217..1690d82cfd3e 100644 --- a/Tests/ComposableArchitectureTests/StoreTests.swift +++ b/Tests/ComposableArchitectureTests/StoreTests.swift @@ -57,7 +57,7 @@ final class StoreTests: XCTestCase { let childStore = parentStore.scope(state: String.init) var values: [String] = [] - childStore.$state + childStore.state .sink(receiveValue: { values.append($0) }) .store(in: &self.cancellables) @@ -79,7 +79,7 @@ final class StoreTests: XCTestCase { let childViewStore = ViewStore(childStore) var values: [Int] = [] - parentStore.$state + parentStore.state .sink(receiveValue: { values.append($0) }) .store(in: &self.cancellables) @@ -102,7 +102,7 @@ final class StoreTests: XCTestCase { parentStore .scope(state: { $0.map { "\($0)" }.removeDuplicates() }) .sink { childStore in - childStore.$state + childStore.state .sink { outputs.append($0) } .store(in: &self.cancellables) } @@ -246,7 +246,7 @@ final class StoreTests: XCTestCase { parentStore .scope { $0.removeDuplicates() } - .sink { outputs.append($0.state) } + .sink { outputs.append($0.state.value) } .store(in: &self.cancellables) XCTAssertEqual(outputs, [0]) @@ -285,7 +285,7 @@ final class StoreTests: XCTestCase { .ifLet( then: { store in stores.append(store) - outputs.append(store.state) + outputs.append(store.state.value) }, else: { outputs.append(nil)