Skip to content

Commit 396ae72

Browse files
committed
Fix builds, tests, warnings and run swift-format
1 parent a1eddf5 commit 396ae72

File tree

10 files changed

+868
-869
lines changed

10 files changed

+868
-869
lines changed

Sources/ComposableArchitecture/Effects/SignalProducer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,9 +323,9 @@ extension EffectProducer where Failure == Swift.Error {
323323
}
324324
}
325325

326-
extension Effect {
326+
extension EffectProducer {
327327

328-
/// Turns any effect into an ``Effect`` for any output and failure type by ignoring all output
328+
/// Turns any effect into an ``EffectProducer`` for any output and failure type by ignoring all output
329329
/// and any failure.
330330
///
331331
/// This is useful for times you want to fire off an effect but don't want to feed any data back
@@ -348,7 +348,7 @@ extension Effect {
348348
public func fireAndForget<NewValue, NewError>(
349349
outputType: NewValue.Type = NewValue.self,
350350
failureType: NewError.Type = NewError.self
351-
) -> Effect<NewValue, NewError> {
351+
) -> EffectProducer<NewValue, NewError> {
352352
self
353353
.producer
354354
.flatMapError { _ in .empty }

Sources/ComposableArchitecture/Store.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -399,24 +399,24 @@ public final class Store<State, Action> {
399399
}
400400
},
401401
completed: { [weak self] in
402-
self?.threadCheck(status: .effectCompletion(action))
403-
boxedTask.wrappedValue?.cancel()
404-
didComplete = true
402+
self?.threadCheck(status: .effectCompletion(action))
403+
boxedTask.wrappedValue?.cancel()
404+
didComplete = true
405405
self?.effectDisposables.removeValue(forKey: uuid)?.dispose()
406-
},
406+
},
407407
interrupted: { [weak self] in
408408
boxedTask.wrappedValue?.cancel()
409409
didComplete = true
410410
self?.effectDisposables.removeValue(forKey: uuid)?.dispose()
411-
}
411+
}
412412
)
413413

414414
let effectDisposable = CompositeDisposable()
415415
effectDisposable += producer.start(observer)
416416
effectDisposable += AnyDisposable { [weak self] in
417417
self?.threadCheck(status: .effectCompletion(action))
418418
self?.effectDisposables.removeValue(forKey: uuid)?.dispose()
419-
}
419+
}
420420

