Skip to content

Commit f75f938

Browse files
stephencelismbrandonwscogeokabiroberai
authored
@Reducer macro enhancements (#2795)
* updated binding docs * adding docs * clean up * wip * wip * wip * clean up * clean up * clean up * wip; * lots of fixes * update more docs * fix * wip * wip * Remove ObservationRegistrarWrapper. (#2634) * Remove ObservationRegistrarWrapper. * Delete Sources/ComposableArchitecture/Internal/ObservationRegistrarWrapper.swift --------- Co-authored-by: Stephen Celis <[email protected]> * more docs * update docs * a few more tests * fix * wip * wip * wip * Cache data in store collections (#2635) * fix tutorial highlighting * wip * wip * wip * wip * tests for observation of special domain types * another test * fix * wip * Implement memoization for perception checks (#2630) * Implement memoization for isInSwiftUIBody * tidy up * Perception caching updates (#2649) * Small updates to perception caching. * wip * debug * some more macro tests * syncups tutorial beginnings * wip * wip * wip * wip * wip * merge fixes * wip * update tests * fix * fix * fix perception checking in store * rename task local * delete old test * deprecate test using old apis * fix test * perception tests for store * wip * wip * wip * wip * wip * wip * wip * Opt out of key path for Store.ifLet * sync ups * lots more sync up tutorial * more sync ups tutorial * wip * wip * wio * wip * wip * wip * updated references of 1.6 to 1.7 * wip * no need to force unwrap here * fixed crash in ForEach with bindings * more sync ups tutorial * more sync ups tutorial * wip * more sync ups * wip * wip * Better support for observing copies of values (#2650) * Explore using _modify * wip * wip * wip * wip * wip * wip * more tests * wip * get another failing test for an edge case * wip * tests all passing * flag for determining when new state was created * wip * clean up * wip * wip * wip; * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * New test that currently fails. * wip * wip * Update Sources/ComposableArchitectureMacros/PresentsMacro.swift * wip * remove redundant attached member attribute * storage * cleanup * more benchmarks and tests * wip * wip * wip * wip * update tests * wip * wip --------- Co-authored-by: Brandon Williams <[email protected]> * wip * wip * wip * swift-format * fix * wip * wip * wip * wip * Perception * wip * wip * clean up shared state * fix shared state tests * wip * add alert test * wip * wip * wip * wip * Use transaction in binding * wip * wip * wip * wip * wip * wip * uikit * keep references to controllers when presenting so that we can properly dismiss * change order of features in shared state demo * wip * cleanup * cleanup * wip * wip * wip * Fix perception checking for effect actions. * wip * wip * wip * Fix perception checking for effect actions. * wip * wip * remove sync ups tutorial * wip * wip * wip * wip * wip * wip * wip * wip * wip * @Reducer macro will insert protocol requirements if missing * wip * fixes * fix * wip * wip * wip * docs for observe function for uikit * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Add cancellation to observation' * re-record integration test snapshots * fixed some todos * update test * remove 5.9.2 checks * wip * wip * improve docs * update docs * updates * lots of fixes * more docs * remove unneeded file; * wip * wip * wip * update readme and getting started * wip * wip * simplify * migration stuff * wip * Update Models.swift * wip * wip * wip * Update Bindings.md * wip * wip * wip * wip * fix * wip * wip * wip * wip * wip Co-authored-by: Kabir Oberai <[email protected]> * lots of docs and some fixes * more docs * more docs * wip * upate integration tests to use enum destination macro * re-org migration guide * wip * wip * docs for other enum reducer macros * update ephemeral state docs * wip * move docs for reducer protocol and macro into single article * mention observable state * wip * updated docs and some macro tests * wip * wip * cleanup * wip * wip * wip * revert 16 * wip * clean up * Revert "clean up" This reverts commit 49e7308. * Availability fixes * comment out tests crashing the compiler * wip * fix ttt tests * wip --------- Co-authored-by: Brandon Williams <[email protected]> Co-authored-by: Brandon Williams <[email protected]> Co-authored-by: George Scott <[email protected]> Co-authored-by: Kabir Oberai <[email protected]>
1 parent 08c7c6b commit f75f938

File tree

62 files changed

+2715
-1448
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+2715
-1448
lines changed

Examples/CaseStudies/SwiftUICaseStudies/03-Navigation-Multiple-Destinations.swift

+6-29
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,11 @@ private let readMe = """
88

99
@Reducer
1010
struct MultipleDestinations {
11-
@Reducer
12-
public struct Destination {
13-
@ObservableState
14-
public enum State: Equatable {
15-
case drillDown(Counter.State)
16-
case popover(Counter.State)
17-
case sheet(Counter.State)
18-
}
19-
20-
public enum Action {
21-
case drillDown(Counter.Action)
22-
case popover(Counter.Action)
23-
case sheet(Counter.Action)
24-
}
25-
26-
public var body: some Reducer<State, Action> {
27-
Scope(state: \.drillDown, action: \.drillDown) {
28-
Counter()
29-
}
30-
Scope(state: \.sheet, action: \.sheet) {
31-
Counter()
32-
}
33-
Scope(state: \.popover, action: \.popover) {
34-
Counter()
35-
}
36-
}
11+
@Reducer(state: .equatable)
12+
enum Destination {
13+
case drillDown(Counter)
14+
case popover(Counter)
15+
case sheet(Counter)
3716
}
3817

3918
@ObservableState
@@ -64,9 +43,7 @@ struct MultipleDestinations {
6443
return .none
6544
}
6645
}
67-
.ifLet(\.$destination, action: \.destination) {
68-
Destination()
69-
}
46+
.ifLet(\.$destination, action: \.destination)
7047
}
7148
}
7249

Examples/CaseStudies/SwiftUICaseStudies/03-NavigationStack.swift

+30-65
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ private let readMe = """
77

88
@Reducer
99
struct NavigationDemo {
10+
@Reducer(state: .equatable)
11+
enum Path {
12+
case screenA(ScreenA)
13+
case screenB(ScreenB)
14+
case screenC(ScreenC)
15+
}
16+
1017
@ObservableState
1118
struct State: Equatable {
1219
var path = StackState<Path.State>()
@@ -27,23 +34,23 @@ struct NavigationDemo {
2734
return .none
2835

2936
case .goToABCButtonTapped:
30-
state.path.append(.screenA())
31-
state.path.append(.screenB())
32-
state.path.append(.screenC())
37+
state.path.append(.screenA(ScreenA.State()))
38+
state.path.append(.screenB(ScreenB.State()))
39+
state.path.append(.screenC(ScreenC.State()))
3340
return .none
3441

3542
case let .path(action):
3643
switch action {
3744
case .element(id: _, action: .screenB(.screenAButtonTapped)):
38-
state.path.append(.screenA())
45+
state.path.append(.screenA(ScreenA.State()))
3946
return .none
4047

4148
case .element(id: _, action: .screenB(.screenBButtonTapped)):
42-
state.path.append(.screenB())
49+
state.path.append(.screenB(ScreenB.State()))
4350
return .none
4451

4552
case .element(id: _, action: .screenB(.screenCButtonTapped)):
46-
state.path.append(.screenC())
53+
state.path.append(.screenC(ScreenC.State()))
4754
return .none
4855

4956
default:
@@ -55,37 +62,7 @@ struct NavigationDemo {
5562
return .none
5663
}
5764
}
58-
.forEach(\.path, action: \.path) {
59-
Path()
60-
}
61-
}
62-
63-
@Reducer
64-
struct Path {
65-
@ObservableState
66-
enum State: Equatable {
67-
case screenA(ScreenA.State = .init())
68-
case screenB(ScreenB.State = .init())
69-
case screenC(ScreenC.State = .init())
70-
}
71-
72-
enum Action {
73-
case screenA(ScreenA.Action)
74-
case screenB(ScreenB.Action)
75-
case screenC(ScreenC.Action)
76-
}
77-
78-
var body: some Reducer<State, Action> {
79-
Scope(state: \.screenA, action: \.screenA) {
80-
ScreenA()
81-
}
82-
Scope(state: \.screenB, action: \.screenB) {
83-
ScreenB()
84-
}
85-
Scope(state: \.screenC, action: \.screenC) {
86-
ScreenC()
87-
}
88-
}
65+
.forEach(\.path, action: \.path)
8966
}
9067
}
9168

@@ -100,15 +77,15 @@ struct NavigationDemoView: View {
10077
Section {
10178
NavigationLink(
10279
"Go to screen A",
103-
state: NavigationDemo.Path.State.screenA()
80+
state: NavigationDemo.Path.State.screenA(ScreenA.State())
10481
)
10582
NavigationLink(
10683
"Go to screen B",
107-
state: NavigationDemo.Path.State.screenB()
84+
state: NavigationDemo.Path.State.screenB(ScreenB.State())
10885
)
10986
NavigationLink(
11087
"Go to screen C",
111-
state: NavigationDemo.Path.State.screenC()
88+
state: NavigationDemo.Path.State.screenC(ScreenC.State())
11289
)
11390
}
11491

@@ -120,19 +97,13 @@ struct NavigationDemoView: View {
12097
}
12198
.navigationTitle("Root")
12299
} destination: { store in
123-
switch store.state {
124-
case .screenA:
125-
if let store = store.scope(state: \.screenA, action: \.screenA) {
126-
ScreenAView(store: store)
127-
}
128-
case .screenB:
129-
if let store = store.scope(state: \.screenB, action: \.screenB) {
130-
ScreenBView(store: store)
131-
}
132-
case .screenC:
133-
if let store = store.scope(state: \.screenC, action: \.screenC) {
134-
ScreenCView(store: store)
135-
}
100+
switch store.case {
101+
case let .screenA(store):
102+
ScreenAView(store: store)
103+
case let .screenB(store):
104+
ScreenBView(store: store)
105+
case let .screenC(store):
106+
ScreenCView(store: store)
136107
}
137108
}
138109
.safeAreaInset(edge: .bottom) {
@@ -318,15 +289,15 @@ struct ScreenAView: View {
318289
Section {
319290
NavigationLink(
320291
"Go to screen A",
321-
state: NavigationDemo.Path.State.screenA(.init(count: store.count))
292+
state: NavigationDemo.Path.State.screenA(ScreenA.State(count: store.count))
322293
)
323294
NavigationLink(
324295
"Go to screen B",
325-
state: NavigationDemo.Path.State.screenB()
296+
state: NavigationDemo.Path.State.screenB(ScreenB.State())
326297
)
327298
NavigationLink(
328299
"Go to screen C",
329-
state: NavigationDemo.Path.State.screenC(.init(count: store.count))
300+
state: NavigationDemo.Path.State.screenC(ScreenC.State(count: store.count))
330301
)
331302
}
332303
}
@@ -460,11 +431,11 @@ struct ScreenCView: View {
460431
)
461432
NavigationLink(
462433
"Go to screen B",
463-
state: NavigationDemo.Path.State.screenB()
434+
state: NavigationDemo.Path.State.screenB(ScreenB.State())
464435
)
465436
NavigationLink(
466437
"Go to screen C",
467-
state: NavigationDemo.Path.State.screenC()
438+
state: NavigationDemo.Path.State.screenC(ScreenC.State())
468439
)
469440
}
470441
}
@@ -476,13 +447,7 @@ struct ScreenCView: View {
476447

477448
#Preview {
478449
NavigationDemoView(
479-
store: Store(
480-
initialState: NavigationDemo.State(
481-
path: StackState([
482-
.screenA(ScreenA.State())
483-
])
484-
)
485-
) {
450+
store: Store(initialState: NavigationDemo.State()) {
486451
NavigationDemo()
487452
}
488453
)

Examples/Integration/Integration/Legacy/EscapedWithViewStoreTestCase.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import SwiftUI
33

44
@Reducer
55
private struct EscapedWithViewStoreTestCase {
6-
enum Action: Equatable, Sendable {
6+
enum Action: Sendable {
77
case incr
88
case decr
99
}

0 commit comments

Comments
 (0)