Skip to content

Commit 72077c7

Browse files
Create TCA example and refactor core codes for TCA structure (#1)
Co-authored-by: Yongwook Choi <hyperflow@kakao.com>
1 parent a8592da commit 72077c7

16 files changed

+674
-344
lines changed

Example/Wrp.xcodeproj/project.pbxproj

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,20 @@
1515
571B0BE4283B55A400F57F78 /* WrpExampleServiceProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = 571B0BE3283B55A400F57F78 /* WrpExampleServiceProvider.swift */; };
1616
571B0BEA283B63C100F57F78 /* pbkit.wrp.example.WrpExampleService.wrp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 571B0BE9283B63C100F57F78 /* pbkit.wrp.example.WrpExampleService.wrp.swift */; };
1717
57230F5D2844CBEE003237E5 /* wrp-example.proto in Sources */ = {isa = PBXBuildFile; fileRef = 57230F5C2844CBEE003237E5 /* wrp-example.proto */; };
18+
57288C402856FA27008CEF23 /* WrpSampleSwiftUIView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57288C3F2856FA27008CEF23 /* WrpSampleSwiftUIView.swift */; };
1819
5740EE19283F4B7E00DF378A /* Style.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5740EE18283F4B7E00DF378A /* Style.swift */; };
1920
5740EE1C2840CC1C00DF378A /* ComposableArchitecture in Frameworks */ = {isa = PBXBuildFile; productRef = 5740EE1B2840CC1C00DF378A /* ComposableArchitecture */; };
2021
57D7E61528375E8F00C5F532 /* WrpApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57D7E61428375E8F00C5F532 /* WrpApp.swift */; };
2122
57D7E61928375E9100C5F532 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 57D7E61828375E9100C5F532 /* Assets.xcassets */; };
2223
57D7E61C28375E9100C5F532 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 57D7E61B28375E9100C5F532 /* Preview Assets.xcassets */; };
2324
57D7E62C283767E400C5F532 /* SwiftProtobuf in Frameworks */ = {isa = PBXBuildFile; productRef = 57D7E62B283767E400C5F532 /* SwiftProtobuf */; };
2425
57D7E62F283767FD00C5F532 /* GRPC in Frameworks */ = {isa = PBXBuildFile; productRef = 57D7E62E283767FD00C5F532 /* GRPC */; };
26+
C9F4531328459498009A26B2 /* WrpSampleAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9F4530E28459498009A26B2 /* WrpSampleAction.swift */; };
27+
C9F4531428459498009A26B2 /* WrpSampleTCAView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9F4530F28459498009A26B2 /* WrpSampleTCAView.swift */; };
28+
C9F4531528459498009A26B2 /* WrpSampleEnvironment.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9F4531028459498009A26B2 /* WrpSampleEnvironment.swift */; };
29+
C9F4531628459498009A26B2 /* WrpSampleReducer.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9F4531128459498009A26B2 /* WrpSampleReducer.swift */; };
30+
C9F4531728459498009A26B2 /* WrpSampleState.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9F4531228459498009A26B2 /* WrpSampleState.swift */; };
31+
C9F4531A2852FAB5009A26B2 /* AsyncSequence+Publisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = C9F453192852FAB5009A26B2 /* AsyncSequence+Publisher.swift */; };
2532
/* End PBXBuildFile section */
2633

2734
/* Begin PBXFileReference section */
@@ -32,11 +39,18 @@
3239
571B0BE3283B55A400F57F78 /* WrpExampleServiceProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrpExampleServiceProvider.swift; sourceTree = "<group>"; };
3340
571B0BE9283B63C100F57F78 /* pbkit.wrp.example.WrpExampleService.wrp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = pbkit.wrp.example.WrpExampleService.wrp.swift; sourceTree = "<group>"; };
3441
57230F5C2844CBEE003237E5 /* wrp-example.proto */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.protobuf; path = "wrp-example.proto"; sourceTree = "<group>"; };
42+
57288C3F2856FA27008CEF23 /* WrpSampleSwiftUIView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrpSampleSwiftUIView.swift; sourceTree = "<group>"; };
3543
5740EE18283F4B7E00DF378A /* Style.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Style.swift; sourceTree = "<group>"; };
3644
57D7E61128375E8F00C5F532 /* WrpExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WrpExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
3745
57D7E61428375E8F00C5F532 /* WrpApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrpApp.swift; sourceTree = "<group>"; };
3846
57D7E61828375E9100C5F532 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
3947
57D7E61B28375E9100C5F532 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
48+
C9F4530E28459498009A26B2 /* WrpSampleAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrpSampleAction.swift; sourceTree = "<group>"; };
49+
C9F4530F28459498009A26B2 /* WrpSampleTCAView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrpSampleTCAView.swift; sourceTree = "<group>"; };
50+
C9F4531028459498009A26B2 /* WrpSampleEnvironment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrpSampleEnvironment.swift; sourceTree = "<group>"; };
51+
C9F4531128459498009A26B2 /* WrpSampleReducer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrpSampleReducer.swift; sourceTree = "<group>"; };
52+
C9F4531228459498009A26B2 /* WrpSampleState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WrpSampleState.swift; sourceTree = "<group>"; };
53+
C9F453192852FAB5009A26B2 /* AsyncSequence+Publisher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AsyncSequence+Publisher.swift"; sourceTree = "<group>"; };
4054
/* End PBXFileReference section */
4155

