Skip to content

Commit 33de89e

Browse files
stephencelismluisbrown
authored andcommitted
Run swift-format
(cherry picked from commit 8f356ef0a118dc5b6d0977f83f02667ade053398) # Conflicts: # Sources/ComposableArchitecture/Effect.swift # Sources/ComposableArchitecture/Effects/SignalProducer.swift # Sources/swift-composable-architecture-benchmark/Dependencies.swift # Tests/ComposableArchitectureTests/EffectTests.swift
1 parent cca1554 commit 33de89e

File tree

5 files changed

+122
-116
lines changed

5 files changed

+122
-116
lines changed

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ let package = Package(
1414
.library(
1515
name: "ComposableArchitecture",
1616
targets: ["ComposableArchitecture"]
17-
),
17+
)
1818
],
1919
dependencies: [
2020
.package(url: "https://github.com/apple/swift-docc-plugin", from: "1.0.0"),

Sources/ComposableArchitecture/Effect.swift

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -180,39 +180,39 @@ extension EffectProducer where Failure == Never {
180180
) -> Self {
181181
withEscapedDependencies { escaped in
182182
Self(
183-
operation: .run(priority) { send in
183+
operation: .run(priority) { send in
184184
await escaped.yield {
185-
do {
186-
try await send(operation())
187-
} catch is CancellationError {
188-
return
189-
} catch {
190-
guard let handler = handler else {
191-
#if DEBUG
192-
var errorDump = ""
193-
customDump(error, to: &errorDump, indent: 4)
194-
runtimeWarn(
195-
"""
196-
An "EffectTask.task" returned from "\(fileID):\(line)" threw an unhandled \
197-
error. …
198-
199-
\(errorDump)
200-
201-
All non-cancellation errors must be explicitly handled via the "catch" \
202-
parameter on "EffectTask.task", or via a "do" block.
203-
""",
204-
file: file,
205-
line: line
206-
)
207-
#endif
185+
do {
186+
try await send(operation())
187+
} catch is CancellationError {
208188
return
189+
} catch {
190+
guard let handler = handler else {
191+
#if DEBUG
192+
var errorDump = ""
193+
customDump(error, to: &errorDump, indent: 4)
194+
runtimeWarn(
195+
"""
196+
An "EffectTask.task" returned from "\(fileID):\(line)" threw an unhandled \
197+
error. …
198+
199+
\(errorDump)
200+
201+
All non-cancellation errors must be explicitly handled via the "catch" \
202+
parameter on "EffectTask.task", or via a "do" block.
203+
""",
204+
file: file,
205+
line: line
206+
)
207+
#endif
208+
return
209+
}
210+
await send(handler(error))
209211
}
210-
await send(handler(error))
211212
}
212213
}
213-
}
214-
)
215-
}
214+
)
215+
}
216216
}
217217

218218
/// Wraps an asynchronous unit of work that can emit any number of times in an effect.
@@ -264,38 +264,38 @@ extension EffectProducer where Failure == Never {
264264
) -> Self {
265265
withEscapedDependencies { escaped in
266266
Self(
267-
operation: .run(priority) { send in
267+
operation: .run(priority) { send in
268268
await escaped.yield {
269-
do {
270-
try await operation(send)
271-
} catch is CancellationError {
272-
return
273-
} catch {
274-
guard let handler = handler else {
275-
#if DEBUG
276-
var errorDump = ""
277-
customDump(error, to: &errorDump, indent: 4)
278-
runtimeWarn(
279-
"""
280-
An "EffectTask.run" returned from "\(fileID):\(line)" threw an unhandled error. …
281-
282-
\(errorDump)
283-
284-
All non-cancellation errors must be explicitly handled via the "catch" parameter \
285-
on "EffectTask.run", or via a "do" block.
286-
""",
287-
file: file,
288-
line: line
289-
)
290-
#endif
269+
do {
270+
try await operation(send)
271+
} catch is CancellationError {
291272
return
273+
} catch {
274+
guard let handler = handler else {
275+
#if DEBUG
276+
var errorDump = ""
277+
customDump(error, to: &errorDump, indent: 4)
278+
runtimeWarn(
279+
"""
280+
An "EffectTask.run" returned from "\(fileID):\(line)" threw an unhandled error. …
281+
282+
\(errorDump)
283+
284+
All non-cancellation errors must be explicitly handled via the "catch" parameter \
285+
on "EffectTask.run", or via a "do" block.
286+
""",
287+
file: file,
288+
line: line
289+
)
290+
#endif
291+
return
292+
}
293+
await handler(error, send)
292294
}
293-
await handler(error, send)
294295
}
295296
}
296-
}
297-
)
298-
}
297+
)
298+
}
299299
}
300300

301301
/// Creates an effect that executes some work in the real world that doesn't need to feed data
@@ -511,32 +511,34 @@ extension EffectProducer {
511511
return .init(
512512
operation: .producer(
513513
producer
514-
.map(withEscapedDependencies { escaped in
514+
.map(
515+
withEscapedDependencies { escaped in
515516
{ action in
516517
escaped.yield {
517518
transform(action)
518519
}
519520
}
520-
})
521+
}
522+
)
521523
)
522524
)
523525
case let .run(priority, operation):
524526
return withEscapedDependencies { escaped in
525527
.init(
526-
operation: .run(priority) { send in
528+
operation: .run(priority) { send in
527529
await escaped.yield {
528-
await operation(
529-
Send { action in
530-
send(transform(action))
530+
await operation(
531+
Send { action in
532+
send(transform(action))
533+
}
534+
)
535+
}
531536
}
532537
)
533-
}
534-
}
535-
)
538+
}
536539
}
537540
}
538541
}
539-
}
540542

