Skip to content

Commit 7e1d3c5

Browse files
mluisbrownmbrandonwDante-Broggistephencelisklop
authored
Sync upstream changes from the Pointfree repo (#6)
* Clarify assertion failure for incorrect send usage (#151) * Clarify assertion failure for incorrect send usage * Update ViewStore.swift * Update Sources/ComposableArchitecture/Store.swift Co-authored-by: Dante Broggi <[email protected]> * Update Sources/ComposableArchitecture/Store.swift Co-authored-by: Stephen Celis <[email protected]> Co-authored-by: Dante Broggi <[email protected]> Co-authored-by: Stephen Celis <[email protected]> * Run swift-format * Reset cancellation test environment in tearDown and fix testCancellationAfterDelay (#156) * Resetting cancellation test environment in tearDown and fixed testCancellationAfterDelay * Defining CancelToken once at class scope * Explicit self * Run swift-format * Replace 'receive(subscriber:)' with 'subscribe()' (#158) * Insert interval work before synchronous work. (#161) * Run swift-format * Reflect repo rename of ReactiveSwift fork (#162) The fork was renamed to `reactiveswift-composable-architecture` to avoid confusion. * Replace recursive call in Store.send with a while loop to process synchronous effects (#163) * While loop instead of recursive send for synchronous effects in store * Created StoreTests.testLotsOfSynchronousActions * Run swift-format * Speed up TestScheduler work removal (#164) * Speed up TestScheduler work removal * Simplify * Remove recursion from TestScheduler.advance (#166) * Optimize IfLetStore ViewBuilder code (#167) * Optimize IfLetStore ViewBuilder code * Infer * Cancellation Fixes (#169) * Failing test when reusing cancellation id. * wip * Clean up * update test * Update Tests/ComposableArchitectureTests/TimerTests.swift * move methods around * wip * more * wip Co-authored-by: Brandon Williams <[email protected]> * Make forEach explictly check that the ID is present in the IdentifiedArray. (#154) * Run swift-format * Add assertion to Reducer.optional (#157) * Add assertion to Reducer.optional * Another bug * Another potential bug * best practice? * WIP * Clean up language and add more language to index-based forEach * Re-wrap * Update Sources/ComposableArchitecture/Reducer.swift Co-authored-by: Brandon Williams <[email protected]> * Update Sources/ComposableArchitecture/Reducer.swift Co-authored-by: Brandon Williams <[email protected]> * wording Co-authored-by: Brandon Williams <[email protected]> * Run swift-format * Update readme to better describe what the reducer returns. (#174) * Update assertion messaging (#170) * Update assertion messaging * updated some docs Co-authored-by: Brandon Williams <[email protected]> * Increase timeout to reduce test flakiness. * Return to random number of effects in effect cancellation tests. * swift-format changes Co-authored-by: Brandon Williams <[email protected]> Co-authored-by: Dante Broggi <[email protected]> Co-authored-by: Stephen Celis <[email protected]> Co-authored-by: mbrandonw <[email protected]> Co-authored-by: klop <[email protected]> Co-authored-by: stephencelis <[email protected]> Co-authored-by: Anton Siliuk <[email protected]> Co-authored-by: Peter Kovacs <[email protected]>
1 parent 446a0aa commit 7e1d3c5

29 files changed

+661
-483
lines changed

Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-OptionalState.swift

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,29 @@ enum OptionalBasicsAction: Equatable {
2323

2424
struct OptionalBasicsEnvironment {}
2525

26-
let optionalBasicsReducer = Reducer<
27-
OptionalBasicsState, OptionalBasicsAction, OptionalBasicsEnvironment
28-
>.combine(
29-
Reducer { state, action, environment in
30-
switch action {
31-
case .toggleCounterButtonTapped:
32-
state.optionalCounter =
33-
state.optionalCounter == nil
34-
? CounterState()
35-
: nil
36-
return .none
37-
case .optionalCounter:
38-
return .none
39-
}
40-
},
41-
counterReducer.optional.pullback(
26+
let optionalBasicsReducer = counterReducer
27+
.optional
28+
.pullback(
4229
state: \.optionalCounter,
4330
action: /OptionalBasicsAction.optionalCounter,
4431
environment: { _ in CounterEnvironment() }
4532
)
46-
)
33+
.combined(
34+
with: Reducer<
35+
OptionalBasicsState, OptionalBasicsAction, OptionalBasicsEnvironment
36+
> { state, action, environment in
37+
switch action {
38+
case .toggleCounterButtonTapped:
39+
state.optionalCounter =
40+
state.optionalCounter == nil
41+
? CounterState()
42+
: nil
43+
return .none
44+
case .optionalCounter:
45+
return .none
46+
}
47+
}
48+
)
4749

4850
struct OptionalBasicsView: View {
4951
let store: Store<OptionalBasicsState, OptionalBasicsAction>

Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-SharedState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ let sharedStateProfileReducer = Reducer<
123123
}
124124
}
125125

126-
let sharedStateReducer: Reducer<SharedState, SharedStateAction, Void> = .combine(
126+
let sharedStateReducer = Reducer<SharedState, SharedStateAction, Void>.combine(
127127
sharedStateCounterReducer.pullback(
128128
state: \SharedState.counter,
129129
action: /SharedStateAction.counter,

Examples/CaseStudies/SwiftUICaseStudies/03-Navigation-Lists-LoadThenNavigate.swift

Lines changed: 43 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -31,50 +31,55 @@ struct LazyListNavigationEnvironment {
3131
var mainQueue: DateScheduler
3232
}
3333

34-
let lazyListNavigationReducer = Reducer<
35-
LazyListNavigationState, LazyListNavigationAction, LazyListNavigationEnvironment
36-
>.combine(
37-
Reducer { state, action, environment in
38-
struct CancelId: Hashable {}
34+
let lazyListNavigationReducer =
35+
counterReducer
36+
.pullback(
37+
state: \Identified.value,
38+
action: .self,
39+
environment: { $0 }
40+
)
41+
.optional
42+
.pullback(
43+
state: \LazyListNavigationState.selection,
44+
action: /LazyListNavigationAction.counter,
45+
environment: { _ in CounterEnvironment() }
46+
)
47+
.combined(
48+
with: Reducer<
49+
LazyListNavigationState, LazyListNavigationAction, LazyListNavigationEnvironment
50+
> { state, action, environment in
51+
struct CancelId: Hashable {}
3952

40-
switch action {
41-
case .counter:
42-
return .none
53+
switch action {
54+
case .counter:
55+
return .none
4356

44-
case let .setNavigation(selection: .some(id)):
45-
for index in state.rows.indices {
46-
state.rows[index].isActivityIndicatorVisible = state.rows[index].id == id
47-
}
57+
case let .setNavigation(selection: .some(id)):
58+
for index in state.rows.indices {
59+
state.rows[index].isActivityIndicatorVisible = state.rows[index].id == id
60+
}
4861

49-
return Effect(value: .setNavigationSelectionDelayCompleted(id))
50-
.delay(1, on: environment.mainQueue)
51-
.cancellable(id: CancelId(), cancelInFlight: true)
62+
return Effect(value: .setNavigationSelectionDelayCompleted(id))
63+
.delay(1, on: environment.mainQueue)
64+
.cancellable(id: CancelId(), cancelInFlight: true)
5265

53-
case .setNavigation(selection: .none):
54-
if let selection = state.selection {
55-
state.rows[id: selection.id]?.count = selection.count
56-
}
57-
state.selection = nil
58-
return .cancel(id: CancelId())
66+
case .setNavigation(selection: .none):
67+
if let selection = state.selection {
68+
state.rows[id: selection.id]?.count = selection.count
69+
}
70+
state.selection = nil
71+
return .cancel(id: CancelId())
5972

60-
case let .setNavigationSelectionDelayCompleted(id):
61-
state.rows[id: id]?.isActivityIndicatorVisible = false
62-
state.selection = Identified(
63-
CounterState(count: state.rows[id: id]?.count ?? 0),
64-
id: id
65-
)
66-
return .none
73+
case let .setNavigationSelectionDelayCompleted(id):
74+
state.rows[id: id]?.isActivityIndicatorVisible = false
75+
state.selection = Identified(
76+
CounterState(count: state.rows[id: id]?.count ?? 0),
77+
id: id
78+
)
79+
return .none
80+
}
6781
}
68-
},
69-
counterReducer
70-
.pullback(state: \Identified.value, action: .self, environment: { $0 })
71-
.optional
72-
.pullback(
73-
state: \LazyListNavigationState.selection,
74-
action: /LazyListNavigationAction.counter,
75-
environment: { _ in CounterEnvironment() }
76-
)
77-
)
82+
)
7883

7984
struct LazyListNavigationView: View {
8085
let store: Store<LazyListNavigationState, LazyListNavigationAction>

Examples/CaseStudies/SwiftUICaseStudies/03-Navigation-Lists-NavigateAndLoad.swift

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -29,47 +29,47 @@ struct EagerListNavigationEnvironment {
2929
var mainQueue: DateScheduler
3030
}
3131

32-
let eagerListNavigationReducer = Reducer<
33-
EagerListNavigationState, EagerListNavigationAction, EagerListNavigationEnvironment
34-
>.combine(
35-
Reducer { state, action, environment in
36-
37-
struct CancelId: Hashable {}
38-
39-
switch action {
40-
case .counter:
41-
return .none
42-
43-
case let .setNavigation(selection: .some(id)):
44-
state.selection = Identified(nil, id: id)
45-
46-
return Effect(value: .setNavigationSelectionDelayCompleted)
47-
.delay(1, on: environment.mainQueue)
48-
.cancellable(id: CancelId())
32+
let eagerListNavigationReducer = counterReducer
33+
.optional
34+
.pullback(state: \Identified.value, action: .self, environment: { $0 })
35+
.optional
36+
.pullback(
37+
state: \EagerListNavigationState.selection,
38+
action: /EagerListNavigationAction.counter,
39+
environment: { _ in CounterEnvironment() }
40+
)
41+
.combined(
42+
with: Reducer<
43+
EagerListNavigationState, EagerListNavigationAction, EagerListNavigationEnvironment
44+
> { state, action, environment in
45+
46+
struct CancelId: Hashable {}
47+
48+
switch action {
49+
case .counter:
50+
return .none
51+
52+
case let .setNavigation(selection: .some(id)):
53+
state.selection = Identified(nil, id: id)
54+
55+
return Effect(value: .setNavigationSelectionDelayCompleted)
56+
.delay(1, on: environment.mainQueue)
57+
.cancellable(id: CancelId())
58+
59+
case .setNavigation(selection: .none):
60+
if let selection = state.selection, let count = selection.value?.count {
61+
state.rows[id: selection.id]?.count = count
62+
}
63+
state.selection = nil
64+
return .cancel(id: CancelId())
4965

50-
case .setNavigation(selection: .none):
51-
if let selection = state.selection, let count = selection.value?.count {
52-
state.rows[id: selection.id]?.count = count
66+
case .setNavigationSelectionDelayCompleted:
67+
guard let id = state.selection?.id else { return .none }
68+
state.selection?.value = CounterState(count: state.rows[id: id]?.count ?? 0)
69+
return .none
5370
}
54-
state.selection = nil
55-
return .cancel(id: CancelId())
56-
57-
case .setNavigationSelectionDelayCompleted:
58-
guard let id = state.selection?.id else { return .none }
59-
state.selection?.value = CounterState(count: state.rows[id: id]?.count ?? 0)
60-
return .none
6171
}
62-
},
63-
counterReducer
64-
.optional
65-
.pullback(state: \Identified.value, action: .self, environment: { $0 })
66-
.optional
67-
.pullback(
68-
state: \EagerListNavigationState.selection,
69-
action: /EagerListNavigationAction.counter,
70-
environment: { _ in CounterEnvironment() }
71-
)
72-
)
72+
)
7373

7474
struct EagerListNavigationView: View {
7575
let store: Store<EagerListNavigationState, EagerListNavigationAction>

Examples/CaseStudies/SwiftUICaseStudies/03-Navigation-LoadThenNavigate.swift

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,35 +27,37 @@ struct LazyNavigationEnvironment {
2727
var mainQueue: DateScheduler
2828
}
2929

30-
let lazyNavigationReducer = Reducer<
31-
LazyNavigationState, LazyNavigationAction, LazyNavigationEnvironment
32-
>.combine(
33-
Reducer { state, action, environment in
34-
switch action {
35-
case .setNavigation(isActive: true):
36-
state.isActivityIndicatorVisible = true
37-
return Effect(value: .setNavigationIsActiveDelayCompleted)
38-
.delay(1, on: environment.mainQueue)
30+
let lazyNavigationReducer = counterReducer
31+
.optional
32+
.pullback(
33+
state: \.optionalCounter,
34+
action: /LazyNavigationAction.optionalCounter,
35+
environment: { _ in CounterEnvironment() }
36+
)
37+
.combined(
38+
with: Reducer<
39+
LazyNavigationState, LazyNavigationAction, LazyNavigationEnvironment
40+
> { state, action, environment in
41+
switch action {
42+
case .setNavigation(isActive: true):
43+
state.isActivityIndicatorVisible = true
44+
return Effect(value: .setNavigationIsActiveDelayCompleted)
45+
.delay(1, on: environment.mainQueue)
3946

40-
case .setNavigation(isActive: false):
41-
state.optionalCounter = nil
42-
return .none
47+
case .setNavigation(isActive: false):
48+
state.optionalCounter = nil
49+
return .none
4350

44-
case .setNavigationIsActiveDelayCompleted:
45-
state.isActivityIndicatorVisible = false
46-
state.optionalCounter = CounterState()
47-
return .none
51+
case .setNavigationIsActiveDelayCompleted:
52+
state.isActivityIndicatorVisible = false
53+
state.optionalCounter = CounterState()
54+
return .none
4855

49-
case .optionalCounter:
50-
return .none
56+
case .optionalCounter:
57+
return .none
58+
}
5159
}
52-
},
53-
counterReducer.optional.pullback(
54-
state: \.optionalCounter,
55-
action: /LazyNavigationAction.optionalCounter,
56-
environment: { _ in CounterEnvironment() }
5760
)
58-
)
5961

6062
struct LazyNavigationView: View {
6163
let store: Store<LazyNavigationState, LazyNavigationAction>

Examples/CaseStudies/SwiftUICaseStudies/03-Navigation-NavigateAndLoad.swift

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,35 +26,37 @@ struct EagerNavigationEnvironment {
2626
var mainQueue: DateScheduler
2727
}
2828

29-
let eagerNavigationReducer = Reducer<
30-
EagerNavigationState, EagerNavigationAction, EagerNavigationEnvironment
31-
>.combine(
32-
Reducer { state, action, environment in
33-
switch action {
34-
case .setNavigation(isActive: true):
35-
state.isNavigationActive = true
36-
return Effect(value: .setNavigationIsActiveDelayCompleted)
37-
.delay(1, on: environment.mainQueue)
29+
let eagerNavigationReducer = counterReducer
30+
.optional
31+
.pullback(
32+
state: \.optionalCounter,
33+
action: /EagerNavigationAction.optionalCounter,
34+
environment: { _ in CounterEnvironment() }
35+
)
36+
.combined(
37+
with: Reducer<
38+
EagerNavigationState, EagerNavigationAction, EagerNavigationEnvironment
39+
> { state, action, environment in
40+
switch action {
41+
case .setNavigation(isActive: true):
42+
state.isNavigationActive = true
43+
return Effect(value: .setNavigationIsActiveDelayCompleted)
44+
.delay(1, on: environment.mainQueue)
3845

39-
case .setNavigation(isActive: false):
40-
state.isNavigationActive = false
41-
state.optionalCounter = nil
42-
return .none
46+
case .setNavigation(isActive: false):
47+
state.isNavigationActive = false
48+
state.optionalCounter = nil
49+
return .none
4350

44-
case .setNavigationIsActiveDelayCompleted:
45-
state.optionalCounter = CounterState()
46-
return .none
51+
case .setNavigationIsActiveDelayCompleted:
52+
state.optionalCounter = CounterState()
53+
return .none
4754

48-
case .optionalCounter:
49-
return .none
55+
case .optionalCounter:
56+
return .none
57+
}
5058
}
51-
},
52-
counterReducer.optional.pullback(
53-
state: \.optionalCounter,
54-
action: /EagerNavigationAction.optionalCounter,
55-
environment: { _ in CounterEnvironment() }
5659
)
57-
)
5860

5961
struct EagerNavigationView: View {
6062
let store: Store<EagerNavigationState, EagerNavigationAction>

0 commit comments

Comments
 (0)