4256
/* Begin PBXFrameworksBuildPhase section */
@@ -80,6 +94,8 @@
8094
57D7E61828375E9100C5F532 /* Assets.xcassets */,
8195
57D7E61A28375E9100C5F532 /* Preview Content */,
8296
5740EE18283F4B7E00DF378A /* Style.swift */,
97+
C9F453192852FAB5009A26B2 /* AsyncSequence+Publisher.swift */,
98+
C9F45318284594A2009A26B2 /* WrpSample */,
8399
);
84100
path = Wrp;
85101
sourceTree = "<group>";
@@ -112,6 +128,19 @@
112128
path = Messages;
113129
sourceTree = "<group>";
114130
};
131+
C9F45318284594A2009A26B2 /* WrpSample */ = {
132+
isa = PBXGroup;
133+
children = (
134+
C9F4530E28459498009A26B2 /* WrpSampleAction.swift */,
135+
C9F4530F28459498009A26B2 /* WrpSampleTCAView.swift */,
136+
C9F4531028459498009A26B2 /* WrpSampleEnvironment.swift */,
137+
C9F4531128459498009A26B2 /* WrpSampleReducer.swift */,
138+
C9F4531228459498009A26B2 /* WrpSampleState.swift */,
139+
57288C3F2856FA27008CEF23 /* WrpSampleSwiftUIView.swift */,
140+
);
141+
path = WrpSample;
142+
sourceTree = "<group>";
143+
};
115144
/* End PBXGroup section */
116145

117146
/* Begin PBXNativeTarget section */
@@ -194,12 +223,19 @@
194223
buildActionMask = 2147483647;
195224
files = (
196225
571B0BDB2837E3E900F57F78 /* pbkit.wrp.example.GetTextValueResponse.pb.swift in Sources */,
226+
C9F4531728459498009A26B2 /* WrpSampleState.swift in Sources */,
227+
C9F4531328459498009A26B2 /* WrpSampleAction.swift in Sources */,
197228
57D7E61528375E8F00C5F532 /* WrpApp.swift in Sources */,
198229
571B0BDD2837E3E900F57F78 /* pbkit.wrp.example.GetSliderValueRequest.pb.swift in Sources */,
199230
571B0BE4283B55A400F57F78 /* WrpExampleServiceProvider.swift in Sources */,
200231
571B0BDE2837E3E900F57F78 /* pbkit.wrp.example.GetSliderValueResponse.pb.swift in Sources */,
232+
57288C402856FA27008CEF23 /* WrpSampleSwiftUIView.swift in Sources */,
201233
57230F5D2844CBEE003237E5 /* wrp-example.proto in Sources */,
234+
C9F4531428459498009A26B2 /* WrpSampleTCAView.swift in Sources */,
235+
C9F4531A2852FAB5009A26B2 /* AsyncSequence+Publisher.swift in Sources */,
202236
571B0BDC2837E3E900F57F78 /* pbkit.wrp.example.GetTextValueRequest.pb.swift in Sources */,
237+
C9F4531528459498009A26B2 /* WrpSampleEnvironment.swift in Sources */,
238+
C9F4531628459498009A26B2 /* WrpSampleReducer.swift in Sources */,
203239
571B0BEA283B63C100F57F78 /* pbkit.wrp.example.WrpExampleService.wrp.swift in Sources */,
204240
5740EE19283F4B7E00DF378A /* Style.swift in Sources */,
205241
);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// AsyncSequence+publisher.swift
3+
// WrpExample
4+
//
5+
// Created by Jaeyoung Yoon on 2022/06/10.
6+
//
7+
8+
import Combine
9+
10+
extension AsyncSequence {
11+
func toPublisher() -> AnyPublisher<Element, Error> {
12+
let subject = PassthroughSubject<Element, Error>()
13+
14+
Task {
15+
do {
16+
for try await element in self {
17+
subject.send(element)
18+
}
19+
20+
subject.send(completion: .finished)
21+
} catch {
22+
subject.send(completion: .failure(error))
23+
}
24+
}
25+
26+
return subject.eraseToAnyPublisher()
27+
}
28+
}

0 commit comments

Comments
 (0)