541543
// MARK: - Testing Effects
542544

@@ -668,7 +670,7 @@ extension EffectProducer {
668670
message:
669671
"""
670672
'Effect' has been deprecated in favor of 'EffectTask' when 'Failure == Never', or 'EffectProducer<Output, Failure>' in general.
671-
673+
672674
You are encouraged to use 'EffectTask<Action>' to model the output of your reducers, and to use Swift concurrency to model failable streams of values.
673675
674676
To find and replace instances of 'Effect<Action, Never>' to 'EffectTask<Action, Never>' in your codebase, use the following regular expression:

Sources/ComposableArchitecture/Effects/SignalProducer.swift

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,11 @@ extension EffectProducer {
154154
observer.sendCompleted()
155155
case let .failure(error):
156156
observer.send(error: error)
157-
}
157+
}
158158
}
159159
}
160-
}
161-
}
160+
}
161+
}
162162
.eraseToEffect()
163163
}
164164
}
@@ -249,10 +249,10 @@ extension EffectProducer {
249249
SignalProducer<Action, Failure> { observer, lifetime in
250250
lifetime += escaped.yield {
251251
work(observer)
252+
}
252253
}
254+
.eraseToEffect()
253255
}
254-
.eraseToEffect()
255-
}
256256
}
257257

258258
/// Creates an effect that executes some work in the real world that doesn't need to feed data
@@ -270,15 +270,15 @@ extension EffectProducer {
270270
SignalProducer.deferred {
271271
escaped.yield {
272272
SignalProducer { observer, lifetime in
273-
try? work()
273+
try? work()
274274
observer.sendCompleted()
275+
}
275276
}
276277
}
278+
.eraseToEffect()
277279
}
278-
.eraseToEffect()
279280
}
280281
}
281-
}
282282

283283
extension EffectProducer where Failure == Swift.Error {
284284
/// Initializes an effect that lazily executes some work in the real world and synchronously sends
@@ -425,13 +425,15 @@ extension SignalProducer {
425425
public func eraseToEffect<T>(
426426
_ transform: @escaping (Value) -> T
427427
) -> EffectProducer<T, Error> {
428-
self.map(withEscapedDependencies { escaped in
428+
self.map(
429+
withEscapedDependencies { escaped in
429430
{ action in
430431
escaped.yield {
431432
transform(action)
432433
}
433434
}
434-
})
435+
}
436+
)
435437
.eraseToEffect()
436438
}
437439

@@ -505,13 +507,15 @@ extension SignalProducer {
505507
) -> EffectTask<T> {
506508
return
507509
self
508-
.map(withEscapedDependencies { escaped in
510+
.map(
511+
withEscapedDependencies { escaped in
509512
{ action in
510513
escaped.yield {
511514
transform(.success(action))
512-
}
513-
}
514-
})
515+
}
516+
}
517+
}
518+
)
515519
.flatMapError { SignalProducer<T, Never>(value: transform(.failure($0))) }
516520
.eraseToEffect()
517521
}

Sources/swift-composable-architecture-benchmark/Dependencies.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@ import Foundation
55
import ReactiveSwift
66

77
let dependenciesSuite = BenchmarkSuite(name: "Dependencies") { suite in
8-
#if swift(>=5.7)
9-
let reducer: some ReducerProtocol<Int, Void> = BenchmarkReducer()
10-
.dependency(\.calendar, .autoupdatingCurrent)
11-
.dependency(\.date, .init { Date() })
12-
.dependency(\.locale, .autoupdatingCurrent)
8+
#if swift(>=5.7)
9+
let reducer: some ReducerProtocol<Int, Void> = BenchmarkReducer()
10+
.dependency(\.calendar, .autoupdatingCurrent)
11+
.dependency(\.date, .init { Date() })
12+
.dependency(\.locale, .autoupdatingCurrent)
1313
.dependency(\.mainQueueScheduler, ImmediateScheduler())
14-
.dependency(\.timeZone, .autoupdatingCurrent)
15-
.dependency(\.uuid, .init { UUID() })
14+
.dependency(\.timeZone, .autoupdatingCurrent)
15+
.dependency(\.uuid, .init { UUID() })
1616

17-
suite.benchmark("Dependency key writing") {
18-
var state = 0
19-
_ = reducer.reduce(into: &state, action: ())
20-
precondition(state == 1)
21-
}
22-
#endif
17+
suite.benchmark("Dependency key writing") {
18+
var state = 0
19+
_ = reducer.reduce(into: &state, action: ())
20+
precondition(state == 1)
21+
}
22+
#endif
2323
}
2424

2525
private struct BenchmarkReducer: ReducerProtocol {

Tests/ComposableArchitectureTests/EffectTests.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,37 +48,37 @@ final class EffectTests: XCTestCase {
4848
#if swift(>=5.7) && (canImport(RegexBuilder) || !os(macOS) && !targetEnvironment(macCatalyst))
4949
func testConcatenate() async {
5050
await _withMainSerialExecutor {
51-
if #available(iOS 16, macOS 13, tvOS 16, watchOS 9, *) {
52-
let clock = TestClock()
53-
var values: [Int] = []
51+
if #available(iOS 16, macOS 13, tvOS 16, watchOS 9, *) {
52+
let clock = TestClock()
53+
var values: [Int] = []
5454

5555
let effect = EffectProducer<Int, Never>.concatenate(
56-
(1...3).map { count in
57-
.task {
58-
try await clock.sleep(for: .seconds(count))
59-
return count
56+
(1...3).map { count in
57+
.task {
58+
try await clock.sleep(for: .seconds(count))
59+
return count
60+
}
6061
}
61-
}
62-
)
62+
)
6363

6464
effect.producer.startWithValues { values.append($0) }
6565

66-
XCTAssertEqual(values, [])
66+
XCTAssertEqual(values, [])
6767

68-
await clock.advance(by: .seconds(1))
69-
XCTAssertEqual(values, [1])
68+
await clock.advance(by: .seconds(1))
69+
XCTAssertEqual(values, [1])
7070

71-
await clock.advance(by: .seconds(2))
72-
XCTAssertEqual(values, [1, 2])
71+
await clock.advance(by: .seconds(2))
72+
XCTAssertEqual(values, [1, 2])
7373

74-
await clock.advance(by: .seconds(3))
75-
XCTAssertEqual(values, [1, 2, 3])
74+
await clock.advance(by: .seconds(3))
75+
XCTAssertEqual(values, [1, 2, 3])
7676

77-
await clock.run()
78-
XCTAssertEqual(values, [1, 2, 3])
77+
await clock.run()
78+
XCTAssertEqual(values, [1, 2, 3])
79+
}
7980
}
8081
}
81-
}
8282
#endif
8383

8484
func testConcatenateOneEffect() {
@@ -325,19 +325,19 @@ final class EffectTests: XCTestCase {
325325
$0.date.now = Date(timeIntervalSince1970: 1_234_567_890)
326326
} operation: {
327327
EffectTask<Void>(value: ()).map { date() }
328-
}
328+
}
329329
var output: Date?
330330
effect
331331
.producer
332332
.startWithValues { output = $0 }
333333
XCTAssertEqual(output, Date(timeIntervalSince1970: 1_234_567_890))
334-
334+
335335
if #available(iOS 15, macOS 12, tvOS 15, watchOS 8, *) {
336336
let effect = withDependencies {
337337
$0.date.now = Date(timeIntervalSince1970: 1_234_567_890)
338338
} operation: {
339339
EffectTask<Void>.task {}.map { date() }
340-
}
340+
}
341341
output = await effect.values.first(where: { _ in true })
342342
XCTAssertEqual(output, Date(timeIntervalSince1970: 1_234_567_890))
343343
}

0 commit comments

Comments
 (0)