Skip to content

Commit 3d8df04

Browse files
committed
Fix minor typo (#1237)
1 parent 8474705 commit 3d8df04

File tree

1 file changed

+91
-91
lines changed

1 file changed

+91
-91
lines changed
Lines changed: 91 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,106 @@
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-
/// isActive: 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>
41-
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: @escaping () -> ElseContent
54-
) where Content == _ConditionalContent<IfContent, ElseContent> {
55-
self.store = store
56-
self.content = { viewStore in
57-
if var state = viewStore.state {
58-
return ViewBuilder.buildEither(
59-
first: ifContent(
60-
store.scope {
61-
state = $0 ?? state
62-
return state
63-
}
64-
)
65-
)
66-
} else {
67-
return ViewBuilder.buildEither(second: elseContent())
68-
}
69-
}
70-
}
39+
private let content: (ViewStore<State?, Action>) -> Content
40+
private let store: Store<State?, Action>
7141

72-
/// Initializes an ``IfLetStore`` view that computes content depending on if a store of optional
73-
/// state is `nil` or non-`nil`.
74-
///
75-
/// - Parameters:
76-
/// - store: A store of optional state.
77-
/// - ifContent: A function that is given a store of non-optional state and returns a view that
78-
/// is visible only when the optional state is non-`nil`.
79-
public init<IfContent>(
80-
_ store: Store<State?, Action>,
81-
@ViewBuilder then ifContent: @escaping (Store<State, Action>) -> IfContent
82-
) where Content == IfContent? {
83-
self.store = store
84-
self.content = { viewStore in
85-
if var state = viewStore.state {
86-
return 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: @escaping () -> ElseContent
54+
) where Content == _ConditionalContent<IfContent, ElseContent> {
55+
self.store = store
56+
self.content = { viewStore in
57+
if var state = viewStore.state {
58+
return ViewBuilder.buildEither(
59+
first: ifContent(
8760
store.scope {
8861
state = $0 ?? state
8962
return state
9063
}
9164
)
92-
} else {
93-
return nil
94-
}
65+
)
66+
} else {
67+
return ViewBuilder.buildEither(second: elseContent())
9568
}
9669
}
70+
}
9771

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

0 commit comments

Comments
 (0)