421421
if !didComplete {
422422
let task = Task<Void, Never> { @MainActor in
@@ -677,7 +677,7 @@ public typealias StoreOf<R: ReducerProtocol> = Store<R.State, R.Action>
677677
let reducer = ScopedReducer<RootState, RootAction, RescopedState, RescopedAction>(
678678
rootStore: self.rootStore,
679679
state: { _ in toRescopedState(store.state) },
680-
action: { fromRescopedAction($0, $1).flatMap { fromScopedAction(store.state.value, $0) } },
680+
action: { fromRescopedAction($0, $1).flatMap { fromScopedAction(store.state, $0) } },
681681
parentStores: self.parentStores + [store]
682682
)
683683
let childStore = Store<RescopedState, RescopedAction>(
Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,112 @@
11
#if canImport(SwiftUI)
2-
import SwiftUI
2+
import SwiftUI
33

4-
/// A view that safely unwraps a store of optional state in order to show one of two views.
5-
///
6-
/// When the underlying state is non-`nil`, the `then` closure will be performed with a ``Store``
7-
/// that holds onto non-optional state, and otherwise the `else` closure will be performed.
8-
///
9-
/// This is useful for deciding between two views to show depending on an optional piece of state:
10-
///
11-
/// ```swift
12-
/// IfLetStore(
13-
/// store.scope(state: \SearchState.results, action: SearchAction.results),
14-
/// ) {
15-
/// SearchResultsView(store: $0)
16-
/// } else: {
17-
/// Text("Loading search results...")
18-
/// }
19-
/// ```
20-
///
21-
/// And for showing a sheet when a piece of state becomes non-`nil`:
22-
///
23-
/// ```swift
24-
/// .sheet(
25-
/// isPresented: viewStore.binding(
26-
/// get: \.isGameActive,
27-
/// send: { $0 ? .startButtonTapped : .detailDismissed }
28-
/// )
29-
/// ) {
30-
/// IfLetStore(
31-
/// self.store.scope(state: \.detail, action: AppAction.detail)
32-
/// ) {
33-
/// DetailView(store: $0)
34-
/// }
35-
/// }
36-
/// ```
37-
///
4+
/// A view that safely unwraps a store of optional state in order to show one of two views.
5+
///
6+
/// When the underlying state is non-`nil`, the `then` closure will be performed with a ``Store``
7+
/// that holds onto non-optional state, and otherwise the `else` closure will be performed.
8+
///
9+
/// This is useful for deciding between two views to show depending on an optional piece of state:
10+
///
11+
/// ```swift
12+
/// IfLetStore(
13+
/// store.scope(state: \SearchState.results, action: SearchAction.results),
14+
/// ) {
15+
/// SearchResultsView(store: $0)
16+
/// } else: {
17+
/// Text("Loading search results...")
18+
/// }
19+
/// ```
20+
///
21+
/// And for showing a sheet when a piece of state becomes non-`nil`:
22+
///
23+
/// ```swift
24+
/// .sheet(
25+
/// isPresented: viewStore.binding(
26+
/// get: \.isGameActive,
27+
/// send: { $0 ? .startButtonTapped : .detailDismissed }
28+
/// )
29+
/// ) {
30+
/// IfLetStore(
31+
/// self.store.scope(state: \.detail, action: AppAction.detail)
32+
/// ) {
33+
/// DetailView(store: $0)
34+
/// }
35+
/// }
36+
/// ```
37+
///
3838
public struct IfLetStore<State, Action, Content>: View where Content: View {
39-
private let content: (ViewStore<State?, Action>) -> Content
40-
private let store: Store<State?, Action>
39+
private let content: (ViewStore<State?, Action>) -> Content
40+
private let store: Store<State?, Action>
4141

42-
/// Initializes an ``IfLetStore`` view that computes content depending on if a store of optional
43-
/// state is `nil` or non-`nil`.
44-
///
45-
/// - Parameters:
46-
/// - store: A store of optional state.
47-
/// - ifContent: A function that is given a store of non-optional state and returns a view that
48-
/// is visible only when the optional state is non-`nil`.
49-
/// - elseContent: A view that is only visible when the optional state is `nil`.
50-
public init<IfContent, ElseContent>(
51-
_ store: Store<State?, Action>,
52-
@ViewBuilder then ifContent: @escaping (Store<State, Action>) -> IfContent,
53-
@ViewBuilder else elseContent: () -> ElseContent
54-
) where Content == _ConditionalContent<IfContent, ElseContent> {
55-
self.store = store
56-
let elseContent = elseContent()
57-
self.content = { viewStore in
58-
if var state = viewStore.state {
59-
return ViewBuilder.buildEither(
60-
first: ifContent(
42+
/// Initializes an ``IfLetStore`` view that computes content depending on if a store of optional
43+
/// state is `nil` or non-`nil`.
44+
///
45+
/// - Parameters:
46+
/// - store: A store of optional state.
47+
/// - ifContent: A function that is given a store of non-optional state and returns a view that
48+
/// is visible only when the optional state is non-`nil`.
49+
/// - elseContent: A view that is only visible when the optional state is `nil`.
50+
public init<IfContent, ElseContent>(
51+
_ store: Store<State?, Action>,
52+
@ViewBuilder then ifContent: @escaping (Store<State, Action>) -> IfContent,
53+
@ViewBuilder else elseContent: () -> ElseContent
54+
) where Content == _ConditionalContent<IfContent, ElseContent> {
55+
self.store = store
56+
let elseContent = elseContent()
57+
self.content = { viewStore in
58+
if var state = viewStore.state {
59+
return ViewBuilder.buildEither(
60+
first: ifContent(
61+
store
62+
.filter { state, _ in state == nil ? !BindingLocal.isActive : true }
63+
.scope {
64+
state = $0 ?? state
65+
return state
66+
}
67+
)
68+
)
69+
} else {
70+
return ViewBuilder.buildEither(second: elseContent)
71+
}
72+
}
73+
}
74+
75+
/// Initializes an ``IfLetStore`` view that computes content depending on if a store of optional
76+
/// state is `nil` or non-`nil`.
77+
///
78+
/// - Parameters:
79+
/// - store: A store of optional state.
80+
/// - ifContent: A function that is given a store of non-optional state and returns a view that
81+
/// is visible only when the optional state is non-`nil`.
82+
public init<IfContent>(
83+
_ store: Store<State?, Action>,
84+
@ViewBuilder then ifContent: @escaping (Store<State, Action>) -> IfContent
85+
) where Content == IfContent? {
86+
self.store = store
87+
self.content = { viewStore in
88+
if var state = viewStore.state {
89+
return ifContent(
6190
store
6291
.filter { state, _ in state == nil ? !BindingLocal.isActive : true }
6392
.scope {
64-
state = $0 ?? state
65-
return state
66-
}
93+
state = $0 ?? state
94+
return state
95+
}
6796
)
68-
)
69-
} else {
70-
return ViewBuilder.buildEither(second: elseContent)
97+
} else {
98+
return nil
99+
}
71100
}
72101
}
73-
}
74102

75-
/// Initializes an ``IfLetStore`` view that computes content depending on if a store of optional
76-
/// state is `nil` or non-`nil`.
77-
///
78-
/// - Parameters:
79-
/// - store: A store of optional state.
80-
/// - ifContent: A function that is given a store of non-optional state and returns a view that
81-
/// is visible only when the optional state is non-`nil`.
82-
public init<IfContent>(
83-
_ store: Store<State?, Action>,
84-
@ViewBuilder then ifContent: @escaping (Store<State, Action>) -> IfContent
85-
) where Content == IfContent? {
86-
self.store = store
87-
self.content = { viewStore in
88-
if var state = viewStore.state {
89-
return ifContent(
90-
store
91-
.filter { state, _ in state == nil ? !BindingLocal.isActive : true }
92-
.scope {
93-
state = $0 ?? state
94-
return state
95-
}
96-
)
97-
} else {
98-
return nil
99-
}
103+
public var body: some View {
104+
WithViewStore(
105+
self.store,
106+
observe: { $0 },
107+
removeDuplicates: { ($0 != nil) == ($1 != nil) },
108+
content: self.content
109+
)
100110
}
101111
}
102-
103-
public var body: some View {
104-
WithViewStore(
105-
self.store,
106-
observe: { $0 },
107-
removeDuplicates: { ($0 != nil) == ($1 != nil) },
108-
content: self.content
109-
)
110-
}
111-
}
112112
#endif

0 commit comments

Comments
 (0)