Skip to content

Commit

Permalink
Update to TCA 1.5.6 (#196)
Browse files Browse the repository at this point in the history
* wip

* wip

* wip

* wip

* wip

* wip

* wip

---------

Co-authored-by: Stephen Celis <[email protected]>
  • Loading branch information
mbrandonw and stephencelis authored Jan 10, 2024
1 parent 1013a87 commit 592030a
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 41 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
run: brew link postgresql@15
- name: Start Postgres
run: brew services start postgresql@15
- name: Select Xcode 15.0.1
run: sudo xcode-select -s /Applications/Xcode_15.0.1.app
- name: Select Xcode 15.1
run: sudo xcode-select -s /Applications/Xcode_15.1.app
- name: Bootstrap
run: make bootstrap
- name: Run tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-composable-architecture",
"state" : {
"revision" : "d8f81ca2d43026641c5c60729d01f245ccc32370",
"version" : "1.5.3"
"revision" : "3568f01377c6c668aad40d066acf97ce670a1dad",
"version" : "1.5.6"
}
},
{
Expand Down
4 changes: 2 additions & 2 deletions Bootstrap/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM swift:5.9.1 as build
FROM swift:5.9.2 as build

RUN apt-get --fix-missing update
RUN apt-get install -y cmake libpq-dev libssl-dev libz-dev openssl python
Expand Down Expand Up @@ -26,7 +26,7 @@ RUN swift build \
--product server \
-Xswiftc -g

FROM swift:5.9.1-slim
FROM swift:5.9.2-slim

RUN apt-get --fix-missing update
RUN apt-get install -y libpq-dev libsqlite3-dev libssl-dev libz-dev openssl python
Expand Down
4 changes: 2 additions & 2 deletions Bootstrap/development.dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM swift:5.3 as build
FROM swift:5.9.2 as build

RUN apt-get --fix-missing update
RUN apt-get install -y cmake libpq-dev libssl-dev libz-dev openssl python
Expand Down Expand Up @@ -27,7 +27,7 @@ RUN swift build \
--product server \
-Xswiftc -g

FROM swift:5.3-slim
FROM swift:5.9.2-slim

RUN apt-get --fix-missing update
RUN apt-get install -y libpq-dev libsqlite3-dev libssl-dev libz-dev openssl python
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ run-server-linux:
--build

test-server-linux:
docker run --rm -v "$(PWD):$(PWD)" -w "$(PWD)" swift:5.9.1-focal bash Bootstrap/test.sh
docker run --rm -v "$(PWD):$(PWD)" -w "$(PWD)" swift:5.9.2-focal bash Bootstrap/test.sh

clean-server: clean-db

Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var package = Package(
dependencies: [
.package(url: "https://github.com/apple/swift-crypto", from: "1.1.6"),
.package(url: "https://github.com/pointfreeco/swift-case-paths", from: "1.1.0"),
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", from: "1.5.3"),
.package(url: "https://github.com/pointfreeco/swift-composable-architecture", from: "1.5.6"),
.package(url: "https://github.com/pointfreeco/swift-custom-dump", from: "1.0.0"),
.package(url: "https://github.com/pointfreeco/swift-dependencies", from: "1.1.0"),
.package(url: "https://github.com/pointfreeco/swift-gen", from: "0.3.0"),
Expand Down
14 changes: 6 additions & 8 deletions Sources/CubeCore/CubeFaceNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,13 @@ public class CubeFaceNode: SCNNode {

private var cancellables: Set<AnyCancellable> = []
private let uuid = UUID()
private let viewStore: ViewStore<ViewState, Never>

public init(
letterGeometry: SCNGeometry,
store: Store<ViewState, Never>
viewState viewStatePublisher: StorePublisher<ViewState>
) {
self.viewStore = ViewStore(store, observe: { $0 })
self.side = self.viewStore.cubeFace.side

let viewState = viewStatePublisher.currentValue
self.side = viewState.cubeFace.side
super.init()

let letterNode = SCNNode(geometry: letterGeometry)
Expand All @@ -49,9 +47,9 @@ public class CubeFaceNode: SCNNode {
self.addChildNode(letterNode)

self.category = [.cubeFace, .shadowSurface]
self.name = "Face: \(self.viewStore.cubeFace.side)"
self.name = "Face: \(viewState.cubeFace.side)"

switch self.viewStore.cubeFace.side {
switch viewState.cubeFace.side {
case .top:
self.eulerAngles = SCNVector3(-CGFloat.pi / 2, 0, 0)
self.position = SCNVector3(0, 0.5, 0)
Expand All @@ -62,7 +60,7 @@ public class CubeFaceNode: SCNNode {
self.position = SCNVector3(0.5, 0, 0)
}

self.viewStore.publisher
viewStatePublisher
.sink { [weak self] state in
guard let self = self else { return }
guard state.cubeFace.useCount <= 2 else { return }
Expand Down
21 changes: 10 additions & 11 deletions Sources/CubeCore/CubeNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,33 +65,32 @@ public class CubeNode: SCNNode {
private lazy var shakeAnimationActionKey = "shake animation: \(ObjectIdentifier(self))"
private lazy var removeAnimationActionKey = "remove animation: \(ObjectIdentifier(self))"
private var cancellables: Set<AnyCancellable> = []
private let viewStore: ViewStore<ViewState, Never>

public init(
letterGeometry: SCNGeometry,
store: Store<ViewState, Never>
viewStatePublisher: StorePublisher<ViewState>
) {
self.viewStore = ViewStore(store, observe: { $0 })
let viewState = viewStatePublisher.currentValue

self.index = self.viewStore.index
self.index = viewState.index
self.leftPlaneNode = CubeFaceNode(
letterGeometry: letterGeometry,
store: store.scope(state: \.left, action: \.never)
viewState: viewStatePublisher.left
)
self.rightPlaneNode = CubeFaceNode(
letterGeometry: letterGeometry,
store: store.scope(state: \.right, action: \.never)
viewState: viewStatePublisher.right
)
self.topPlaneNode = CubeFaceNode(
letterGeometry: letterGeometry,
store: store.scope(state: \.top, action: \.never)
viewState: viewStatePublisher.top
)

super.init()

self.isHidden = !self.viewStore.isInPlay
self.isHidden = !viewState.isInPlay
self.name =
"xIndex: \(self.viewStore.index.x), yIndex: \(self.viewStore.index.y), zIndex: \(self.viewStore.index.z)"
"xIndex: \(viewState.index.x), yIndex: \(viewState.index.y), zIndex: \(viewState.index.z)"

for side in CubeFace.Side.allCases {
switch side {
Expand All @@ -104,7 +103,7 @@ public class CubeNode: SCNNode {
}
}

self.viewStore.publisher
viewStatePublisher
.prefix(while: \.isInPlay)
.map { ($0.isCriticallySelected, $0.index, $0.cubeShakeStartedAt) }
.removeDuplicates(by: ==)
Expand All @@ -117,7 +116,7 @@ public class CubeNode: SCNNode {
}
.store(in: &self.cancellables)

self.viewStore.publisher.isInPlay
viewStatePublisher.isInPlay
.dropFirst()
.sink { [weak self] isInPlay in
guard let self = self else { return }
Expand Down
13 changes: 6 additions & 7 deletions Sources/CubeCore/CubeSceneView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ public class CubeSceneView: SCNView, UIGestureRecognizerDelegate {
private let light = SCNLight()
private var motionManager: CMMotionManager?
private var startingAttitude: Attitude?
private let store: Store<ViewState, ViewAction>
private let viewStore: ViewStore<ViewState, ViewAction>
private var worldScale: Float = 1.0

Expand All @@ -91,10 +90,9 @@ public class CubeSceneView: SCNView, UIGestureRecognizerDelegate {

public init(
size: CGSize,
store: Store<ViewState, ViewAction>
viewStore: ViewStore<ViewState, ViewAction>
) {
self.store = store
self.viewStore = ViewStore(self.store, observe: { $0 })
self.viewStore = viewStore

super.init(frame: .zero, options: nil)

Expand Down Expand Up @@ -134,10 +132,11 @@ public class CubeSceneView: SCNView, UIGestureRecognizerDelegate {

self.gameCubeNode.childNodes.forEach { $0.removeFromParentNode() }


LatticePoint.cubeIndices.forEach { index in
let cube = CubeNode(
letterGeometry: letterGeometry,
store: store.scope(state: \.cubes[index], action: \.never)
viewStatePublisher: self.viewStore.publisher.cubes[index]
)
cube.scale = SCNVector3(x: 1 / 3, y: 1 / 3, z: 1 / 3)
self.gameCubeNode.addChildNode(cube)
Expand All @@ -148,14 +147,14 @@ public class CubeSceneView: SCNView, UIGestureRecognizerDelegate {
[CubeFaceNode.ViewState.Status.selected, .selectable].forEach { status in
let warmer = CubeFaceNode(
letterGeometry: letterGeometry,
store: Store(
viewState: Store<CubeFaceNode.ViewState, Never>(
initialState: .init(
cubeFace: .init(letter: "A", side: .top),
letterIsHidden: true,
status: status
)
) {
}
}.publisher
)
warmer.position = .init(-1, -1, -1)
warmer.scale = .init(0.001, 0.001, 0.001)
Expand Down
10 changes: 5 additions & 5 deletions Sources/CubeCore/CubeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import ComposableArchitecture
import SwiftUI

public struct CubeView: View {
public let store: Store<CubeSceneView.ViewState, CubeSceneView.ViewAction>
public let viewStore: ViewStore<CubeSceneView.ViewState, CubeSceneView.ViewAction>

public init(store: Store<CubeSceneView.ViewState, CubeSceneView.ViewAction>) {
self.store = store
self.viewStore = ViewStore(store, observe: { $0 })
}

public var body: some View {
GeometryReader { geometry in
CubeRepresentable(size: geometry.size, store: self.store)
CubeRepresentable(size: geometry.size, viewStore: self.viewStore)
}
}
}
Expand All @@ -20,10 +20,10 @@ private struct CubeRepresentable: UIViewRepresentable {
@AppStorage(.showSceneStatistics) var showSceneStatistics

let size: CGSize
let store: Store<CubeSceneView.ViewState, CubeSceneView.ViewAction>
let viewStore: ViewStore<CubeSceneView.ViewState, CubeSceneView.ViewAction>

func makeUIView(context: Context) -> CubeSceneView {
CubeSceneView(size: self.size, store: self.store)
CubeSceneView(size: self.size, viewStore: self.viewStore)
}

func updateUIView(_ sceneView: CubeSceneView, context: Context) {
Expand Down
10 changes: 10 additions & 0 deletions Sources/CubeCore/StorePublisherHelpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ComposableArchitecture

extension StorePublisher {
var currentValue: State {
var state: State!
let cancellable = self.sink { state = $0 }
defer { _ = cancellable }
return state
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class LeaderboardTests: XCTestCase {
throw SomeError()
})
}
store.exhaustivity = .off

await store.send(.task) {
$0.isLoading = true
Expand Down

0 comments on commit 592030a

Please sign in to comment.