Skip to content

"Meet the Composable Architecture" tutorial #2107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 25 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ day-to-day when building applications, such as:

### Essentials

- <doc:MeetComposableArchitecture>
- <doc:GettingStarted>
- <doc:DependencyManagement>
- <doc:Testing>
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import ComposableArchitecture
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import ComposableArchitecture

struct CounterFeature: ReducerProtocol {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ComposableArchitecture

struct CounterFeature: ReducerProtocol {
struct State {

}

enum Action {

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import ComposableArchitecture

struct CounterFeature: ReducerProtocol {
struct State {
var count = 0
}

enum Action {
case decrementButtonTapped
case incrementButtonTapped
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import ComposableArchitecture

struct CounterFeature: ReducerProtocol {
struct State {
var count = 0
}

enum Action {
case decrementButtonTapped
case incrementButtonTapped
}

func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
switch action {
case .decrementButtonTapped:

case .incrementButtonTapped:

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import ComposableArchitecture

struct CounterFeature: ReducerProtocol {
struct State {
var count = 0
}

enum Action {
case decrementButtonTapped
case incrementButtonTapped
}

func reduce(into state: inout State, action: Action) -> EffectTask<Action> {
switch action {
case .decrementButtonTapped:
state.count -= 1
return .none

case .incrementButtonTapped:
state.count += 1
return .none
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import ComposableArchitecture
import SwiftUI

struct CounterView: View {
var body: some View {
EmptyView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
struct CounterView: View {
let store: StoreOf<CounterFeature>

var body: some View {
EmptyView()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
struct CounterView: View {
let store: StoreOf<CounterFeature>

var body: some View {
VStack {
Text("0")
.font(.largeTitle)
.padding()
.background(Color.black.opacity(0.1))
.cornerRadius(10)
HStack {
Button("-") {
}
.font(.largeTitle)
.padding()
.background(Color.black.opacity(0.1))
.cornerRadius(10)

Button("+") {
}
.font(.largeTitle)
.padding()
.background(Color.black.opacity(0.1))
.cornerRadius(10)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
struct CounterView: View {
let store: StoreOf<CounterFeature>

var body: some View {
VStack {
Text("0")
.font(.largeTitle)
.padding()
.background(Color.black.opacity(0.1))
.cornerRadius(10)
HStack {
Button("-") {
}
.font(.largeTitle)
.padding()
.background(Color.black.opacity(0.1))
.cornerRadius(10)

Button("+") {
}
.font(.largeTitle)
.padding()
.background(Color.black.opacity(0.1))
.cornerRadius(10)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
extension CounterFeature.State: Equatable {}

struct CounterView: View {
let store: StoreOf<CounterFeature>

var body: some View {
WithViewStore(self.store, observe: { $0 }) { viewStore in
VStack {
Text("\(viewStore.count)")
.font(.largeTitle)
.padding()
.background(Color.black.opacity(0.1))
.cornerRadius(10)
HStack {
Button("-") {
viewStore.send(.decrementButtonTapped)
}
.font(.largeTitle)
.padding()
.background(Color.black.opacity(0.1))
.cornerRadius(10)

Button("+") {
viewStore.send(.incrementButtonTapped)
}
.font(.largeTitle)
.padding()
.background(Color.black.opacity(0.1))
.cornerRadius(10)
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
struct CounterPreview: PreviewProvider {
static var previews: some View {
CounterView(
store: Store(initialState: CounterFeature.State()) {
CounterFeature()
}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
struct CounterPreview: PreviewProvider {
static var previews: some View {
CounterView(
store: Store(initialState: CounterFeature.State()) {
// CounterFeature()
}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import SwiftUI

@main
struct TCATestApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import ComposableArchitecture
import SwiftUI

@main
struct TCATestApp: App {
var body: some Scene {
WindowGroup {
CounterView(
store: Store(initialState: CounterFeature.State()) {
CounterFeature()
}
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import ComposableArchitecture
import SwiftUI

@main
struct TCATestApp: App {
static let store = Store(initialState: CounterFeature.State()) {
CounterFeature()
}

var body: some Scene {
WindowGroup {
CounterView(store: store)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import ComposableArchitecture
import SwiftUI

@main
struct TCATestApp: App {
static let store = Store(initialState: CounterFeature.State()) {
CounterFeature()
._printChanges()
}

var body: some Scene {
WindowGroup {
CounterView(store: store)
}
}
}
Loading