Skip to content

Commit be6ee99

Browse files
committed
feat: Handler & DataSource API improvements
- `Functional` prefix removed - Assign functions implemented - More testing
1 parent 68656e7 commit be6ee99

File tree

6 files changed

+606
-71
lines changed

6 files changed

+606
-71
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Swift Declarative Configuration (SDC, for short) is a tiny library, that enables
3636

3737
## Basic Usage
3838

39+
> See tests for more
40+
3941
### No SDC
4042

4143
```swift
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
public func assign<Root: AnyObject, T0>(
2+
to root: Root,
3+
_ keyPath: ReferenceWritableKeyPath<Root, T0>
4+
) -> (T0) -> Void {
5+
{ [weak root] result in root?[keyPath: keyPath] = result }
6+
}
7+
8+
public func assignFirst<Root: AnyObject, T0, T1>(
9+
to root: Root,
10+
_ keyPath: ReferenceWritableKeyPath<Root, T0>
11+
) -> (T0, T1) -> Void {
12+
{ [weak root] result, _ in root?[keyPath: keyPath] = result }
13+
}
14+
15+
public func assignFirst<Root: AnyObject, T0, T1, T2>(
16+
to root: Root,
17+
_ keyPath: ReferenceWritableKeyPath<Root, T0>
18+
) -> (T0, T1, T2) -> Void {
19+
{ [weak root] result, _, _ in root?[keyPath: keyPath] = result }
20+
}
21+
22+
public func assignFirst<Root: AnyObject, T0, T1, T2, T3>(
23+
to root: Root,
24+
_ keyPath: ReferenceWritableKeyPath<Root, T0>
25+
) -> (T0, T1, T2, T3) -> Void {
26+
{ [weak root] result, _, _, _ in root?[keyPath: keyPath] = result }
27+
}
28+
29+
public func assignFirst<Root: AnyObject, T0, T1, T2, T3, T4>(
30+
to root: Root,
31+
_ keyPath: ReferenceWritableKeyPath<Root, T0>
32+
) -> (T0, T1, T2, T3, T4) -> Void {
33+
{ [weak root] result, _, _, _, _ in root?[keyPath: keyPath] = result }
34+
}
35+
36+
public func assignSecond<Root: AnyObject, T0, T1>(
37+
to root: Root,
38+
_ keyPath: ReferenceWritableKeyPath<Root, T1>
39+
) -> (T0, T1) -> Void {
40+
{ [weak root] _, result in root?[keyPath: keyPath] = result }
41+
}
42+
43+
public func assignSecond<Root: AnyObject, T0, T1, T2>(
44+
to root: Root,
45+
_ keyPath: ReferenceWritableKeyPath<Root, T1>
46+
) -> (T0, T1, T2) -> Void {
47+
{ [weak root] _, result, _ in root?[keyPath: keyPath] = result }
48+
}
49+
50+
public func assignSecond<Root: AnyObject, T0, T1, T2, T3>(
51+
to root: Root,
52+
_ keyPath: ReferenceWritableKeyPath<Root, T1>
53+
) -> (T0, T1, T2, T3) -> Void {
54+
{ [weak root] _, result, _, _ in root?[keyPath: keyPath] = result }
55+
}
56+
57+
public func assignSecond<Root: AnyObject, T0, T1, T2, T3, T4>(
58+
to root: Root,
59+
_ keyPath: ReferenceWritableKeyPath<Root, T1>
60+
) -> (T0, T1, T2, T3, T4) -> Void {
61+
{ [weak root] _, result, _, _, _ in root?[keyPath: keyPath] = result }
62+
}
63+
64+
public func assignThird<Root: AnyObject, T0, T1, T2>(
65+
to root: Root,
66+
_ keyPath: ReferenceWritableKeyPath<Root, T2>
67+
) -> (T0, T1, T2) -> Void {
68+
{ [weak root] _, _, result in root?[keyPath: keyPath] = result }
69+
}
70+
71+
public func assignThird<Root: AnyObject, T0, T1, T2, T3>(
72+
to root: Root,
73+
_ keyPath: ReferenceWritableKeyPath<Root, T2>
74+
) -> (T0, T1, T2, T3) -> Void {
75+
{ [weak root] _, _, result, _ in root?[keyPath: keyPath] = result }
76+
}
77+
78+
public func assignThird<Root: AnyObject, T0, T1, T2, T3, T4>(
79+
to root: Root,
80+
_ keyPath: ReferenceWritableKeyPath<Root, T2>
81+
) -> (T0, T1, T2, T3, T4) -> Void {
82+
{ [weak root] _, _, result, _, _ in root?[keyPath: keyPath] = result }
83+
}
84+
85+
public func assignFourth<Root: AnyObject, T0, T1, T2, T3>(
86+
to root: Root,
87+
_ keyPath: ReferenceWritableKeyPath<Root, T3>
88+
) -> (T0, T1, T2, T3) -> Void {
89+
{ [weak root] _, _, _, result in root?[keyPath: keyPath] = result }
90+
}
91+
92+
public func assignFourth<Root: AnyObject, T0, T1, T2, T3, T4>(
93+
to root: Root,
94+
_ keyPath: ReferenceWritableKeyPath<Root, T3>
95+
) -> (T0, T1, T2, T3, T4) -> Void {
96+
{ [weak root] _, _, _, result, _ in root?[keyPath: keyPath] = result }
97+
}
98+
99+
public func assignFifth<Root: AnyObject, T0, T1, T2, T3, T4>(
100+
to root: Root,
101+
_ keyPath: ReferenceWritableKeyPath<Root, T4>
102+
) -> (T0, T1, T2, T3, T4) -> Void {
103+
{ [weak root] _, _, _, _, result in root?[keyPath: keyPath] = result }
104+
}
105+
106+
public func assign<Root: AnyObject, T0>(
107+
to root: Root,
108+
_ keyPath: ReferenceWritableKeyPath<Root, T0?>
109+
) -> (T0) -> Void {
110+
{ [weak root] result in root?[keyPath: keyPath] = result }
111+
}
112+
113+
public func assignFirst<Root: AnyObject, T0, T1>(
114+
to root: Root,
115+
_ keyPath: ReferenceWritableKeyPath<Root, T0?>
116+
) -> (T0, T1) -> Void {
117+
{ [weak root] result, _ in root?[keyPath: keyPath] = result }
118+
}
119+
120+
public func assignFirst<Root: AnyObject, T0, T1, T2>(
121+
to root: Root,
122+
_ keyPath: ReferenceWritableKeyPath<Root, T0?>
123+
) -> (T0, T1, T2) -> Void {
124+
{ [weak root] result, _, _ in root?[keyPath: keyPath] = result }
125+
}
126+
127+
public func assignFirst<Root: AnyObject, T0, T1, T2, T3>(
128+
to root: Root,
129+
_ keyPath: ReferenceWritableKeyPath<Root, T0?>
130+
) -> (T0, T1, T2, T3) -> Void {
131+
{ [weak root] result, _, _, _ in root?[keyPath: keyPath] = result }
132+
}
133+
134+
public func assignFirst<Root: AnyObject, T0, T1, T2, T3, T4>(
135+
to root: Root,
136+
_ keyPath: ReferenceWritableKeyPath<Root, T0?>
137+
) -> (T0, T1, T2, T3, T4) -> Void {
138+
{ [weak root] result, _, _, _, _ in root?[keyPath: keyPath] = result }
139+
}
140+
141+
public func assignSecond<Root: AnyObject, T0, T1>(
142+
to root: Root,
143+
_ keyPath: ReferenceWritableKeyPath<Root, T1?>
144+
) -> (T0, T1) -> Void {
145+
{ [weak root] _, result in root?[keyPath: keyPath] = result }
146+
}
147+
148+
public func assignSecond<Root: AnyObject, T0, T1, T2>(
149+
to root: Root,
150+
_ keyPath: ReferenceWritableKeyPath<Root, T1?>
151+
) -> (T0, T1, T2) -> Void {
152+
{ [weak root] _, result, _ in root?[keyPath: keyPath] = result }
153+
}
154+
155+
public func assignSecond<Root: AnyObject, T0, T1, T2, T3>(
156+
to root: Root,
157+
_ keyPath: ReferenceWritableKeyPath<Root, T1?>
158+
) -> (T0, T1, T2, T3) -> Void {
159+
{ [weak root] _, result, _, _ in root?[keyPath: keyPath] = result }
160+
}
161+
162+
public func assignSecond<Root: AnyObject, T0, T1, T2, T3, T4>(
163+
to root: Root,
164+
_ keyPath: ReferenceWritableKeyPath<Root, T1?>
165+
) -> (T0, T1, T2, T3, T4) -> Void {
166+
{ [weak root] _, result, _, _, _ in root?[keyPath: keyPath] = result }
167+
}
168+
169+
public func assignThird<Root: AnyObject, T0, T1, T2>(
170+
to root: Root,
171+
_ keyPath: ReferenceWritableKeyPath<Root, T2?>
172+
) -> (T0, T1, T2) -> Void {
173+
{ [weak root] _, _, result in root?[keyPath: keyPath] = result }
174+
}
175+
176+
public func assignThird<Root: AnyObject, T0, T1, T2, T3>(
177+
to root: Root,
178+
_ keyPath: ReferenceWritableKeyPath<Root, T2?>
179+
) -> (T0, T1, T2, T3) -> Void {
180+
{ [weak root] _, _, result, _ in root?[keyPath: keyPath] = result }
181+
}
182+
183+
public func assignThird<Root: AnyObject, T0, T1, T2, T3, T4>(
184+
to root: Root,
185+
_ keyPath: ReferenceWritableKeyPath<Root, T2?>
186+
) -> (T0, T1, T2, T3, T4) -> Void {
187+
{ [weak root] _, _, result, _, _ in root?[keyPath: keyPath] = result }
188+
}
189+
190+
public func assignFourth<Root: AnyObject, T0, T1, T2, T3>(
191+
to root: Root,
192+
_ keyPath: ReferenceWritableKeyPath<Root, T3?>
193+
) -> (T0, T1, T2, T3) -> Void {
194+
{ [weak root] _, _, _, result in root?[keyPath: keyPath] = result }
195+
}
196+
197+
public func assignFourth<Root: AnyObject, T0, T1, T2, T3, T4>(
198+
to root: Root,
199+
_ keyPath: ReferenceWritableKeyPath<Root, T3?>
200+
) -> (T0, T1, T2, T3, T4) -> Void {
201+
{ [weak root] _, _, _, result, _ in root?[keyPath: keyPath] = result }
202+
}
203+
204+
public func assignFifth<Root: AnyObject, T0, T1, T2, T3, T4>(
205+
to root: Root,
206+
_ keyPath: ReferenceWritableKeyPath<Root, T4?>
207+
) -> (T0, T1, T2, T3, T4) -> Void {
208+
{ [weak root] _, _, _, _, result in root?[keyPath: keyPath] = result }
209+
}

Sources/FunctionalClosures/FunctionalDataSource.swift renamed to Sources/FunctionalClosures/DataSource.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
///
33
/// Provides a public API to set internal closure-based datasource with a functional API
44
@propertyWrapper
5-
public struct FunctionalDataSource<Input, Output> {
5+
public struct DataSource<Input, Output> {
66
public struct Container {
77
internal var action: ((Input) -> Output)?
88

Sources/FunctionalClosures/FunctionalHandler.swift

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)